Friday, January 5, 2007

Howto: get Azureus to start at boot and run headless (ie without a gui) on Linux

Getting Azureus to start at boot headless saves system resources and means it will work away nicely in the background. This approach works great with a web front-end like the Azureus Swing UI. To get the most out of bittorrent, you also need to make sure that it shuts down properly. Here are the steps I used to set it up...

Install and configure Azureus
  • Download Azureus and decompress it into a directory
  • Download log4j.jar and commons-cli.jar and put them in the directory you uncompressed Azureus into
  • Run Azureus by opening a terminal, changing into the directory you put Azureus and typing
  • Configure Azureus with the GUI tool
  • Exit Azureus
  • Create a file called with the following in it:
java -jar Azureus2.jar --ui=console >/dev/null 2>&1
  • Make that file executable by typing
chmod u+x
  • Create a file called azureus_rcscript with the following in it: (you need to change the AZ_USER and DIR variables to represent the name of the user who will be running Azureus and the directory Azureus is installed to)
#! /bin/sh
#rc script for Azureus by Phill -
#Based on script from Azureus wiki -

#The user that will run Azureus

#your path to the azureus directory, where Azureus2.jar is located

#executable files in the following paths that are perhaps needed by the script

DESC="Azureus daemon"

case "$1" in
if [[ ` ps -ef | grep "java -jar Azureus2.jar --ui=console"|grep -v grep` ]]
echo "Azureus is already running!"
echo "Starting $DESC"
su $AZ_USER -c "cd $DIR; ./"
if [[ ` ps -ef | grep "java -jar Azureus2.jar --ui=console"|grep -v grep` ]]
echo -n "Stopping $DESC"
su $AZ_USER -c "kill `ps -ef | grep "java -jar Azureus2.jar" | grep -v grep | awk '{print $2}'`"
echo " ... done."
echo "Coulnd't find a running $DESC"
if [[ ` ps -ef | grep "java -jar Azureus2.jar --ui=console"|grep -v grep` ]]
echo -n "Stopping $DESC"
su $AZ_USER -c "kill `ps -ef | grep "java -jar Azureus2.jar" | grep -v grep | awk '{print $2}'`"
echo " ... done."
echo "Coulnd't find a running $DESC"
echo "Starting $DESC: $NAME"
su $AZ_USER -c "cd $DIR; ./"
echo " ... done."
if [[ ` ps -ef | grep "java -jar Azureus2.jar --ui=console"|grep -v grep` ]]
echo "Azureus is RUNNING"
echo "Azureus is DOWN"
echo "Usage: $0 {start|stop|status|restart}"
exit 1

exit 0

  • Put that file inside the startup for the runlevel your machine runs at. For my machine, that is runlevel 5, and it is probably the same for yours if it boots up to a graphical environment. I did this by typing
mv /etc/rc5.d/
cp /etc/rc5.d/ /etc/rc5.d/
chmod 755 /etc/rc5.d/ /etc/rc5.d/
  • The S99 makes it run this script after everything else has started up, which is good as it makes sure it won't try to run before things like network services have started. As the script also includes functionality to shut down Azureus, I copied it to have it run when we leave runlevel 5, which usually means shutdown time. The K01 means to run it before shutting down any other processes
That's it! If you reboot you should now have Azureus running in headless mode, and shutting down cleanly when you shutdown the system.

Please let me know if this works for you, and if you have any questions!


David said...

Hi Phil,

Just tried this script out. Seems to launch azureus great (i can connect through html webui), but my linux box hangs during system startup. I get the message

"Starting Starting Azureus daemon", but it never goes to OK.

Any thoughts?

Phill said...

Thanks for the comment David. My first thoughts are:

The line it is hanging on is probably:
su $AZ_USER -c "cd $DIR; ./"

Have you set the AZ_USER to a user that exists and has permission to run Azureus and DIR to the directory containing azureus? If you're using your own account (eg. david) and have decompressed all the files as that user then having something like:


should work.

If the above has been set correctly and it still isn't working then I'll need more information. It would help if you could give me an "ls -l" of your /etc/rc5.d/, and also let me know if running "/etc/rc5.d/
start" and "/etc/rc5.d/ stop" works

Thanks again for the feedback.

John Jacklitsch said...

Hello phill,

It's been quite awhile since this posting. Are you still involved with this topic. I'm having the same problem as david had.

UniIsland said...

hi Phill,

this is a good alternative script to the official screen method, running azureus as a daemon

but do you think azureus can shutdown "tidily" when the process is simply killed?

Louis said...

Killing the java process with just the plain kill command gives it a chance to close properly. If the script called "kill -9" then no, it wouldn't close nicely.

P.S. Thanks Phill. The script works great for me in slackware (with some mods). I changed it so that it didn't rely on for launching the program but instead just did it directly inside the script.

I've posted my modified version here:

Anyone know what I need to change to make restart work properly?

Louis said...

Azureus Daemon in Slackware

Making clicky link.

Bferd said...

I keep getting this error

/etc/init.d/ 65: [[: not found

UniIsland said...

maybe line break at wrong place.

Orban said...

Write this in the file

java -jar Azureus2.jar --ui=console < /dev/null >>logfile.txt 2>>errorfile.txt&

And the "Starting Starting Azureus daemon" problem on boot disappear.

1lias3 said...

to avoid the kill, another approach is to use the telnetUI as below:

start azureus as with :

--ui=telnet (instead of --ui=console)

it will start a telnet server, for example:

changeLocale: no message properties for Locale 'English (United States)' (en_US), using 'English (default)'
Telnet server started. Listening on port: 57006

you have telnet access now (telnet 0 57006) to manage azureus

and to stop it, there is supported command "quit iamsure" which will stop (not kill) the app in regular way!

this is what i decided to use, hope it helps if you are interested :)

Abd Halim Haris said...
This comment has been removed by the author.
Abd Halim Haris said...

I get the [[: not found
my fix is change
#! /bin/sh
#! /bin/bash