supervise-daemon: make the pidfile an implementation detail

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.
This commit is contained in:
William Hubbs 2018-11-15 14:15:06 -06:00
parent 2504a2c25b
commit 0f704402a2
4 changed files with 3 additions and 36 deletions

View File

@ -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
@ -57,8 +55,6 @@
.Nm
.Fl K , -stop
.Ar daemon
.Fl p , -pidfile
.Ar pidfile
.Fl r , -chroot
.Ar chrootpath
.Sh DESCRIPTION
@ -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
@ -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
@ -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
@ -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.

View File

@ -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 \
@ -44,7 +43,6 @@ 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}"
}
@ -52,13 +50,9 @@ supervise_start()
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}"
}

View File

@ -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 */
@ -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;
@ -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");
@ -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);
@ -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);

View File

@ -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"
```