Skip to content

Commit

Permalink
supervise-daemon: make the pidfile an implementation detail
Browse files Browse the repository at this point in the history
The pidfile of the supervisor doesn't need to be adjustable by the
service script. It is only used so the supervisor can stop itself when
the --stop option is used.
  • Loading branch information
williamh committed Nov 15, 2018
1 parent 2504a2c commit 0f70440
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 36 deletions.
17 changes: 1 addition & 16 deletions man/supervise-daemon.8
Expand Up @@ -36,8 +36,6 @@
.Ar count
.Fl N , -nicelevel
.Ar level
.Fl p , -pidfile
.Ar pidfile
.Fl P , -respawn-period
.Ar seconds
.Fl R , -retry
Expand All @@ -57,8 +55,6 @@
.Nm
.Fl K , -stop
.Ar daemon
.Fl p , -pidfile
.Ar pidfile
.Fl r , -chroot
.Ar chrootpath
.Sh DESCRIPTION
Expand All @@ -76,12 +72,6 @@ should not be the one the daemon writes.
.Pp
Here are the options to specify the daemon and how it should start or stop:
.Bl -tag -width indent
.It Fl p , -pidfile Ar pidfile
When starting, we write a
.Ar pidfile
so we know which supervisor to stop. When stopping we only stop the pid(s)
listed in the
.Ar pidfile .
.It Fl u , -user Ar user Ns Op : Ns Ar group
Start the daemon as the
.Ar user
Expand Down Expand Up @@ -132,7 +122,7 @@ signal/timeout pairs (like SIGTERM/5).
If this option is not given, the default is SIGTERM/5.
.It Fl r , -chroot Ar path
chroot to this directory before starting the daemon. All other paths, such
as the path to the daemon, chdir and pidfile, should be relative to the chroot.
as the path to the daemon and chdir should be relative to the chroot.
.It Fl u , -user Ar user
Start the daemon as the specified user.
.It Fl 1 , -stdout Ar logfile
Expand All @@ -145,7 +135,6 @@ The same thing as
.Fl 1 , -stdout
but with the standard error output.
.El
.El
.Sh ENVIRONMENT
.Va SSD_NICELEVEL
can also set the scheduling priority of the daemon, but the command line
Expand All @@ -172,10 +161,6 @@ seconds.
.Xr chroot 2 ,
.Xr getopt 3 ,
.Xr nice 2 ,
.Xr rc_find_pids 3
.Sh BUGS
.Nm
cannot stop an interpreted daemon that no longer exists without a pidfile.
.Sh HISTORY
.Nm
first appeared in Debian.
Expand Down
6 changes: 0 additions & 6 deletions sh/supervise-daemon.sh
Expand Up @@ -30,7 +30,6 @@ supervise_start()
${chroot:+--chroot} $chroot \
${output_log+--stdout} ${output_log} \
${error_log+--stderr} $error_log \
${pidfile:+--pidfile} $pidfile \
${respawn_delay:+--respawn-delay} $respawn_delay \
${respawn_max:+--respawn-max} $respawn_max \
${respawn_period:+--respawn-period} $respawn_period \
Expand All @@ -44,21 +43,16 @@ supervise_start()
rc=$?
if [ $rc = 0 ]; then
[ -n "${chroot}" ] && service_set_value "chroot" "${chroot}"
[ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}"
fi
eend $rc "failed to start ${name:-$RC_SVCNAME}"
}

supervise_stop()
{
local startchroot="$(service_get_value "chroot")"
local startpidfile="$(service_get_value "pidfile")"
chroot="${startchroot:-$chroot}"
pidfile="${startpidfile:-$pidfile}"
[ -n "$pidfile" ] || return 0
ebegin "Stopping ${name:-$RC_SVCNAME}"
supervise-daemon "${RC_SVCNAME}" --stop \
${pidfile:+--pidfile} $chroot$pidfile \

eend $? "Failed to stop ${name:-$RC_SVCNAME}"
}
Expand Down
7 changes: 2 additions & 5 deletions src/rc/supervise-daemon.c
Expand Up @@ -766,7 +766,7 @@ int main(int argc, char **argv)
break;

case 'p': /* --pidfile <pid-file> */
pidfile = optarg;
ewarn("%s: --pidfile is deprecated and will be removed", applet);
break;

case 'R': /* --retry <schedule>|timeout */
Expand Down Expand Up @@ -830,8 +830,6 @@ int main(int argc, char **argv)
case_RC_COMMON_GETOPT
}

if (!pidfile && !reexec)
eerrorx("%s: --pidfile must be specified", applet);
endpwent();
argc -= optind;
argv += optind;
Expand All @@ -844,6 +842,7 @@ int main(int argc, char **argv)
ch_root = expand_home(home, ch_root);

umask(numask);
xasprintf(&pidfile, "/var/run/supervise-%s.pid", svcname);

if (reexec) {
str = rc_service_value_get(svcname, "argc");
Expand All @@ -862,7 +861,6 @@ int main(int argc, char **argv)
sscanf(str, "%d", &child_pid);
free(str);
exec = rc_service_value_get(svcname, "exec");
pidfile = rc_service_value_get(svcname, "pidfile");
retry = rc_service_value_get(svcname, "retry");
if (retry) {
parse_schedule(applet, retry, sig);
Expand Down Expand Up @@ -944,7 +942,6 @@ int main(int argc, char **argv)
eerrorx("%s: fopen `%s': %s", applet, pidfile, strerror(errno));
fclose(fp);

rc_service_value_set(svcname, "pidfile", pidfile);
varbuf = NULL;
xasprintf(&varbuf, "%i", respawn_delay);
rc_service_value_set(svcname, "respawn_delay", varbuf);
Expand Down
9 changes: 0 additions & 9 deletions supervise-daemon-guide.md
Expand Up @@ -57,15 +57,6 @@ Several other variables affect the way services behave under
supervise-daemon. They are documented on the openrc-run man page, but I
will list them here for convenience:

``` sh
pidfile=/pid/of/supervisor.pid
```

If you are using start-stop-daemon to monitor your scripts, the pidfile
is the path to the pidfile the daemon creates. If, on the other hand,
you are using supervise-daemon, this is the path to the pidfile the
supervisor creates.

``` sh
command_args_foreground="arguments"
```
Expand Down

0 comments on commit 0f70440

Please sign in to comment.