Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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