Merge pull request #3339 from jkohen/patch-1
[collectd.git] / contrib / aix / init.d-collectd
1 #!/bin/sh
2 #
3 # description: collectd startup script
4 #
5 # March 2010, Aurelien Reynaud <collectd@wattapower.net>
6 #
7
8 # Some plugins need libs in non-standard paths
9 case `uname` in
10         SunOS)
11                 LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/ssl/lib"
12                 export LD_LIBRARY_PATH
13                 ;;
14         *)
15                 ;;
16 esac
17
18 # Set umask
19 umask 022
20
21 COLLECTD_BIN=/opt/freeware/sbin/collectd
22 PIDFILE=/opt/freeware/var/run/collectd.pid
23
24 # Check for missing binaries (stale symlinks should not happen)
25 if [ ! -x $COLLECTD_BIN ]; then
26         echo "$COLLECTD_BIN not installed"
27         [ "$1" = "stop" ] && exit 0
28         exit 5
29 fi
30
31 # Check for existence of needed config file and read it
32 COLLECTD_CONFIG=/opt/freeware/etc/collectd.conf
33 if [ ! -r $COLLECTD_CONFIG ]; then
34         echo "$COLLECTD_CONFIG not existing"
35         [ "$1" = "stop" ] && exit 0
36         exit 6
37 fi
38
39 case "$1" in
40     start)
41         if [ -r $PIDFILE ]; then
42             echo "collectd daemon is already running with PID `cat $PIDFILE`."
43             exit 1
44         fi
45         echo "Starting collectd..."
46
47         ## Start daemon
48         $COLLECTD_BIN
49         ;;
50     stop)
51         echo "Shutting down collectd daemon... "
52         ## Stop daemon.
53         if [ -r $PIDFILE ]; then
54             pid=`cat $PIDFILE`
55             kill -15 $pid
56             while ps -p $pid >/dev/null; do
57                 sleep 1
58             done
59             rm -f $PIDFILE
60         fi
61         ;;
62     status)
63         if [ -r $PIDFILE ]; then
64             echo "collectd daemon is running with PID `cat $PIDFILE`."
65         else
66             echo "collectd daemon is not running."
67         fi
68         ;;
69     restart)
70         ## Stop the service and regardless of whether it was
71         ## running or not, start it again.
72         $0 stop
73         $0 start
74         ;;
75     *)
76         echo "Usage: $0 {start|stop|status|restart}"
77         exit 1
78         ;;
79 esac