Skip to content

Commit

Permalink
[CHEF-2491] init scripts should implement reload
Browse files Browse the repository at this point in the history
  • Loading branch information
schisamo committed Jul 27, 2011
1 parent 71089cc commit 5aacab1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 42 deletions.
86 changes: 48 additions & 38 deletions templates/default/debian/init.d/chef-client.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions templates/default/redhat/init.d/chef-client.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
#
#
# chef-client Startup script for the Chef client
#
# chkconfig: - 98 02
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -57,7 +57,11 @@ restart () {
}

reload() {
restart
echo -n $"Reloading $prog: "
killproc -p $pidfile chef-client -HUP
retval=$?
echo
return $retval
}

force_reload() {
Expand Down

0 comments on commit 5aacab1

Please sign in to comment.