When the pid file wasn't removed (eg: forced reboot, etc...) the services were printing confusing warnings during restart/condrestart.
Signed-off-by: Federico Simoncelli fsimonce@redhat.com --- init.d/sanlock | 15 ++++++++------- init.d/wdmd | 49 ++++++++++++++++++++++++++++++++++++------------- 2 files changed, 44 insertions(+), 20 deletions(-)
diff --git a/init.d/sanlock b/init.d/sanlock index bd8dccb..83b35e8 100644 --- a/init.d/sanlock +++ b/init.d/sanlock @@ -48,7 +48,9 @@ start() { }
stop() { - echo -n $"Sending stop signal $prog: " + PID=$(pidofproc -p $runfile $prog) + + echo -n $"Sending stop signal $prog ($PID): " killproc -p $runfile $prog -TERM retval=$? echo @@ -57,9 +59,10 @@ stop() { return $retval fi
- echo -n $"Waiting for $prog to stop:" + echo -n $"Waiting for $prog ($PID) to stop:" + timeout=10 - while [ -e $runfile ]; do + while checkpid $PID; do sleep 1 timeout=$((timeout - 1)) if [ "$timeout" -le 0 ]; then @@ -74,9 +77,8 @@ stop() { }
restart() { - stop && start - retval=$? - return $retval + rh_status_q && stop + start }
reload() { @@ -122,4 +124,3 @@ case "$1" in exit 2 esac exit $? - diff --git a/init.d/wdmd b/init.d/wdmd index 19fc3ae..af45561 100644 --- a/init.d/wdmd +++ b/init.d/wdmd @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # wdmd - watchdog multiplexing daemon # @@ -31,20 +31,24 @@ WDMDOPTS="-G $WDMDGROUP"
[ -f /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
-start() { - [ -x $exec ] || exit 5 - - if [ ! -d /var/run/$prog ]; then - mkdir -p /var/run/$prog - [ -x /sbin/restorecon ] && restorecon /var/run/$prog - fi - +watchdog_check() { if [ ! -c /dev/watchdog ]; then echo -n $"Loading the softdog kernel module: " modprobe softdog && udevadm settle [ -c /dev/watchdog ] && success || failure echo fi +} + +start() { + watchdog_check + + [ -x $exec ] || exit 5 + + if [ ! -d /var/run/$prog ]; then + install -d -g $WDMDGROUP -m 775 /var/run/$prog + [ -x /sbin/restorecon ] && restorecon /var/run/$prog + fi
echo -n $"Starting $prog: " daemon $prog $WDMDOPTS @@ -55,16 +59,36 @@ start() { }
stop() { - echo -n $"Stopping $prog: " + PID=$(pidofproc -p $runfile $prog) + + echo -n $"Sending stop signal $prog ($PID): " killproc -p $runfile $prog -TERM retval=$? echo - [ $retval -eq 0 ] && rm -f $lockfile + + if [ $retval -ne 0 ]; then + return $retval + fi + + echo -n $"Waiting for $prog ($PID) to stop:" + + timeout=10 + while checkpid $PID; do + sleep 1 + timeout=$((timeout - 1)) + if [ "$timeout" -le 0 ]; then + failure; echo + return 1 + fi + done + + success; echo + rm -f $lockfile return $retval }
restart() { - stop + rh_status_q && stop start }
@@ -111,4 +135,3 @@ case "$1" in exit 2 esac exit $? -
Signed-off-by: Federico Simoncelli fsimonce@redhat.com --- init.d/sanlock | 11 +++++++++++ init.d/sanlock.upstart | 14 ++++++++++++++ init.d/wdmd | 11 +++++++++++ init.d/wdmd.upstart | 14 ++++++++++++++ sanlock.spec | 1 + src/main.c | 12 +++++++++--- src/sanlock.8 | 3 +++ src/sanlock_internal.h | 3 ++- wdmd/main.c | 9 +++++++-- wdmd/wdmd.8 | 4 ++++ 10 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 init.d/sanlock.upstart create mode 100644 init.d/wdmd.upstart
diff --git a/init.d/sanlock b/init.d/sanlock index 83b35e8..e7d8002 100644 --- a/init.d/sanlock +++ b/init.d/sanlock @@ -28,10 +28,20 @@ exec="/usr/sbin/$prog"
SANLOCKUSER="sanlock" SANLOCKOPTS="-U $SANLOCKUSER -G $SANLOCKUSER" +INITCTL="/sbin/initctl"
[ -f /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+initctl_check() { + if [ -x "$INITCTL" ] && $INITCTL status $prog &> /dev/null; then + logger -t "$prog" \ + -s "$prog is managed by upstart use initctl instead" + exit 14 + fi +} + start() { + initctl_check [ -x $exec ] || exit 5
if [ ! -d /var/run/$prog ]; then @@ -48,6 +58,7 @@ start() { }
stop() { + initctl_check PID=$(pidofproc -p $runfile $prog)
echo -n $"Sending stop signal $prog ($PID): " diff --git a/init.d/sanlock.upstart b/init.d/sanlock.upstart new file mode 100644 index 0000000..f65616e --- /dev/null +++ b/init.d/sanlock.upstart @@ -0,0 +1,14 @@ +# sanlock upstart job +start on stopped rc RUNLEVEL=[345] +stop on runlevel [!345] + +respawn + +script + SANLOCKUSER="sanlock" + SANLOCKOPTS="-U $SANLOCKUSER -G $SANLOCKUSER" + + [ -f /etc/sysconfig/sanlock ] && . /etc/sysconfig/sanlock + + exec /usr/sbin/sanlock daemon -F $SANLOCKOPTS +end script diff --git a/init.d/wdmd b/init.d/wdmd index af45561..60f454d 100644 --- a/init.d/wdmd +++ b/init.d/wdmd @@ -28,9 +28,18 @@ exec="/usr/sbin/$prog"
WDMDGROUP="sanlock" WDMDOPTS="-G $WDMDGROUP" +INITCTL="/sbin/initctl"
[ -f /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+initctl_check() { + if [ -x "$INITCTL" ] && $INITCTL status $prog &> /dev/null; then + logger -t "$prog" \ + -s "$prog is managed by upstart use initctl instead" + exit 14 + fi +} + watchdog_check() { if [ ! -c /dev/watchdog ]; then echo -n $"Loading the softdog kernel module: " @@ -41,6 +50,7 @@ watchdog_check() { }
start() { + initctl_check watchdog_check
[ -x $exec ] || exit 5 @@ -59,6 +69,7 @@ start() { }
stop() { + initctl_check PID=$(pidofproc -p $runfile $prog)
echo -n $"Sending stop signal $prog ($PID): " diff --git a/init.d/wdmd.upstart b/init.d/wdmd.upstart new file mode 100644 index 0000000..502d1b8 --- /dev/null +++ b/init.d/wdmd.upstart @@ -0,0 +1,14 @@ +# wdmd upstart job +start on stopped rc RUNLEVEL=[345] +stop on runlevel [!345] + +respawn + +script + WDMDUSER="sanlock" + WDMDOPTS="-G $WDMDUSER" + + [ -f /etc/sysconfig/wdmd ] && . /etc/sysconfig/wdmd + + exec /usr/sbin/wdmd -F $WDMDOPTS +end script diff --git a/sanlock.spec b/sanlock.spec index 05c9c95..5217b74 100644 --- a/sanlock.spec +++ b/sanlock.spec @@ -108,6 +108,7 @@ fi
%files %defattr(-,root,root,-) +%doc init.d/sanlock.upstart init.d/wdmd.upstart %if 0%{?fedora} >= 16 /lib/systemd/systemd-sanlock /lib/systemd/systemd-wdmd diff --git a/src/main.c b/src/main.c index 247b3f4..4cac8d9 100644 --- a/src/main.c +++ b/src/main.c @@ -1523,7 +1523,7 @@ static int do_daemon(void)
/* TODO: copy comprehensive daemonization method from libvirtd */
- if (!com.debug) { + if (!com.debug && !com.foreground) { if (daemon(0, 0) < 0) { log_tool("cannot fork daemon\n"); exit(EXIT_FAILURE); @@ -1698,6 +1698,7 @@ static void print_usage(void) printf("\n"); printf("sanlock daemon [options]\n"); printf(" -D no fork and print all logging to stderr\n"); + printf(" -F foreground (no fork)\n"); printf(" -Q 0|1 quiet error messages for common lock contention (0)\n"); printf(" -R 0|1 renewal debugging, log debug info about renewals (0)\n"); printf(" -L <pri> write logging at priority level and up to logfile (3 LOG_ERR))\n"); @@ -1898,13 +1899,18 @@ static int read_command_line(int argc, char *argv[]) optchar = p[1]; i++;
- /* the only option that does not have optionarg */ + /* options that does not have optionarg */ if (optchar == 'D') { - com.debug = 1; + com.foreground = 1; log_stderr_priority = LOG_DEBUG; continue; }
+ if (optchar == 'F') { + com.foreground = 1; + continue; + } + if (i >= argc) { log_tool("option '%c' requires arg", optchar); exit(EXIT_FAILURE); diff --git a/src/sanlock.8 b/src/sanlock.8 index e716264..55c26d5 100644 --- a/src/sanlock.8 +++ b/src/sanlock.8 @@ -206,6 +206,9 @@ COMMAND can be one of three primary top level choices .BR -D " " no fork and print all logging to stderr
+.BR -F " " +foreground (no fork) + .BR -Q " 0|1" quiet error messages for common lock contention
diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h index a69b367..366e961 100644 --- a/src/sanlock_internal.h +++ b/src/sanlock_internal.h @@ -250,7 +250,8 @@ EXTERN struct client *client; struct command_line { int type; /* COM_ */ int action; /* ACT_ */ - int debug; + int debug; /* -D */ + int foreground; /* -F */ int debug_renew; int quiet_fail; int use_watchdog; diff --git a/wdmd/main.c b/wdmd/main.c index 17687be..2ded9f9 100644 --- a/wdmd/main.c +++ b/wdmd/main.c @@ -55,6 +55,7 @@ static int fire_timeout = DEFAULT_FIRE_TIMEOUT; static int high_priority = DEFAULT_HIGH_PRIORITY; static int daemon_quit; static int daemon_debug; +static int daemon_foreground; static int socket_gid; static time_t last_keepalive; static char lockfile_path[PATH_MAX]; @@ -943,6 +944,7 @@ static void print_usage_and_exit(int status) printf("--version, -V print version\n"); printf("--help, -h print usage\n"); printf("-D debug: no fork and print all logging to stderr\n"); + printf("-F foreground (no fork)\n"); printf("-H <num> use high priority features (1 yes, 0 no, default %d)\n", DEFAULT_HIGH_PRIORITY); printf("-G <groupname> group ownership for the socket\n"); @@ -987,7 +989,7 @@ int main(int argc, char *argv[]) {0, 0, 0, 0 } };
- c = getopt_long(argc, argv, "hVDH:G:", + c = getopt_long(argc, argv, "hVDFH:G:", long_options, &option_index); if (c == -1) break; @@ -1002,6 +1004,9 @@ int main(int argc, char *argv[]) case 'D': daemon_debug = 1; break; + case 'F': + daemon_foreground = 1; + break; case 'G': socket_gid = group_to_gid(optarg); break; @@ -1011,7 +1016,7 @@ int main(int argc, char *argv[]) } }
- if (!daemon_debug) { + if (!daemon_debug && !daemon_foreground) { if (daemon(0, 0) < 0) { fprintf(stderr, "cannot fork daemon\n"); exit(EXIT_FAILURE); diff --git a/wdmd/wdmd.8 b/wdmd/wdmd.8 index 2df7297..5d913b3 100644 --- a/wdmd/wdmd.8 +++ b/wdmd/wdmd.8 @@ -66,6 +66,10 @@ added in the future.) Enable debugging to stderr and don't fork.
.TP +.B -F +Keep wdmd in foreground. + +.TP .BI -H " num" Enable (1) or disable (0) high priority features such as realtime scheduling priority and mlockall.
sanlock-devel@lists.fedorahosted.org