Upstart – Command Runs in Bash but Not from /etc/init: Troubleshooting

initupstart

I'm having some trouble with this init script.

When I run the command I'm passing to start-stop-daemon from the command line it works perfectly, even if I run it sudoed as the userid in the script, but for some reason the command:

sudo service start deluged

prints this:

deluged start/stopping  

but I can't see any deluged processes using top, htop or ps aux, and I can't connect to it on the port it's supposed to be listening to (or any other port).

I'm out of ideas for what to try next. Running the init script fails before anything is written to the logfile, so I have no idea what's going wrong.

I'm 100% convinced the user and group exist and aren't typoed, but it's possible they're misconfigured in some way, since I made them manually and might have missed something. I'm also pretty sure that user has permission to access all the relevant files for the program.

Here's the script, I have no idea what I've done wrong (and I took most of this from the deluged documentation anyway!)

#deluged - Deluge daemon                                                                                                                         
#                                                                                                                                                 

# The daemon component of Deluge BitTorrent client. Deluge UI clients                                                                             
# connect to this daemon via DelugeRPC protocol.                                                                                                  



description "Deluge daemon"                                                                                                                       
author "Deluge Team"                                                                                                                              

start on filesystem and static-network-up                                                                                                         
stop on runlevel [016]                                                                                                                            

respawn                                                                                                                                           
respawn limit 5 30                                                                                                                                

env uid=debian-deluged                                                                                                                            
env gid=debian-deluged                                                                                                                            
env umask=007                                                                                                                                     

exec start-stop-daemon -S -c $uid:$gid -k $umask -x /usr/bin/python /usr/bin/deluged -L info -l /var/log/deluged/server.log -c /var/opt/deluged/config -p 8112 -- -d  

Best Answer

The deluge docs have something similar to yours but I think this is a hangover from very old versions of Upstart. I'd try simplifying it down to something like this first:

description "Deluge daemon"
author "Deluge Team"

start on filesystem and static-network-up
stop on runlevel [016]

respawn
respawn limit 5 30

setuid debian-deluged
setgid debian-deluged
umask 007

exec /usr/bin/python /usr/bin/deluged -L info -l /var/log/deluged/server.log -c /var/opt/deluged/config -p 8112 -- -d

And then if that still doesn't work, check the permissions on /var/log/deluged/ and /var/log/deluged/server.log (that the debian-deluged user can write there). If it's still not working then, the upstart log files might help you out. Yours will be /var/log/upstart/deluged.log. If that shows nothing, we could just try launching the command as the right user:

sudo -u debian-deluged -g debian-deluged /usr/bin/python /usr/bin/deluged -L info -l /var/log/deluged/server.log -c /var/opt/deluged/config -p 8112 -- -d
Related Question