-
Notifications
You must be signed in to change notification settings - Fork 34
/
istatd-agent-init.sh
executable file
·111 lines (98 loc) · 2.34 KB
/
istatd-agent-init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
### BEGIN INIT INFO
# Provides: istatd-agent
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start collecting statistics
# Description: Istatd collects statistics for later graphing and analysis
### END INIT INFO
if [ `whoami` != 'root' ]; then
echo "You must be root!"
exit 1
fi
DESC="IMVU Statistics Agent Daemon"
NAME=istatd-agent
PIDFILE=/var/run/$NAME.pid
HOSTNAME=`hostname -s`
LOCALSTATS="^host.$HOSTNAME"
DAEMON="/usr/bin/istatd-agent"
CONFIG=/etc/istatd-agent.cfg
LOGFILE=/var/log/istatd-agent.log
#source defaults file
[ -f /etc/default/istatd-agent ] && . /etc/default/istatd-agent
# first, cd to a "safe" place
cd /var/tmp
is_istatd_running() {
#in shell land, 0 is true!
if [ -s $PIDFILE ] && ps `cat $PIDFILE` | grep -q $DAEMON > /dev/null ; then
return 0
elif ps -FC $NAME | grep -q $DAEMON > /dev/null ; then
return 0
else
return 1
fi
}
start_istatd() {
if [ "$ENABLE_ISTATD" -eq 1 ]; then
echo -n "Starting $DESC: "
"$DAEMON" \
--daemonize \
--pid-file "$PIDFILE" \
--config "$CONFIG" \
--log-file "$LOGFILE" \
$EXTRA_ARGS
echo -n "$NAME."
echo
else
echo "ISTATD Agent is not enabled. Modify /etc/default/istatd-agent to enable."
fi
}
stop_istatd() {
echo -n "Stopping $DESC: "
I=0
while [ $I -lt 10 ] && is_istatd_running ; do
let I=$I+1
if [ -s $PIDFILE ] && ps `cat $PIDFILE` | grep -q $DAEMON > /dev/null ; then
kill -TERM `cat $PIDFILE`
elif ps -FC $NAME | grep -q $DAEMON > /dev/null ; then
kill -TERM `ps -FC $NAME | grep $DAEMON | awk '{print $2}'`
fi
if ! is_istatd_running ; then
break
fi
sleep 1
done
if is_istatd_running ; then
echo "failed"
else
echo "stopped"
fi
}
status_istatd() {
if is_istatd_running ; then
echo $NAME is running
else
echo $NAME is stopped
fi
}
case "$1" in
start)
start_istatd
;;
stop)
stop_istatd
;;
status)
status_istatd
;;
restart)
stop_istatd
start_istatd
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|restart|status}" >&2
exit 1
;;
esac