Instead of start_stop_daemon_args="--name ${SVCNAME}" I have to write stop() { start-stop-daemon --name ${SVCNAME} -K } in /etc/init.d/mydaemon script otherwise `/etc/init.d/mydaemon stop` prints mydaemon | * start-stop-daemon: no matching processes found [ ok ] Reproducible: Always
start_stop_daemon_args only gets passed in the start function. Try setting the 'procname' variable instead. procname="${SVCNAME}" From start-stop-daemon.sh: ssd_start() { ... eval start-stop-daemon --start \ --exec $command \ ${chroot:+--chroot} $chroot \ ${procname:+--name} $procname \ ${pidfile:+--pidfile} $pidfile \ ${command_user+--user} $command_user \ $_background $start_stop_daemon_args \ -- $command_args $command_args_background ... } ssd_stop() { ... start-stop-daemon --stop \ ${retry:+--retry} $retry \ ${command:+--exec} $command \ ${procname:+--name} $procname \ ${pidfile:+--pidfile} $chroot$pidfile \ ${stopsig:+--signal} $stopsig ... }
Created attachment 438528 [details, diff] document the procname variable I see this variable is undocumented. Here's a patch to fix that.
Yes, procname="${SVCNAME}" did the trick. But only if init-script name is the same as executable name. Otherwise even `start-stop-daemon --name ${SVCNAME} -K` not works.
(In reply to Dmitri Bogomolov from comment #3) > Yes, procname="${SVCNAME}" did the trick. But only if init-script name is > the same as executable name. Otherwise even `start-stop-daemon --name > ${SVCNAME} -K` not works. So then set procname to the name of the executable instead.
(In reply to Mike Gilbert from comment #4) > (In reply to Dmitri Bogomolov from comment #3) > > Yes, procname="${SVCNAME}" did the trick. But only if init-script name is > > the same as executable name. Otherwise even `start-stop-daemon --name > > ${SVCNAME} -K` not works. > > So then set procname to the name of the executable instead. It's pointless if I run many copies of the same executable with symlinked init-scripts.
(In reply to Dmitri Bogomolov from comment #5) > It's pointless if I run many copies of the same executable with symlinked > init-scripts. So use pidfiles instead. I'm not sure how you would expect it to work otherwise.
Oh, I see. You're trying to set the process name to an arbitrary value that differs based on the service name. That might be a bug indeed.
(In reply to Mike Gilbert from comment #6) > (In reply to Dmitri Bogomolov from comment #5) > > It's pointless if I run many copies of the same executable with symlinked > > init-scripts. > > So use pidfiles instead. I'm not sure how you would expect it to work > otherwise. That executable forks to random pid and have no argument to store it in file.
The only reason SVCNAME is there at all is for compatibility with old bl1 scripts until they switch to the documented variable, which is RC_SVCNAME, so please use that to refer to the service name, not SVCNAME. Unfortunately there is no way for me to print out warnings when scripts use the wrong variable; I'm not sure how I'm going to handle that yet.
(In reply to Dmitri Bogomolov from comment #3) > Yes, procname="${SVCNAME}" did the trick. But only if init-script name is > the same as executable name. Otherwise even `start-stop-daemon --name > ${SVCNAME} -K` not works. I had no problem getting your use case to work with openrc-19.1. Using the example daemon and init script below, I was able to successfully start and stop three instances of the "mydaemon" service. openrc ~ # cat /etc/init.d/mydaemon #!/sbin/openrc-run command="/usr/local/bin/mydaemon" procname="${RC_SVCNAME}" openrc ~ # ls -l /etc/init.d/mydaemon* -rwxr-xr-x 1 root root 78 Jun 23 20:40 /etc/init.d/mydaemon lrwxrwxrwx 1 root root 8 Jun 23 11:26 /etc/init.d/mydaemon.a -> mydaemon lrwxrwxrwx 1 root root 8 Jun 23 11:26 /etc/init.d/mydaemon.b -> mydaemon lrwxrwxrwx 1 root root 8 Jun 23 20:38 /etc/init.d/mydaemon.c -> mydaemon openrc ~ # cat mydaemon.c #include <stdlib.h> #include <stdio.h> #include <unistd.h> int main(int argc, char **argv) { if (daemon(0, 0)) { perror(argv[0]); exit(1); } pause(); return 0; }
(In reply to Mike Gilbert from comment #10) > (In reply to Dmitri Bogomolov from comment #3) > > Yes, procname="${SVCNAME}" did the trick. But only if init-script name is > > the same as executable name. Otherwise even `start-stop-daemon --name > > ${SVCNAME} -K` not works. > > I had no problem getting your use case to work with openrc-19.1. Using the > example daemon and init script below, I was able to successfully start and > stop three instances of the "mydaemon" service. > > openrc ~ # cat /etc/init.d/mydaemon > #!/sbin/openrc-run > command="/usr/local/bin/mydaemon" > procname="${RC_SVCNAME}" > > openrc ~ # ls -l /etc/init.d/mydaemon* > -rwxr-xr-x 1 root root 78 Jun 23 20:40 /etc/init.d/mydaemon > lrwxrwxrwx 1 root root 8 Jun 23 11:26 /etc/init.d/mydaemon.a -> mydaemon > lrwxrwxrwx 1 root root 8 Jun 23 11:26 /etc/init.d/mydaemon.b -> mydaemon > lrwxrwxrwx 1 root root 8 Jun 23 20:38 /etc/init.d/mydaemon.c -> mydaemon > > openrc ~ # cat mydaemon.c > #include <stdlib.h> > #include <stdio.h> > #include <unistd.h> > > int main(int argc, char **argv) > { > if (daemon(0, 0)) > { > perror(argv[0]); > exit(1); > } > pause(); > return 0; > } Thank you very much for help in debugging! My problem was in pidfile variable which I leaved uncommented while testing my init-script.