From 0f704402a236d385e8b30083ccf9aca327c0a57e Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Thu, 15 Nov 2018 14:15:06 -0600 Subject: [PATCH] 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. --- man/supervise-daemon.8 | 17 +---------------- sh/supervise-daemon.sh | 6 ------ src/rc/supervise-daemon.c | 7 ++----- supervise-daemon-guide.md | 9 --------- 4 files changed, 3 insertions(+), 36 deletions(-) diff --git a/man/supervise-daemon.8 b/man/supervise-daemon.8 index 8bcd8b5c..0da1c5ac 100644 --- a/man/supervise-daemon.8 +++ b/man/supervise-daemon.8 @@ -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. diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh index 5d803d7c..d12c54eb 100644 --- a/sh/supervise-daemon.sh +++ b/sh/supervise-daemon.sh @@ -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}" } diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c index 52525c19..99159ef3 100644 --- a/src/rc/supervise-daemon.c +++ b/src/rc/supervise-daemon.c @@ -766,7 +766,7 @@ int main(int argc, char **argv) break; case 'p': /* --pidfile */ - pidfile = optarg; + ewarn("%s: --pidfile is deprecated and will be removed", applet); break; case 'R': /* --retry |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); diff --git a/supervise-daemon-guide.md b/supervise-daemon-guide.md index 07ab55cf..8fb02f6a 100644 --- a/supervise-daemon-guide.md +++ b/supervise-daemon-guide.md @@ -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" ```