I have done a script to start transmission-daemon as a normal user:
start on filesystem
stop on runlevel [!2345]
respawn
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 PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
user 3148 0.0 0.0 154848 2708 ? Ssl 13:33 0:00 transmission-daemon
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:
Using
--foreground
is correct—you want upstart to track the progress of your transmission process. To omit--foreground
addexpect 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:
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 seesu
as a parent process oftransimssion-daemon
for all the time the latter lives.If you remove that option, you will see that
su
process will terminate as soon astransmission-daemon
goes to the background.Apart from removing that option that seems inopportune for a service, I suggest to use
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.My version:
Woks good: