From df081af0d6b9146defc9c55594dd76ba1134ebca Mon Sep 17 00:00:00 2001 From: Seth Chisamore Date: Tue, 26 Jul 2011 22:01:20 -0400 Subject: [PATCH] [CHEF-2491] init scripts should implement reload --- .../default/debian/init.d/chef-client.erb | 86 +++++++++++-------- .../default/redhat/init.d/chef-client.erb | 12 ++- 2 files changed, 56 insertions(+), 42 deletions(-) diff --git a/chef-client/templates/default/debian/init.d/chef-client.erb b/chef-client/templates/default/debian/init.d/chef-client.erb index e45c9579c..4c2e1d231 100644 --- a/chef-client/templates/default/debian/init.d/chef-client.erb +++ b/chef-client/templates/default/debian/init.d/chef-client.erb @@ -32,55 +32,61 @@ fi DAEMON_OPTS="-d -P $PIDFILE -L $LOGFILE -c $CONFIG -i $INTERVAL -s $SPLAY" -running_pid() { +running_pid() { pid=$1 - name=$2 - [ -z "$pid" ] && return 1 - [ ! -d /proc/$pid ] && return 1 + name=$2 + [ -z "$pid" ] && return 1 + [ ! -d /proc/$pid ] && return 1 cmd=`awk '/Name:/ {print $2}' /proc/$pid/status` - [ "$cmd" != "$name" ] && return 1 - return 0 -} + [ "$cmd" != "$name" ] && return 1 + return 0 +} -running() { +running() { [ ! -f "$PIDFILE" ] && return 1 pid=`cat $PIDFILE` - running_pid $pid $NAME || return 1 + running_pid $pid $NAME || return 1 return 0 -} +} -start_server() { - if [ -z "$DAEMONUSER" ] ; then - start_daemon -p $PIDFILE $DAEMON $DAEMON_OPTS +start_server() { + if [ -z "$DAEMONUSER" ] ; then + start_daemon -p $PIDFILE $DAEMON $DAEMON_OPTS errcode=$? else - start-stop-daemon --start --quiet --pidfile $PIDFILE \ - --chuid $DAEMONUSER \ - --exec $DAEMON -- $DAEMON_OPTS - errcode=$? - fi - return $errcode -} + start-stop-daemon --start --quiet --pidfile $PIDFILE \ + --chuid $DAEMONUSER \ + --exec $DAEMON -- $DAEMON_OPTS + errcode=$? + fi + return $errcode +} -stop_server() { - if [ -z "$DAEMONUSER" ] ; then - killproc -p $PIDFILE $DAEMON +stop_server() { + if [ -z "$DAEMONUSER" ] ; then + killproc -p $PIDFILE $DAEMON errcode=$? else - start-stop-daemon --stop --quiet --pidfile $PIDFILE \ - --user $DAEMONUSER \ + start-stop-daemon --stop --quiet --pidfile $PIDFILE \ + --user $DAEMONUSER \ --exec $DAEMON - errcode=$? - fi - return $errcode -} + errcode=$? + fi + return $errcode +} -reload_server() { - [ ! -f "$PIDFILE" ] && return 1 - pid=pidofproc $PIDFILE # This is the daemon's pid - /bin/kill -1 $pid - return $? -} +reload_server() { + if [ -z "$DAEMONUSER" ] ; then + killproc -p $PIDFILE $DAEMON -HUP + errcode=$? + else + start-stop-daemon --stop --signal HUP --quiet --pidfile $PIDFILE \ + --user $DAEMONUSER \ + --exec $DAEMON + errcode=$? + fi + return $errcode +} force_stop() { [ ! -e "$PIDFILE" ] && return @@ -108,7 +114,7 @@ case "$1" in exit 0 fi if start_server ; then - [ -n "$STARTTIME" ] && sleep $STARTTIME # Wait some time + [ -n "$STARTTIME" ] && sleep $STARTTIME # Wait some time if running ; then log_end_msg 0 else @@ -161,8 +167,12 @@ case "$1" in fi ;; reload) - log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon" - log_warning_msg "cannot re-read the config file (use restart)." + if running; then + log_daemon_msg "Reloading $DESC" "$NAME" + errcode=0 + reload_server || errcode=$? + log_end_msg $errcode + fi ;; *) N=/etc/init.d/$NAME diff --git a/chef-client/templates/default/redhat/init.d/chef-client.erb b/chef-client/templates/default/redhat/init.d/chef-client.erb index 9a0d481ea..a9ddf765b 100644 --- a/chef-client/templates/default/redhat/init.d/chef-client.erb +++ b/chef-client/templates/default/redhat/init.d/chef-client.erb @@ -1,5 +1,5 @@ #!/bin/bash -# +# # chef-client Startup script for the Chef client # # chkconfig: - 98 02 @@ -35,7 +35,7 @@ start() { [ -x $exec ] || exit 5 [ -f $config ] || exit 6 echo -n $"Starting $prog: " - daemon $exec -d -c "$config" -L "$logfile" -P "$pidfile" -i "$interval" -s "$splay" "$options" + daemon chef-client -d -c "$config" -L "$logfile" -P "$pidfile" -i "$interval" -s "$splay" "$options" retval=$? echo [ $retval -eq 0 ] && touch $lockfile @@ -44,7 +44,7 @@ start() { stop() { echo -n $"Stopping $prog: " - killproc -p $pidfile $exec + killproc -p $pidfile chef-client retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile @@ -57,7 +57,11 @@ restart () { } reload() { - restart + echo -n $"Reloading $prog: " + killproc -p $pidfile chef-client -HUP + retval=$? + echo + return $retval } force_reload() {