Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have done a script to start transmission-daemon as a normal user:

start on filesystem
stop on runlevel [!2345]

respawn limit 10 5

pre-start script
    test -x /usr/bin/transmission-daemon || { stop; exit 0; }
    test -d /home/user/.config/transmission-daemon || { stop; exit 0; }
end script

exec su -l -c 'transmission-daemon --foreground --config-dir /home/user/.config/transmission-daemon --logfile /home/user/.config/transmission-daemon/daemon.log' user

This script works but I see two processes in execution of transmission-daemon:

user     5041  0.0  0.0  48556  1516 ?        Ss   01:10   0:00 su -l -c transmission-daemon --foreground --config-dir /home/user/.config/transmission-daemon --logfile /home/user/.config/transmission-daemon/daemon.log user
user     5048  0.5  0.0 150432  2960 ?        Sl   01:10   0:00 transmission-daemon --foreground --config-dir /home/user/.config/transmission-daemon --logfile /home/user/.config/transmission-daemon/daemon.log

Is this correct? Is there another way to execute this better?

Note: The default startup script of transmission package is disabled.

More info:

If I execute transmission as a daemon (without foreground) the problem is the detected PID by init:

start on filesystem
stop on runlevel [!2345]

expect fork

pre-start script
    test -x /usr/local/bin/transmission-daemon || { stop; exit 0; }
    test -d /home/mario/.config/transmission-daemon || { stop; exit 0; }
end script

exec sudo -u user transmission-daemon --config-dir /home/user/.config/transmission-daemon --logfile /home/user/.config/transmission-daemon/daemon.log


$ sudo initctl list | grep trans
trans-test start/running, process 3110

but really this is the PID of sudo (finished process), the transmission-daemon PID is another:

$ ps aux 
user     3148  0.0  0.0 154848  2708 ?        Ssl  13:33   0:00 transmission-daemon 
share|improve this question
Am I correct in assuming that you already know about and have disabled the System V startup script that is installed by default? –  ændrük Jul 7 '11 at 0:03
Yes, the default startup script is disabled and that script doesn't start transmission-daemon with foreground. –  Simón Jul 7 '11 at 9:40
add comment

4 Answers 4

When you start an app with su -c, su will wait for the app to terminate. In your case, having added the --foreground option, make transmission to not detach from its parent. So you will see su as a parent process of transimssion-daemon for all the time the latter lives.

If you remove that option, you will see that su process will terminate as soon as transmission-daemon goes to the background.

Apart from removing that option that seems inopportune for a service, I suggest to use

sudo -u <your-user> app-name options

instead of su, being more close to the Ubuntu way of doing things, and being more simple to manage options without the need to use single quotes.

share|improve this answer
But if I supress foreground, init detects wrong the process PID. It saves the PID of sudo but sudo is finished: initctl: trans-test start/running, process 3110 but the process has other PID: user 3148 0.0 0.0 154848 2708 ? Ssl 13:33 0:00 transmission-daemon –  Simón Jul 8 '11 at 12:06
An untested alternative could be to get ownership of the executable (sudo chown $USER:$USER /usr/bin/transmission-daemon), then make it setuid (chmod u+s /usr/bin/transmission-daemon). –  enzotib Jul 8 '11 at 12:28
Thanks, but this doesn't work for me. Tranmission will be executed twice with different users. –  Simón Jul 8 '11 at 13:30
Executed twice, and with different users in addition, is very very strange –  enzotib Jul 8 '11 at 13:40
Yes, one transmission-daemon for each system user. –  Simón Jul 14 '11 at 12:54
add comment

Ok, the solution is to start transmission-daemon in foreground (no expect fork or daemon) and that start-stop-daemon creates the pid file.
The complete script:

description "Transmission daemon for user"

start on (local-filesystems and net-device-up IFACE=eth0 and runlevel [235])
stop on runlevel [016]

kill timeout 50


env USER=user
env PIDFILE=/var/run/transmission-user.pid

    DAEMON=$(which transmission-daemon) || exit 0

    exec start-stop-daemon --start --quiet --chuid $USER --pidfile $PIDFILE --make-pidfile --exec $DAEMON -- -f --config-dir $CONFIGDIR --logfile $CONFIGDIR/daemon.log
end script

post-stop exec rm -f $PIDFILE
share|improve this answer
add comment

Using --foreground is correct—you want upstart to track the progress of your transmission process. To omit --foreground add expect daemon to the init config which will follow two forks of the process, which is how services daemonize.

Using start-stop-daemon is suboptimal as upstart can't watch your process and respawn it as necessary in case of crash, etc.

Here's my config:

start on (runlevel [2345] and filesystem and networking)
stop on runlevel [!2345]

kill timeout 30

setuid transmission

exec /usr/bin/transmission-daemon --foreground --config-dir /var/lib/transmission
share|improve this answer
add comment

My version:

start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [!2345]

# give time to send info to trackers
kill timeout 30

expect fork

        test -f /etc/default/transmission-daemon && . /etc/default/transmission-daemon
        test "$ENABLE_DAEMON" != "0" || exit 0
        exec start-stop-daemon --start --quiet --chuid $USER --exec /usr/bin/transmission-daemon -- $OPTIONS
end script

Woks good:

root@ubuntu-server:/etc/init# status transmission-daemon
transmission-daemon start/running, process 754
root@ubuntu-server:/etc/init# ps aux|grep [t]ransmission-daemon
torrent    754  0.0  1.1  41592  5596 ?        Ssl  Oct21   0:56 /usr/bin/transmission-daemon --auth --config-dir /var/lib/transmission-daemon/info
share|improve this answer
This script doesn't work to me: transmission-simon start/running, process 5880 but process 5880 doesn't exist. I think upstart takes the PID of start-stop-daemon command instead of the transmission-daemon. –  Simón Oct 22 '11 at 23:15
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.