HeadlessSwingUIAtBoot
Contents
HeadlessSwingUIAtBoot[edit]
Read HeadlessSwingUiHowTo before you proceed.[edit]
You need "screen" to do it this way. If you don't have it then get it [1] or use an alternative to this procedure and run a DaemonizedAzureus.
Create User[edit]
- Create a user for running Azureus. We called him "azureuser". Replace all azureuser with your desired name!
- The <install-dir> is /home/azureuser/azureus. If you installed it somewhere else then substitute your <install-dir> into the scripts for this one.
Write Startscript[edit]
- To make Azureus start at boot, make a script in /home/azureuser/azureus
Create a textfile with the name "azureus_script"
/home/azureuser/azureus/azureus_script contains:
#! /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:/home/azureus/bin #your path to the azureus directory, where Azureus2.jar is located DIR=/home/azureuser/azureus #Description DESC="Azureus screen daemon" case "$1" in start) if [[ `su $AZ_USER -c "screen -ls |grep $NAME"` ]] then echo "Azureus is already running!" else echo "Starting $DESC: $NAME" su $AZ_USER -c "cd $DIR; screen -dmS $NAME java -jar ./Azureus2.jar --ui=console" fi ;; stop) if [[ `su $AZ_USER -c "screen -ls |grep $NAME"` ]] then echo -n "Stopping $DESC: $NAME" su $AZ_USER -c "screen -X quit" echo " ... done." else echo "Coulnd't find a running $DESC" fi ;; restart) if [[ `su $AZ_USER -c "screen -ls |grep $NAME"` ]] then echo -n "Stopping $DESC: $NAME" su $AZ_USER -c "screen -X quit" echo " ... done." else echo "Coulnd't find a running $DESC" fi echo "Starting $DESC: $NAME" su $AZ_USER -c "cd $DIR; screen -dmS $NAME java -jar ./Azureus2.jar --ui=console" echo " ... done." ;; status) if [[ `su $AZ_USER -c "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
NOTE: Ubuntu uses dash as the low-level script interpreter invoked by 'sh' so this script will not work as-is on those systems. The quickest fix is to just change the first line to
#! /bin/bashinstead of
#! /bin/sh
Then chmod the scripts to make it executable
chmod a+x azureus_script
Test your script[edit]
Start Azureus by typing ./azureus_script start
You must be in the directory where your script is. At this point you have to enter the password of the "azureuser"-User twice. (When the script is loaded at startup, you don't have to do that!)
Re-attach the virtual console by screen -r azureus_screen
You should now see the normal console-ui of azureus.
Test also if you are able to connect to your AzureusHTMLWebUI in your Browser.
If this happened correctly, detach the azureus_screen again by pressing ctrl-a and then d
. The azureus console-ui should now be hidden.
Test now your stop-script by typing ./azureus_script stop
If Azureus was sucsessfully killed you can't find "java" in your process list typing top
except you have another Java programm running. Exit the process list by pressing q
If these tests were successfully, you can go further to the next step.
If your script does not start Azureus try this command from the command prompt within the Azureus directory.
java -jar ./Azureus2.jar --ui=console
If this command works the PATH in the script may be incomplete or wrong. Replace the value for PATH in the script with the value from the command:
echo $PATH
Install startscript[edit]
NOTE: This procedure will not work on Ubuntu (and could probably seriously mess up your init process)
On Ubuntu simply copy the script to "/etc/init.d/" (using root privileges) and run
sudo update-rc.d azureus_script default
Also, Debian init scripts should have an LSB defined in them, see [2]
Get superuser access
su
Copy your script in your runlevel-script directory. In most cases it is /etc/rc.d/
cp /home/azureuser/azureus/azureus_script /etc/rc.d/
Now create symbolic links in your default runlevel directory. One to start when entering the runlevel and another one to stop azureus tidily when leaving your runlevel, e.g. shutdown your copmuter.
First find out your default runlevel by typing
cat /etc/inittab | grep :initdefault:
the number on the line that outputs it is your default runlevel. Symlink the azureus_script into the directory of the default runlevel.
cd /etc/rc3.d ln -s /etc/rc.d/azureus_script S99azureus_script
All startscripts in your runlevel folder begin with "S" followed by a number, that gives the start-order. The number 99 makes the "azureus_script" script run after everything else at boot. Now when your machine starts up, the last thing that starts is azureus in console mode with a Web UI enabled.
Now, to stop Azureus tidily when you shutdown your computer, you must also create a symlink for your stop-script.
ln -s /etc/rc.d/azureus_script K01azureus_script
"K" means stop and the number 01 let quit azureus first, before other processes were killed.
Reboot[edit]
Reboot and try to connect to the Web-UI with your browser.