Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 586794 - start_stop_daemon_args="--name ${SVCNAME}" not works
Summary: start_stop_daemon_args="--name ${SVCNAME}" not works
Status: RESOLVED INVALID
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: OpenRC (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: OpenRC Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-06-23 11:42 UTC by Dmitri Bogomolov
Modified: 2016-06-24 07:41 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
document the procname variable (man-procname.patch,833 bytes, patch)
2016-06-23 12:47 UTC, Mike Gilbert
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitri Bogomolov 2016-06-23 11:42:52 UTC
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
Comment 1 Mike Gilbert gentoo-dev 2016-06-23 12:34:00 UTC
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
...
}
Comment 2 Mike Gilbert gentoo-dev 2016-06-23 12:47:55 UTC
Created attachment 438528 [details, diff]
document the procname variable

I see this variable is undocumented. Here's a patch to fix that.
Comment 3 Dmitri Bogomolov 2016-06-23 14:06:36 UTC
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.
Comment 4 Mike Gilbert gentoo-dev 2016-06-23 14:25:49 UTC
(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.
Comment 5 Dmitri Bogomolov 2016-06-23 14:30:33 UTC
(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.
Comment 6 Mike Gilbert gentoo-dev 2016-06-23 14:37:10 UTC
(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.
Comment 7 Mike Gilbert gentoo-dev 2016-06-23 14:45:37 UTC
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.
Comment 8 Dmitri Bogomolov 2016-06-23 14:59:07 UTC
(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.
Comment 9 William Hubbs gentoo-dev 2016-06-23 22:49:32 UTC
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.
Comment 10 Mike Gilbert gentoo-dev 2016-06-24 00:43:28 UTC
(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;
}
Comment 11 Dmitri Bogomolov 2016-06-24 07:41:02 UTC
(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.