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 .Ar count
.Fl N , -nicelevel .Fl N , -nicelevel
.Ar level .Ar level
.Fl p , -pidfile
.Ar pidfile
.Fl P , -respawn-period .Fl P , -respawn-period
.Ar seconds .Ar seconds
.Fl R , -retry .Fl R , -retry
@ -57,8 +55,6 @@
.Nm .Nm
.Fl K , -stop .Fl K , -stop
.Ar daemon .Ar daemon
.Fl p , -pidfile
.Ar pidfile
.Fl r , -chroot .Fl r , -chroot
.Ar chrootpath .Ar chrootpath
.Sh DESCRIPTION .Sh DESCRIPTION
@ -76,12 +72,6 @@ should not be the one the daemon writes.
.Pp .Pp
Here are the options to specify the daemon and how it should start or stop: Here are the options to specify the daemon and how it should start or stop:
.Bl -tag -width indent .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 .It Fl u , -user Ar user Ns Op : Ns Ar group
Start the daemon as the Start the daemon as the
.Ar user .Ar user
@ -132,7 +122,7 @@ signal/timeout pairs (like SIGTERM/5).
If this option is not given, the default is SIGTERM/5. If this option is not given, the default is SIGTERM/5.
.It Fl r , -chroot Ar path .It Fl r , -chroot Ar path
chroot to this directory before starting the daemon. All other paths, such 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 .It Fl u , -user Ar user
Start the daemon as the specified user. Start the daemon as the specified user.
.It Fl 1 , -stdout Ar logfile .It Fl 1 , -stdout Ar logfile
@ -145,7 +135,6 @@ The same thing as
.Fl 1 , -stdout .Fl 1 , -stdout
but with the standard error output. but with the standard error output.
.El .El
.El
.Sh ENVIRONMENT .Sh ENVIRONMENT
.Va SSD_NICELEVEL .Va SSD_NICELEVEL
can also set the scheduling priority of the daemon, but the command line can also set the scheduling priority of the daemon, but the command line
@ -172,10 +161,6 @@ seconds.
.Xr chroot 2 , .Xr chroot 2 ,
.Xr getopt 3 , .Xr getopt 3 ,
.Xr nice 2 , .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 .Sh HISTORY
.Nm .Nm
first appeared in Debian. first appeared in Debian.

View File

@ -30,7 +30,6 @@ supervise_start()
${chroot:+--chroot} $chroot \ ${chroot:+--chroot} $chroot \
${output_log+--stdout} ${output_log} \ ${output_log+--stdout} ${output_log} \
${error_log+--stderr} $error_log \ ${error_log+--stderr} $error_log \
${pidfile:+--pidfile} $pidfile \
${respawn_delay:+--respawn-delay} $respawn_delay \ ${respawn_delay:+--respawn-delay} $respawn_delay \
${respawn_max:+--respawn-max} $respawn_max \ ${respawn_max:+--respawn-max} $respawn_max \
${respawn_period:+--respawn-period} $respawn_period \ ${respawn_period:+--respawn-period} $respawn_period \
@ -44,7 +43,6 @@ supervise_start()
rc=$? rc=$?
if [ $rc = 0 ]; then if [ $rc = 0 ]; then
[ -n "${chroot}" ] && service_set_value "chroot" "${chroot}" [ -n "${chroot}" ] && service_set_value "chroot" "${chroot}"
[ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}"
fi fi
eend $rc "failed to start ${name:-$RC_SVCNAME}" eend $rc "failed to start ${name:-$RC_SVCNAME}"
} }
@ -52,13 +50,9 @@ supervise_start()
supervise_stop() supervise_stop()
{ {
local startchroot="$(service_get_value "chroot")" local startchroot="$(service_get_value "chroot")"
local startpidfile="$(service_get_value "pidfile")"
chroot="${startchroot:-$chroot}" chroot="${startchroot:-$chroot}"
pidfile="${startpidfile:-$pidfile}"
[ -n "$pidfile" ] || return 0
ebegin "Stopping ${name:-$RC_SVCNAME}" ebegin "Stopping ${name:-$RC_SVCNAME}"
supervise-daemon "${RC_SVCNAME}" --stop \ supervise-daemon "${RC_SVCNAME}" --stop \
${pidfile:+--pidfile} $chroot$pidfile \
eend $? "Failed to stop ${name:-$RC_SVCNAME}" eend $? "Failed to stop ${name:-$RC_SVCNAME}"
} }

View File

@ -766,7 +766,7 @@ int main(int argc, char **argv)
break; break;
case 'p': /* --pidfile <pid-file> */ case 'p': /* --pidfile <pid-file> */
pidfile = optarg; ewarn("%s: --pidfile is deprecated and will be removed", applet);
break; break;
case 'R': /* --retry <schedule>|timeout */ case 'R': /* --retry <schedule>|timeout */
@ -830,8 +830,6 @@ int main(int argc, char **argv)
case_RC_COMMON_GETOPT case_RC_COMMON_GETOPT
} }
if (!pidfile && !reexec)
eerrorx("%s: --pidfile must be specified", applet);
endpwent(); endpwent();
argc -= optind; argc -= optind;
argv += optind; argv += optind;
@ -844,6 +842,7 @@ int main(int argc, char **argv)
ch_root = expand_home(home, ch_root); ch_root = expand_home(home, ch_root);
umask(numask); umask(numask);
xasprintf(&pidfile, "/var/run/supervise-%s.pid", svcname);
if (reexec) { if (reexec) {
str = rc_service_value_get(svcname, "argc"); str = rc_service_value_get(svcname, "argc");
@ -862,7 +861,6 @@ int main(int argc, char **argv)
sscanf(str, "%d", &child_pid); sscanf(str, "%d", &child_pid);
free(str); free(str);
exec = rc_service_value_get(svcname, "exec"); exec = rc_service_value_get(svcname, "exec");
pidfile = rc_service_value_get(svcname, "pidfile");
retry = rc_service_value_get(svcname, "retry"); retry = rc_service_value_get(svcname, "retry");
if (retry) { if (retry) {
parse_schedule(applet, retry, sig); parse_schedule(applet, retry, sig);
@ -944,7 +942,6 @@ int main(int argc, char **argv)
eerrorx("%s: fopen `%s': %s", applet, pidfile, strerror(errno)); eerrorx("%s: fopen `%s': %s", applet, pidfile, strerror(errno));
fclose(fp); fclose(fp);
rc_service_value_set(svcname, "pidfile", pidfile);
varbuf = NULL; varbuf = NULL;
xasprintf(&varbuf, "%i", respawn_delay); xasprintf(&varbuf, "%i", respawn_delay);
rc_service_value_set(svcname, "respawn_delay", varbuf); 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 supervise-daemon. They are documented on the openrc-run man page, but I
will list them here for convenience: 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 ``` sh
command_args_foreground="arguments" command_args_foreground="arguments"
``` ```