| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# collectd Startup script for the Collectd statistics gathering daemon |
| 4 |
# chkconfig: - 99 01 |
| 5 |
# description: Collectd is a statistics gathering daemon used to collect \ |
| 6 |
# system information ie. cpu, memory, disk, network |
| 7 |
# processname: collectd |
| 8 |
# config: /etc/collectd.conf |
| 9 |
# config: /etc/sysconfig/collectd |
| 10 |
# pidfile: /var/run/collectd.pid |
| 11 |
|
| 12 |
# Source function library. |
| 13 |
. /etc/init.d/functions |
| 14 |
|
| 15 |
RETVAL=0 |
| 16 |
ARGS="" |
| 17 |
prog="collectdmon" |
| 18 |
service="collectd" |
| 19 |
CONFIG=/etc/collectd.conf |
| 20 |
COLLECTD=/usr/sbin/collectd |
| 21 |
COLLECTDMONPIDDIR="/var/run" |
| 22 |
COLLECTDMONPID="$COLLECTDMONPIDDIR/collectdmon.pid" |
| 23 |
|
| 24 |
MAXWAIT=30 |
| 25 |
|
| 26 |
if [ -r /etc/sysconfig/$service ]; then |
| 27 |
. /etc/sysconfig/$service |
| 28 |
fi |
| 29 |
|
| 30 |
if [[ ! -d $COLLECTDMONPIDDIR ]]; then |
| 31 |
mkdir -p $COLLECTDMONPIDDIR |
| 32 |
[ -n "${RUNAS}" ] && chown "${RUNAS}:" "$COLLECTDMONPIDDIR" |
| 33 |
fi |
| 34 |
|
| 35 |
check_config() { |
| 36 |
if test ! -r "$CONFIG"; then |
| 37 |
return 2 |
| 38 |
fi |
| 39 |
if ! $COLLECTD -t -C "$CONFIG"; then |
| 40 |
return 1 |
| 41 |
fi |
| 42 |
return 0 |
| 43 |
} |
| 44 |
|
| 45 |
start () { |
| 46 |
echo -n $"Starting collectd: " |
| 47 |
check_config |
| 48 |
rc="$?" |
| 49 |
if test "$rc" -ne 0; then |
| 50 |
RETVAL=6 |
| 51 |
echo $"not starting due to configuration error" |
| 52 |
failure $"not starting $service due to configuration error" |
| 53 |
else |
| 54 |
daemon --user "${RUNAS:-root}" $prog -P $COLLECTDMONPID -c $COLLECTD -- -C "$CONFIG" $ARGS |
| 55 |
RETVAL=$? |
| 56 |
echo |
| 57 |
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$service |
| 58 |
fi |
| 59 |
} |
| 60 |
|
| 61 |
stop () { |
| 62 |
echo -n $"Stopping collectd: " |
| 63 |
killproc -p $COLLECTDMONPID -d $MAXWAIT $prog |
| 64 |
RETVAL=$? |
| 65 |
echo |
| 66 |
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$service |
| 67 |
} |
| 68 |
|
| 69 |
restart () { |
| 70 |
check_config |
| 71 |
rc="$?" |
| 72 |
if test "$rc" -ne 0; then |
| 73 |
RETVAL=6 |
| 74 |
echo $"not restarting due to configuration error" |
| 75 |
failure $"not restarting $service due to configuration error" |
| 76 |
else |
| 77 |
stop |
| 78 |
start |
| 79 |
fi |
| 80 |
} |
| 81 |
|
| 82 |
# See how we were called. |
| 83 |
case "$1" in |
| 84 |
start) |
| 85 |
start |
| 86 |
;; |
| 87 |
stop) |
| 88 |
stop |
| 89 |
;; |
| 90 |
status) |
| 91 |
status -p $COLLECTDMONPID $prog |
| 92 |
;; |
| 93 |
restart|reload) |
| 94 |
restart |
| 95 |
;; |
| 96 |
condrestart) |
| 97 |
[ -f /var/lock/subsys/$service ] && restart || : |
| 98 |
;; |
| 99 |
*) |
| 100 |
echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}" |
| 101 |
exit 1 |
| 102 |
esac |
| 103 |
|
| 104 |
exit $? |
| 105 |
|
| 106 |
# vim:syntax=sh |