init.d script for openSUSE

General support for problems installing or using Deluge
jferrandis
Member
Member
Posts: 10
Joined: Sat Mar 20, 2010 7:58 pm

Re: init.d script for openSUSE

Post by jferrandis »

Hi Cas,

Yes, it was not the u option, perhaps I don't explained well. I used the u option before write my first post, and the u option goes well, since I don't use console, I used System services-->Runlevels to start deluged and starts service but then when seing the daemon state it's stopped. Later I used console and I see what's happening, a permissions problem! I was trying to solve permissions when another outage came... Now electricity return.

I've added user deluge to system, at nogroup. I've seen that deluged puts it's preferences at /.config/deluge the first time you execute it. And seems there is no way to change it unless you edit python code. Ideas about it are wellcome.

I've changed /.config/deluge and inside files permissions to user deluge and group nogroup, and set nogroup granted to read and write, too. Then, added nogroup to my user. At /init.d/deluged I add user deluge and mine. It works fine because when electricity returns, I can see this process with command 'ps -ef|grep deluged':

root 2759 1 0 15:20 ? 00:00:00 startpar -f -- deluged
deluge 2878 1 0 15:20 ? 00:00:10 /usr/bin/python /usr/bin/deluged
jose 7748 7734 0 15:52 pts/0 00:00:00 grep deluged

But, if you do the same using System services-->Runlevels, deluged service don't starts. And now there is no answer about what happened. I've to change another time permissions, change deluge group to users, and retry. Deluge changed permissions of various files, core.conf, torrents.state, etc. And if you take a sight to folder /.config/deluge you can see a difference: when you use runlevels there is no file 'deluged.pid' that 'service deluged start' can create.

And I decomment at /init.d/deluged lines:

#DELUGED_ARGS="-P $DELUGED_PIDFILE" # consult man deluged for more options

#test -z "$DELUGED_USER" || exit 6

because if not it give me errors and deluged do not starts. A little while later, I've found what's the problem: pid file path and name of file. I've made this changes and proved it. It's OK.

Well, code now is:

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 deluged

### END INIT INFO

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

DELUGED_USER="deluge"        # CHANGE THIS
#test -z "$DELUGED_USER" || exit 6

DELUGED_PIDFILE=/.config/deluge/deluged.pid

DELUGED_ARGS="-P $DELUGED_PIDFILE"      # consult man deluged for more options

. /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 -u $DELUGED_USER $DELUGED_BIN $DELUGED_ARGS

	# 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.

	;;
    *)
	echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
	exit 1
	;;
esac
rc_exit
and the only problem is you can't use Service-->Runlevels to start deluged but from console you can 'service deluged start' and goes well.
Last edited by jferrandis on Sun Mar 21, 2010 11:18 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 »

For deluge-web, this is the script that runs, user deluged and no root.

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_USER="deluge"

. /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 -u $DELUGED_WEB_USER $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.

	;;
    *)
	echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
	exit 1
	;;
esac
rc_exit
For this the same to deluged, you'll have to start it from console. But all two (deluged and deluge-web) starts when system starts.
jferrandis
Member
Member
Posts: 10
Joined: Sat Mar 20, 2010 7:58 pm

Re: init.d script for openSUSE

Post by jferrandis »

We can include

test -n "$DELUGED_USER" || exit 6

instead of

#test -z "$DELUGED_USER" || exit 6

because if you add a user at DELUGED_WEB_USER="deluge" command 'test' with -z option returns if the length of the string contained in DELUGED_WEB_USER is zero. We need to use -n that returns true if var DELUGED_WEB_USER is not empty. As we have added a user, -n option is what we need.

For me, I have enough to do what I want... what do u think? Really, no!!! If I can't start deluged from Runlevels (openSuse Yast2-->System services-->Runlevels) I'll seek the nearest Cathedral and climb to the tower and throw me down. It's your responsibility it never occurs. Bye.
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 »

Ah good spot with test -n.

I don't understand why you're changing the pidfile to point to /.config?

If you specify a non-default pid address (like you have) then you need to pass -p <pidfile path> to startproc.

Also, could you edit the initscript wiki page to reflect the latest working version?
jferrandis
Member
Member
Posts: 10
Joined: Sat Mar 20, 2010 7:58 pm

Re: init.d script for openSUSE

Post by jferrandis »

Hi johnnyg,

Well I was juggling with my pride, when I saw my keyboard going from my hands to my navel and saw my apartment colleegue running to the street, and I said: move over busker, that's not my style, your time is coming in a little while, but mine is coming to realize my dreams. My sofa hit me to the left, hit me to the right, and I knew what you feel when an earthquake is hitting your ass. I needed only 20 seconds to finish my post and then I`ll try between step down stairs or throw me through the window (I'm in a second floor). But, another outage let my screen fading to black. One brugal bottle later, I can answer you.

I've changed the pidfile to point to /.config/deluge cause deluged daemon started as user can't write at system path. And I think I can't edit the wiki because another guy wrote it and I have not root privileges (hahaha).

But, I'm here and not seeking for a Cathedral, you know? Reading 'man deluged' I've discovered -c option, and used it. Solved file permissions. The new script let u use console and Runevels, and write at logfile if there is a problem:

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 deluged

### END INIT INFO

DELUGED_BIN=/usr/bin/deluged

test -x $DELUGED_BIN || exit 5

DELUGED_USER="deluge" 
test -n "$DELUGED_USER" || exit 6

DELUGED_ARGS="-P /.config/deluge/deluged.pid -c /.config/deluge/ -l /.config/deluge/deluged.log" # consult man deluged for more options

. /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 -u $DELUGED_USER $DELUGED_BIN $DELUGED_ARGS

	# 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.

	;;
    *)
	echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
	exit 1
	;;
esac
rc_exit
And I think all is done. Don't you? Find a Cathedral and tell me why.
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 »

jferrandis wrote:I've changed the pidfile to point to /.config/deluge cause deluged daemon started as user can't write at system path. And I think I can't edit the wiki because another guy wrote it and I have not root privileges (hahaha).
You need to register to be able to edit the wiki: http://dev.deluge-torrent.org/register

I think you mean ~/.config/deluge instead of /.config (that requires root permission to write to).
Which is the same as if you just don't specify anything at all.
Other than that, the scripts looks fine; you might want to update the web one as well.
jferrandis
Member
Member
Posts: 10
Joined: Sat Mar 20, 2010 7:58 pm

Re: init.d script for openSUSE

Post by jferrandis »

Which is the same as if you just don't specify anything at all.
I think it's not the same, at least what I've found is that if you don't specify anything deluged uses this path:

/root/.config/deluge

but in the other hand it's not a good idea store yor downloads there at system path (~/.config/deluge), it's easy to change it.

I'll try to edit scripts page. And thanks.
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 »

jferrandis wrote:I think it's not the same, at least what I've found is that if you don't specify anything deluged uses this path:

/root/.config/deluge
that should only happen if you run deluge as root, if you run it as a normal user the config files should be at /home/user/.config/deluge (where user is the user you're running as).
If that doesn't automatically happen then you could use the -c option to tell startproc to change to a different directory.
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 »

jferrandis,

Thank you so much for all your hard work with the init script.

However, I'm getting some errors while trying to run deluge-webd:

File "/usr/bin/deluge-web", line 8, in <module>
load_entry_point('deluge==1.2.1', 'console_scripts', 'deluge-web')()
File "/usr/lib/python2.6/site-packages/deluge/ui/web/web.py", line 115, in start
web.start()
File "/usr/lib/python2.6/site-packages/deluge/ui/web/web.py", line 101, in start
import server
File "/usr/lib/python2.6/site-packages/deluge/ui/web/server.py", line 202, in <module>
class Tracker(resource.Resource):
File "/usr/lib/python2.6/site-packages/deluge/ui/web/server.py", line 203, in Tracker
tracker_icons = TrackerIcons()
File "/usr/lib/python2.6/site-packages/deluge/ui/tracker_icons.py", line 80, in __init__
self.image_dir = os.path.join(deluge.configmanager.get_config_dir(), "icons")
File "/usr/lib/python2.6/site-packages/deluge/configmanager.py", line 132, in get_config_dir
return _configmanager.get_config_dir()
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/lib64/python2.6/os.py", line 150, in makedirs
makedirs(head, mode)
File "/usr/lib64/python2.6/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/root/.config'


I'm running as root.

I don't understand much of these errors, can someone please help and point me in the right direction to get this sorted?

Regards
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 »

are you pointing deluge-web to the same config directory as deluged?
Post Reply