1#!/bin/sh
2#
3# chkconfig: - 91 35
4# description: Starts and stops the carbonzipper daemon
5#
6# pidfile: /var/run/carbonzipper.pid
7# config:  /usr/local/etc/carbon.conf
8
9carbon="/usr/bin/carbonzipper"
10prog=$(basename $carbon)
11pidfile="/var/run/carbonzipper.pid"
12config="/etc/carbonzipper/carbonzipper.conf"
13
14# Source function library.
15if [ -f /etc/init.d/functions ] ; then
16    . /etc/init.d/functions
17elif [ -f /etc/rc.d/init.d/functions ] ; then
18    . /etc/rc.d/init.d/functions
19else
20    exit 1
21fi
22
23# Avoid using root's TMPDIR
24unset TMPDIR
25
26if [ -f /etc/sysconfig/$prog ]; then
27   . /etc/sysconfig/$prog
28fi
29
30# Check that config exists.
31[ -f $config ] || exit 6
32
33RETVAL=0
34
35start() {
36    echo -n $"Starting $prog services: "
37    daemon --pidfile $pidfile $carbon -config $config -pidfile $pidfile
38    RETVAL=$?
39    echo
40    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog || \
41        RETVAL=1
42    return $RETVAL
43}
44
45stop() {
46    echo -n $"Shutting down $prog services: "
47    killproc -p $pidfile
48    RETVAL=$?
49    echo
50    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
51    return $RETVAL
52}
53
54restart() {
55    stop
56    start
57}
58
59reload() {
60    echo -n $"Reloading $prog: "
61    killproc -p $pidfile $prog -USR2
62    RETVAL=$?
63    echo
64    return $RETVAL
65}
66
67rhstatus() {
68    status -p $pidfile
69    return $?
70}
71
72
73# Allow status as non-root.
74if [ "$1" = status ]; then
75    rhstatus
76    exit $?
77fi
78
79# Check that we can write to it... so non-root users stop here
80[ -w $config ] || exit 4
81
82
83case "$1" in
84    start)
85        start
86        ;;
87    stop)
88        stop
89        ;;
90    restart)
91        restart
92        ;;
93    reload)
94        reload
95        ;;
96    status)
97        rhstatus
98        ;;
99    condrestart)
100        [ -f /var/lock/subsys/$prog ] && restart || :
101        ;;
102    *)
103    echo $"Usage: $0 {start|stop|restart|reload|status|condrestart}"
104    exit 2
105esac
106
107exit $?
108