init.d script for openSUSE

General support for problems installing or using Deluge
primus
New User
New User
Posts: 8
Joined: Fri Mar 19, 2010 1:07 am
Location: Norway

init.d script for openSUSE

Post by primus »

Edit: InitScript for OpenSUSE

Hi guys,

I'm loving the Deluge torrent client, especially the polished AJAX webui. Unfortunately I'm having difficulties running it as a daemon. With the daemon running from an SSH window I can connect to the web UI fine but if I close the SSH client the daemon (obviously) stops and the web UI stops responding.

I would like to be able to invoke Deluge from an /etc/init.d script so I can set it up to run at startup on my headless openSUSE server.

I am pretty new to linux, and even though I've tried to follow the instructions in the init.d/skeleton file I'm not getting any closer. Any help would be greatly appreciated!

Regards
johnnyg
Top Bloke
Top Bloke
Posts: 1522
Joined: Sun Oct 28, 2007 4:00 am
Location: Sydney, Australia

Re: init.d script for openSUSE

Post by johnnyg »

There are init scripts here: http://dev.deluge-torrent.org/wiki/UserGuide/InitScript
however there doesn't seem to be one for openSuse :(

The daemon shouldn't stop when you close the ssh session as you should be running it in the background.
The web ui however will stop. You could run it in screen as a quick fix.

If you do decide to write an init script for openSuse, feel free to add it to the wiki page :)
primus
New User
New User
Posts: 8
Joined: Fri Mar 19, 2010 1:07 am
Location: Norway

Re: init.d script for openSUSE

Post by primus »

Yes, you are correct. The daemon keep running when closing the SSH session, but the webui stops.

I'll try fiddling with screen, but I would really appreciate if someone stepped up and wrote a init script for openSUSE as I've got no clue how to do it :|
jferrandis
Member
Member
Posts: 10
Joined: Sat Mar 20, 2010 7:58 pm

Re: init.d script for openSUSE

Post by jferrandis »

Hello primus,

I need this init.d script too, so I wrote it, but there is a problem still no resolved... the process user is root, I've tried to resolve this issue but I can't.

Code: Select all

#! /bin/sh
# Copyright (c) 1995-2000 SuSE GmbH Nuernberg, Germany.
#
# Author: José Ferrandis
#
# /etc/init.d/deluged
#
#   and symbolic its link
#
# /usr/sbin/deluged
#
### BEGIN INIT INFO
# Provides: deluged
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network

# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: Daemonized version of deluge.
# Description:       Starts the deluge daemon with the user specified in
#                    /home/jose/.config/deluge/core.conf

### END INIT INFO

DELUGED_BIN=/usr/bin/deluged
test -x $DELUGED_BIN || exit 5

DELUGED_SYSCONFIG=/home/jose/.config/deluge/core.conf
test -r $DELUGED_SYSCONFIG || exit 6
. $DELUGED_SYSCONFIG

DELUGED_PIDFILE=/var/run/deluged.init.pid

. /etc/rc.status

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status

# First reset status of this service
rc_reset

case "$1" in
    start)
        
	echo -n "Starting DELUGE daemon"
	## Start daemon with startproc(8). If this fails
	## the echo return value is set appropriate.

	startproc -f $DELUGED_BIN

	# Remember status and be verbose
	rc_status -v
	;;
    stop)
	echo -n "Shutting down DELUGE daemon"
	## Stop daemon with killproc(8) and if this fails
	## set echo the echo return value.

	killproc -TERM $DELUGED_BIN

	# Remember status and be verbose
	rc_status -v
	;;
    try-restart)
        ## Stop the service and if this succeeds (i.e. the 
        ## service was running before), start it again.
        $0 status >/dev/null &&  $0 restart

        # Remember status and be quiet
        rc_status
        ;;
    restart)
        ## Stop the service and regardless of whether it was
        ## running or not, start it again.
        $0 stop
        $0 start

        # Remember status and be quiet
        rc_status
        ;;
    force-reload|reload)
	## Signal the daemon to reload its config. Most daemons
	## do this on signal 1 (SIGHUP).

	echo -n "Reload service DELUGED"

	killproc -HUP $DELUGED_BIN

        rc_status -v

        ;;
    status)
	echo -n "Checking for service DELUGED "
        ## Check status with checkproc(8), if process is running
        ## checkproc will return with exit status 0.

        # Status has a slightly different for the status command:
        # 0 - service running
        # 1 - service dead, but /var/run/  pid  file exists
        # 2 - service dead, but /var/lock/ lock file exists
        # 3 - service not running

	checkproc $DELUGED_BIN

	rc_status -v
	;;
    probe)
	## Optional: Probe for the necessity of a reload,
	## give out the argument which is required for a reload.

        #test /etc/ssh/sshd_config -nt $SSHD_PIDFILE && echo reload
	;;
    *)
	echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
	exit 1
	;;
esac
rc_exit
Name it as deluged and put it into init.d, let execute as a application and add it to runlevels 3 5 or runlevel you want... I have wicd instead of networkmanager and when openSuse starts, no need to log as user and deluged starts (as root).

I'm newbie to this, and could be it can be done better (as my english)... if someone can help us, wellcome!!!
Last edited by jferrandis on Sat Mar 20, 2010 9:57 pm, edited 1 time in total.
jferrandis
Member
Member
Posts: 10
Joined: Sat Mar 20, 2010 7:58 pm

Re: init.d script for openSUSE

Post by jferrandis »

And, the same script modified to start deluge-web, name it deluge-webd and the same as the other one. You'll have the deluge web console.

Code: Select all

#! /bin/sh
# Copyright (c) 1995-2000 SuSE GmbH Nuernberg, Germany.
#
# Author: José Ferrandis
#
# /etc/init.d/deluge-webd
#
#   and symbolic its link
#
# /usr/sbin/deluge-webd
#
### BEGIN INIT INFO
# Provides: deluge-webd
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network

# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: Daemonized version of deluge-web.
# Description:       Starts the deluge-web daemon with the user specified in
#                    /home/jose/.config/deluge/web.conf

### END INIT INFO

DELUGED_WEB_BIN=/usr/bin/deluge-web
test -x $DELUGED_WEB_BIN || exit 5

DELUGED_WEB_SYSCONFIG=/home/jose/.config/deluge/web.conf
test -r $DELUGED_WEB_SYSCONFIG || exit 6
. $DELUGED_WEB_SYSCONFIG

DELUGED_WEB_PIDFILE=/var/run/deluge-webd.init.pid

. /etc/rc.status

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status

# First reset status of this service
rc_reset

case "$1" in
    start)
        
	echo -n "Starting DELUGE-WEB daemon"
	## Start daemon with startproc(8). If this fails
	## the echo return value is set appropriate.

	startproc -f $DELUGED_WEB_BIN

	# Remember status and be verbose
	rc_status -v
	;;
    stop)
	echo -n "Shutting down DELUGE-WEB daemon"
	## Stop daemon with killproc(8) and if this fails
	## set echo the echo return value.

	killproc -TERM $DELUGED_WEB_BIN

	# Remember status and be verbose
	rc_status -v
	;;
    try-restart)
        ## Stop the service and if this succeeds (i.e. the 
        ## service was running before), start it again.
        $0 status >/dev/null &&  $0 restart

        # Remember status and be quiet
        rc_status
        ;;
    restart)
        ## Stop the service and regardless of whether it was
        ## running or not, start it again.
        $0 stop
        $0 start

        # Remember status and be quiet
        rc_status
        ;;
    force-reload|reload)
	## Signal the daemon to reload its config. Most daemons
	## do this on signal 1 (SIGHUP).

	echo -n "Reload service DELUGED_WEB"

	killproc -HUP $DELUGED_WEB_BIN

        rc_status -v

        ;;
    status)
	echo -n "Checking for service DELUGED_WEB "
        ## Check status with checkproc(8), if process is running
        ## checkproc will return with exit status 0.

        # Status has a slightly different for the status command:
        # 0 - service running
        # 1 - service dead, but /var/run/  pid  file exists
        # 2 - service dead, but /var/lock/ lock file exists
        # 3 - service not running

	checkproc $DELUGED_WEB_BIN

	rc_status -v
	;;
    probe)
	## Optional: Probe for the necessity of a reload,
	## give out the argument which is required for a reload.

        #test /etc/ssh/sshd_config -nt $SSHD_PIDFILE && echo reload
	;;
    *)
	echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
	exit 1
	;;
esac
rc_exit
Ah, one thing change the user at this line by yours:

DELUGED_WEB_SYSCONFIG=/home/jose/.config/deluge/web.conf

and too in the deluged script:

DELUGED_SYSCONFIG=/home/jose/.config/deluge/core.conf
johnnyg
Top Bloke
Top Bloke
Posts: 1522
Joined: Sun Oct 28, 2007 4:00 am
Location: Sydney, Australia

Re: init.d script for openSUSE

Post by johnnyg »

I've added it to the InitScript page: http://dev.deluge-torrent.org/wiki/User ... InitScript
Could someone check that it works?
I added the -u option so you should be able to run deluged not as root (you shouldn't run things as root).
I also removed the config stuff as I didn't see the point of it (feel free to add it back in if it's vital).
jferrandis
Member
Member
Posts: 10
Joined: Sat Mar 20, 2010 7:58 pm

Re: init.d script for openSUSE

Post by jferrandis »

Yesterday I was trying to post when suddenly we suffer an outage... In Dominican Republic is usual, I'm here 2 months and I'm desperate: I need a inversor (yes, I'm not in a 24 hours zone now).

You are OK, the config stuff is not necessary, and also don't point to correct script, I'm not sure where is the correct one but near to discover, I was tracing the python program when outage came. So delete or decomment it.

But, if you add the u option, the daemon don't starts. I can't do it now because I'm in a Mac but when at home I'll edit the post and add the error that console shows if yo make a ' service deluged start'. Until now, best option is to remove the u option and, I know you shouldn't run as root, but until we do not figure out how to do better, it's the only way, without u option you'll have a pretty green message: done.
Cas
Top Bloke
Top Bloke
Posts: 3681
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: init.d script for openSUSE

Post by Cas »

jferrandis wrote:But, if you add the u option, the daemon don't starts.
Did you change the following line in the init script as this would be required for the -u option to work.

Code: Select all

DELUGED_USER=""        # CHANGE THIS
jferrandis
Member
Member
Posts: 10
Joined: Sat Mar 20, 2010 7:58 pm

Re: init.d script for openSUSE

Post by jferrandis »

if you write on console 'service deluged start' you obtain:

Code: Select all

Starting DELUGE daemon                                              [color=#40BF00]done[/color]
Traceback (most recent call last):

File "/usr/bin/deluged", line 8, in <module>
    load_entry_point('deluge==1.2.1', 'console_scripts', 'deluged')()
  File "/usr/lib/python2.6/site-packages/deluge/main.py", line 189, in start_daemon
    open_logfile()
  File "/usr/lib/python2.6/site-packages/deluge/main.py", line 172, in open_logfile
    options.logfile = deluge.configmanager.get_config_dir("deluged.log")
  File "/usr/lib/python2.6/site-packages/deluge/configmanager.py", line 130, in get_config_dir
    return os.path.join(_configmanager.get_config_dir(), filename)
  File "/usr/lib/python2.6/site-packages/deluge/configmanager.py", line 93, in get_config_dir
    return self.config_directory
  File "/usr/lib/python2.6/site-packages/deluge/configmanager.py", line 51, in config_directory
    self.__config_directory = deluge.common.get_default_config_dir()
  File "/usr/lib/python2.6/site-packages/deluge/common.py", line 138, in get_default_config_dir
    return xdg.BaseDirectory.save_config_path("deluge")
  File "/usr/lib/python2.6/site-packages/xdg/BaseDirectory.py", line 59, in save_config_path
    os.makedirs(path, 0700)
  File "/usr/lib/python2.6/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/.config/deluge'
Cas
Top Bloke
Top Bloke
Posts: 3681
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: init.d script for openSUSE

Post by Cas »

Code: Select all

Permission denied: '/.config/deluge'
That suggests the daemon user does not have the permissions to create a new config file. As a quick workaround you could specify a different config file location for example deluged -c /home/user/.config/deluge
Post Reply