start-stop-daemon not working as expected, no pid file was written
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
Related videos on Youtube
daisy
Updated on September 18, 2022Comments
-
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 almost 10 yearsOkay the pidfile is written. But stop part still not functioning, same error message
-
daisy almost 10 yearsDone, substituted name to
python
and it worked ;-P -
phemmer almost 10 yearsRight, yes,
$name
has to match too. Completely missed that you were passing that in. Will update the answer.