Saturday, February 16, 2008

azureus and x86 opensolaris and webui

ok, here are my notes about how i got x86 opensolaris running with azureus running in headless mode with a web interface as an smf service. i'm hoping that this might help somebody out there. i'm running nevada b81 by the way. also of note is that i have limited unix/solaris knowledge so i'm not really sure what i'm talking about.

the first thing you need to do is to get pkg-get from blastwave.org going if you haven't already done so. you'll need to install wget, nano if you're not a dork, and screen. once you have those packages installed, download the azureus 2.5.x binaries for solaris x86 via wget or whatever. unzip it and copy the azureus directory into /usr

in order to get the web ui working, we need to get the azureus command line ui working first. the azureus cli requires log4j and commons-cli in /usr/azureus (or whatever your home azureus directory is). both jar files can be downloaded from here.

before we get into the shell scripting part, create a new user called azureus with a home directory of /export/home/azureus (make sure the azureus user owns it!). add the azureus user to whatever group you want and you should grant ownership of the azureus home directory to azureus via chown -R azureus /usr/azureus. to get azureus running, we need to edit the /usr/azureus/azureus script that actually launches azureus. first, make a backup copy of the azureus file because you might want to use the gtk ui later. second, change PROGRAM_DIR="/usr/azureus" near the top. third, change this part at the end that actually launches azureus:

echo "${JAVA_PROGRAM_DIR}java -Xms16m -Xmx128m -cp \"${CLASSPATH}\" -Djava.library.path=\"${PROGRAM_DIR}\" -Dazureus.install.path=\"$PROGRAM_DIR\" org.gudy.azureus2.ui.common.Main --ui=console '$@'" ${JAVA_PROGRAM_DIR}java -Xms16m -Xmx128m -cp "${CLASSPATH}" -Djava.library.path="${PROGRAM_DIR}" -Dazureus.install.path="${PROGRAM_DIR}" org.gudy.azureus2.ui.common.Main --ui=console "$@"
i had problems getting java -jar working so i changed it to invoke the main class directly. and don't forget the --ui=console. i found this to work well for me but your mileage may vary.

ok, you should login or su over to your azureus user and try running the ./azureus script. with luck, azureus should start and spitting all sorts of text to the console. it should also tell you that a newer version of azureus is out but you don't have to pay attention to that. we need to set two configuration parameters via this command line to set azureus to download files in certain directory (/export/downloads in this case but you can do whatever you want. i have mine going into a zfs pool) and where to save its working directory (in this case, i think because of the default data dir setting, it will be in /export/home/azureus/.azureus and you need ls -a to see it)

set "Default save path" "/export/downloads" string set "Use default data dir" true boolean
once that is set, let's go back and download an azureus web interface plugin. i've had good luck with this swing-based webui plugin. get the 1.6.10 version as we are using a 2.5.x azureus. the installation instructions are pretty straightforward. just unzip the archive into /usr/azureus/plugins/webui and restart azureus. you'll know if it works if you run show options and you see Plugin.webui.* properties in the list. try connecting to the swing ui via a web browser on port 6883. hope your browser has the java plugin! ok, we now have azureus up and running in the command line and serving up a web interface, which is perfect for a headless nas box. we just need to get azureus running as a daemon that starts running on boot. the first step towards this is a bash script that uses that screen package that we installed earlier. i made a slight derivative of this awesome script on the azureus wiki. create it in your azureus home directory and call it azureus_script:
#! /bin/sh #The user that will run Azureus AZ_USER=azureus #Name of the screen-session NAME=azureus_screen #executable files in the following paths that are perhaps needed by the script PATH=/bin:/usr/bin:/sbin:/usr/sbin:/opt/csw/bin #your path to the azureus directory, where Azureus2.jar is located DIR=/usr/azureus SCREEN=/opt/csw/bin/screen #Description DESC="Azureus screen daemon" case "$1" in start) if [[ `$SCREEN -ls |grep $NAME` ]] then echo "Azureus is already running!" else echo "Starting $DESC: $NAME" cd $DIR; $SCREEN -dmS $NAME ./azureus fi ;; stop) if [[ `$SCREEN -ls |grep $NAME` ]] then echo -n "Stopping $DESC: $NAME" $SCREEN -X quit echo " ... done." else echo "Coulnd't find a running $DESC" fi ;; restart) if [[ `$SCREEN -ls |grep $NAME` ]] then echo -n "Stopping $DESC: $NAME" $SCREEN -X quit echo " ... done." else echo "Coulnd't find a running $DESC" fi echo "Starting $DESC: $NAME" cd $DIR; $SCREEN -dmS $NAME ./azureus echo " ... done." ;; status) if [[ `$SCREEN -ls |grep $NAME` ]] then echo "Azureus is RUNNING" else echo "Azureus is DOWN" fi ;; *) echo "Usage: $0 {start|stop|status|restart}" exit 1 ;; esac exit 0
the original script called su azureus -c "stuff" and i found that it didn't work out for me at all so i got rid of the su's. don't worry though, the azureus user account that we created will still come into play later. test this script with ./azureus_script start, ./azureus_script status to see if its running or not (try loading the webui too!) and ./azureus_script stop to shut it down. ok, this last final part is to integrate this daemon script with smf. we'll need manifest file that describes this shell script as a smf service. i used this example here as a template. create this meta.xml file in your azureus home directory.
<?xml version="1.0"?> <!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1"> <service_bundle type='manifest' name='azureus_headless'> <service name='application/azureus_headless' type='service' version='1'> <create_default_instance enabled='false' /> <single_instance /> <dependency name='multi-user-server' grouping='optional_all' type='service' restart_on='none'> <service_fmri value='svc:/milestone/multi-user-server' /> </dependency> <exec_method type='method' name='start' exec='/usr/azureus/azureus_script %m' timeout_seconds='60'> <method_context> <method_credential user='azureus' /> </method_context> </exec_method> <exec_method type='method' name='restart' exec='/usr/azureus/azureus_script %m' timeout_seconds='60'> <method_context> <method_credential user='azureus' /> </method_context> </exec_method> <exec_method type='method' name='stop' exec='/usr/azureus/azureus_script %m' timeout_seconds='60' > <method_context> <method_credential user='azureus' /> </method_context> </exec_method> <property_group name='startd' type='framework'> <propval name='duration' type='astring' value='contract' /> </property_group> <template> <common_name> <loctext xml:lang='C'> Azureus in headless mode </loctext> </common_name> </template> </service> </service_bundle>
i think the method_credential_user does the equivalent of that su. "svccfg validate /usr/azureus/meta.xml" in the command line to validate the smf manifest xml file. if it all checks out, run svccfg import /usr/azureus/meta.xml to load the smf manifest. try svcs azureus_headless and the service should show up unstarted. to start it, use svcadm enable azureus_headless. try svcs azureus_headless as it goes from unstarted to running (it might take a few seconds). if it doesn't start, try svcs -x and take a look at its log file to see what's going on. that should be it. happy torrenting.

No comments: