Auto-start Daemon without scripting?

General support for problems installing or using Deluge
Post Reply
_jonte

Auto-start Daemon without scripting?

Post by _jonte »

Hi,
New to Deluge and just just got everything set up perfect with the daemon running on my HTPC and the client on my laptop. The only thing missing is auto-start of Deluge Daemon.

I've searched the forum and found several references to a start-up script available on the web-site. This seem in my Ubuntu_newbie_eyes to be pretty much overkill(??). So I'm wondering if there is a simpler way to to this? All I want to do is to get the Daemon process running on start-up. Is it not possible to just add this somewhere?

I'm very new to Linux and really don't know anything about scripting. However my HTPC is set up with Ubuntu 10.04, and running XBMC as a session on start-up (no Gnome).

Thank you on advance!
diablo_man5666
Member
Member
Posts: 14
Joined: Mon Jul 20, 2009 3:56 am

Re: Auto-start Daemon without scripting?

Post by diablo_man5666 »

Not sure if you got anything working, but here is the script I use to start deluged on boot. Put it in '/etc/init.d/.' I called mine 'deluge-daemon.' You have to make it executable, and then add it to the boot list. The instructions at https://help.ubuntu.com/community/UbuntuBootupHowto can probably help you with this. Don't forget to change that USERNAME variable, or nothing will work.

Code: Select all

#!/bin/bash
#
# Deluged startup script
#
# Jonathan J Simon
#
# Just change USERNAME to equal the username you wish to run Deluged as. Keep in mind that you may have to modify
# the switches to fit your setup. For example, if you don't want or need logging enabled,
# simply set LOGGING to false, and/or change LOG to point to somewhere
# where you actually want to put log files. The user you specify as USERNAME must have write permissions to that location.
# I utilize the --config switch just to be sure Deluged knows where the correct config location is. The currently set location
# is the default location on Ubuntu, and probably Debian, systems. If you want to change that location, just change CONFIG
# to point to somewhere else.
#
# This script is probably not the most elegant way to do it, but it works.

USERNAME="<YOUR USERNAME>"
CONFIG="/home/$USERNAME/.config/deluge/"
LOG="/home/$USERNAME/logs/deluged.log"
LOGGING="true" # must be lowercase 'true' or 'false'




#################################################################################################################
###############DON'T CHANGE ANYTHING BELOW THIS LINE UNLESS YOU REALLY KNOW WHAT YOU ARE DOING###################
#################################################################################################################
if [ $LOGGING = 'true' ]; then
    LOGGING="-L debug -l $LOG"
else
    LOGGING="";
fi

NUMD=$(ps aux | grep deluged | grep bin -c)
SCRIPT=$(basename $0)
USAGE=$"Usage: $SCRIPT {start|stop|restart|status|usage}"
PID=$(ps aux | grep -m 1 '/deluge' | awk '{print $2}')

# Start
start() {
    echo -n "Starting deluged: "
    if [ -e /var/lock/deluged ]; then
	echo
	echo -n -e '\E[31;40mError: '; tput sgr0
	echo "Deluge appears to be already running. Lockfile found at /var/lock/deluged."
	status
	exit 1;
    else
	/bin/su $USERNAME -c "/usr/bin/deluged $LOGGING --config=$CONFIG" &
        ### Create lock file ###
        touch /var/lock/deluged
	echo -e '\E[32;40m[OK]'; tput sgr0
    fi
}

# Stop
stop() {
    echo -n "Stopping deluged: "
    killall deluged
    ### Remove lock file ###
    rm -f /var/lock/deluged
    echo -e '\E[32;40m[OK]'; tput sgr0
}

# Status
status() {
    if [ $NUMD -eq 0 ]; then
	echo "Stopped"
        exit 1
    else
        echo "Started - [$NUMD instance(s) PID: $PID]"
        exit 0
    fi
}

case "$1" in
    start)
	start
	 ;;
    stop)
	stop
	;;
    restart)
	stop
	start
	;;
    status)
	status
	;;
    usage)
	echo $USAGE
	;;
    *)
	echo "Oops, if you got this message, something went very wrong."
	echo $USAGE
	exit 1
esac

exit 0

Post Reply