X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=contrib%2Fredhat%2Finit.d-collectd;h=52bf7433c8a4732b0251ad4a3ee65f3821aa807f;hb=8a533ce6a4f030b8b5c505b649e232f1354dc24f;hp=b7c085cd0efe562caf0a3212211d8b3584934d76;hpb=4fb5d4b471e3f6a24d7cd36272e48e57bcb2c68f;p=collectd.git diff --git a/contrib/redhat/init.d-collectd b/contrib/redhat/init.d-collectd index b7c085cd..52bf7433 100644 --- a/contrib/redhat/init.d-collectd +++ b/contrib/redhat/init.d-collectd @@ -1,7 +1,7 @@ #!/bin/bash # # collectd Startup script for the Collectd statistics gathering daemon -# chkconfig: - 86 15 +# chkconfig: - 99 01 # description: Collectd is a statistics gathering daemon used to collect \ # system information ie. cpu, memory, disk, network # processname: collectd @@ -15,30 +15,53 @@ RETVAL=0 ARGS="" prog="collectdmon" +service="collectd" CONFIG=/etc/collectd.conf COLLECTD=/usr/sbin/collectd -COLLECTDMONPID=/var/run/collectdmon.pid +COLLECTDMONPIDIR="/var/run" +COLLECTDMONPID="$COLLECTDMONPIDIR/collectdmon.pid" -if [ -r /etc/default/$prog ]; then - . /etc/default/$prog +if [ -r /etc/sysconfig/$service ]; then + . /etc/sysconfig/$service fi +if [ ! -d $COLLECTDMONPIDIR ]; then + mkdir -p $COLLECTDMONPIDIR + [ -n "${RUNAS-}" ] && chown $RUNAS: $COLLECTDMONPIDIR +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 --user "${RUNAS-root}" $prog -P $COLLECTDMONPID -c $COLLECTD -- -C "$CONFIG" $ARGS RETVAL=$? echo - [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$service fi } stop () { echo -n $"Stopping collectd: " - killproc $prog + killproc -p $COLLECTDMONPID $prog RETVAL=$? echo - [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog + [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$service } # See how we were called. case "$1" in @@ -49,14 +72,22 @@ case "$1" in stop ;; status) - status $prog + status -p $COLLECTDMONPID $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 || : + [ -f /var/lock/subsys/$service ] && restart || : ;; *) echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}"