From af70862a7a115d6269affca663423e9340d6e929 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sun, 2 Dec 2018 15:15:51 -0600 Subject: supervise-daemon: use a default pid file if one is not specified Since the pid file is internal to us, start moving toward deprecating it by not requiring the user to specify it. In the next release, I plan on working on code to start phasing out the use of a pid file if this is possible. --- sh/supervise-daemon.sh | 6 ++++++ src/rc/supervise-daemon.c | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh index d12c54eb..69d74593 100644 --- a/sh/supervise-daemon.sh +++ b/sh/supervise-daemon.sh @@ -30,6 +30,7 @@ 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 \ @@ -43,6 +44,7 @@ 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}" } @@ -50,9 +52,13 @@ supervise_start() supervise_stop() { local startchroot="$(service_get_value "chroot")" + local startpidfile="$(service_get_value "pidfile")" chroot="${startchroot:-$chroot}" + pidfile="${startpidfile:-$pidfile}" ebegin "Stopping ${name:-$RC_SVCNAME}" supervise-daemon "${RC_SVCNAME}" --stop \ + ${pidfile:+--pidfile} $chroot$pidfile \ + ${stopsig:+--signal} $stopsig eend $? "Failed to stop ${name:-$RC_SVCNAME}" } diff --git a/src/rc/supervise-daemon.c b/src/rc/supervise-daemon.c index c2082100..e7c578b8 100644 --- a/src/rc/supervise-daemon.c +++ b/src/rc/supervise-daemon.c @@ -779,7 +779,7 @@ int main(int argc, char **argv) break; case 'p': /* --pidfile */ - ewarn("%s: --pidfile is deprecated and will be removed", applet); + pidfile = optarg; break; case 'R': /* --retry |timeout */ @@ -855,7 +855,8 @@ int main(int argc, char **argv) ch_root = expand_home(home, ch_root); umask(numask); - xasprintf(&pidfile, "/var/run/supervise-%s.pid", svcname); + if (!pidfile) + xasprintf(&pidfile, "/var/run/supervise-%s.pid", svcname); xasprintf(&fifopath, "%s/supervise-%s.ctl", RC_SVCDIR, svcname); if (mkfifo(fifopath, 0600) == -1 && errno != EEXIST) eerrorx("%s: unable to create control fifo: %s", @@ -878,6 +879,7 @@ 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); @@ -959,6 +961,7 @@ 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); -- cgit v1.2.3