From: Marc Fournier Date: Fri, 16 Nov 2012 15:03:41 +0000 (+0100) Subject: RedHat initscript: small improvements X-Git-Tag: collectd-5.2.2~10^2~11 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=289f06be0b36ec0da43d7ab2567251c55538ac76;p=collectd.git RedHat initscript: small improvements * checks configuration before (re)starting, based on debian's initscript * use /etc/sysconfig instdead of /etc/default * include optional $ARGS in arguments passed to collectd. --- diff --git a/contrib/redhat/init.d-collectd b/contrib/redhat/init.d-collectd index a60acb39..ec55a52a 100644 --- a/contrib/redhat/init.d-collectd +++ b/contrib/redhat/init.d-collectd @@ -20,15 +20,31 @@ CONFIG=/etc/collectd.conf COLLECTD=/usr/sbin/collectd COLLECTDMONPID=/var/run/collectdmon.pid -if [ -r /etc/default/$prog ]; then - . /etc/default/$prog +if [ -r /etc/sysconfig/$service ]; then + . /etc/sysconfig/$service fi +check_config() { + if test ! -r "$CONFIG"; then + return 2 + fi + if ! $COLLECTD -t -C "$CONFIG"; then + return 1 + fi + return 0 +} + + start () { echo -n $"Starting collectd: " - if [ -r "$CONFIG" ] - then - daemon $prog -P $COLLECTDMONPID -c $COLLECTD -- -C "$CONFIG" + check_config + rc="$?" + if test "$rc" -ne 0; then + RETVAL=6 + echo $"not starting due to configuration error" + failure $"not starting $service due to configuration error" + else + daemon $prog -P $COLLECTDMONPID -c $COLLECTD -- -C "$CONFIG" $ARGS RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$service @@ -53,8 +69,16 @@ case "$1" in status $prog ;; restart|reload) - stop - start + check_config + rc="$?" + if test "$rc" -ne 0; then + RETVAL=6 + echo $"not restarting due to configuration error" + failure $"not restarting $service due to configuration error" + else + stop + start + fi ;; condrestart) [ -f /var/lock/subsys/$prog ] && restart || :