Here is a piece of my SysVinit file.


f_start() {
    echo -e "\nStarting : $NAME"
    start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --user $DAEMON_USER --exec $DAEMON

Does anyone knows where must be the error?

Also, it's terrible that in this situation, it is only writing the PID of ONE process into the pidfile. Therefore, if I do /etc/init.d/flask-daemon stop, it only kills the process which is related with the PID that was considered to be written into the file.

Processes (Why two?):

ps aux | grep run.py
root      3591  3.0  1.7 132700 17460 ?        S    19:27   0:00 /usr/bin/python /home/ubuntu/flask/run.py
root      3595  4.5  1.7 213144 18080 ?        Sl   19:27   0:00 /usr/bin/python /home/ubuntu/flask/run.py
root      3602  0.0  0.0  10460   948 pts/0    S+   19:27   0:00 grep --color=auto run.py

PID file:

$ cat /var/run/flask-daemon.pid

Just one process was killed...

ps aux | grep run.py
root      3595  0.3  1.7 213144 18080 ?        Sl   19:27   0:00 /usr/bin/python /home/ubuntu/flask/run.py
root      3613  0.0  0.0  10460   948 pts/0    S+   19:27   0:00 grep --color=auto run.py

Observation:> I also tried to use --startas, but it spawns two processes as well, an even worst: it records the PID from any other process into /var/run/flask-daemon.py, with exception of the PIDs from the daemons


Guessing you're daemon is running in daemon mode, so it's creating a copy of itself when it starts.

I think that might be what the "l" part of "Sl" means in the STAT column of your ps output.

I've been use python-daemon quite a bit recently and if that's what your script is using, you can tell it whether to detach the process or not in the constructor of your daemoncontext, just tell it not to do that and you should be golden.


don't use start-stop-daemon and just make a systemd service that utilizes the detach_process flag.


Do both and tell your process whether you want to detach the process or not.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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