start-stop-daemon not working as expected, no pid file was written

39,325

start-stop-daemon --start --pidfile "$pid" doesn't write to the pid file unless --make-pidfile (-m) is specified. Without --make-pidfile it is up to the program being launched to create it. Also for --make-pidfile to work, the process being launched can't daemonize itself (via a fork), as then start-stop-daemon won't know what PID it should put in the file.

The only thing --pidfile "$pid" does in your usage scenario is that it will result in start-stop-daemon not starting the program if it is already running.


If process still is not stopping, all the criteria passed to start-stop-daemon --stop must match. Meaning $pid has to be a running process, the UID of the process has to match $user, and the process name (arg0) has to match $name.
You can determine the value of arg0 by doing ps h -p $pid -o comm

Share:
39,325

Related videos on Youtube

daisy
Author by

daisy

Updated on September 18, 2022

Comments

  • daisy
    daisy over 1 year

    I'm trying to control a python based program (which doesn't detach itself from console)

    #!/bin/bash
    
    user=nobody
    pid=/var/run/xx.pid
    name=xx
    prog=/xx.py
    
    case $1 in
        start)
            /sbin/start-stop-daemon --start -b --oknodo --user "$user" --name "$name" --pidfile "$pid" --startas "$prog" --chuid nobody -- --daemon
            ;;
        stop)
            /sbin/start-stop-daemon --stop --oknodo --user "$user" --name "$name" --pidfile "$pid" --retry=TERM/5/KILL/1
            ;;
        restart)
            ;;
        *)
            ;;
    esac
    

    The start part works fine. I can see the script up and running, but the stop part doesn't. It simply says No xx found running; none killed.

    So I guess there's something wrong with the start part?

  • daisy
    daisy almost 10 years
    Okay the pidfile is written. But stop part still not functioning, same error message
  • daisy
    daisy almost 10 years
    Done, substituted name to python and it worked ;-P
  • phemmer
    phemmer almost 10 years
    Right, yes, $name has to match too. Completely missed that you were passing that in. Will update the answer.