make the init scripts more portable about location of system config files
[metze/ctdb/wip.git] / config / ctdb.init
1 #!/bin/sh
2 #
3 ##############################
4 # init info for redhat distros
5 # chkconfig: - 90 36
6 # description: Starts and stops the clustered tdb daemon
7 # pidfile: /var/run/ctdbd/ctdbd.pid
8 ##############################
9
10 ##############################
11 # SLES/OpenSuSE init info
12 ### BEGIN INIT INFO
13 # Provides:       ctdb
14 # Required-Start: $network
15 # Required-Stop:
16 # Default-Start:  3 5
17 # Default-Stop:
18 # Description:    initscript for the ctdb service
19 ### END INIT INFO
20
21 # Source function library.
22 if [ -f /etc/init.d/functions ] ; then
23   . /etc/init.d/functions
24 elif [ -f /etc/rc.d/init.d/functions ] ; then
25   . /etc/rc.d/init.d/functions
26 fi
27
28 [ -f /etc/rc.status ] && {
29     . /etc/rc.status
30     rc_reset
31     LC_ALL=en_US.UTF-8
32 }
33
34 # Avoid using root's TMPDIR
35 unset TMPDIR
36
37 . /etc/ctdb/functions
38 loadconfig network
39 loadconfig ctdb
40
41 # check networking is up (for redhat)
42 [ ${NETWORKING} = "no" ] && exit 0
43
44 CTDB_OPTIONS=""
45
46 [ -z "$CTDB_RECOVERY_LOCK" ] && {
47     echo "You must configure the location of the CTDB_RECOVERY_LOCK"
48     exit 1
49 }
50 CTDB_OPTIONS="$CTDB_OPTIONS --reclock=$CTDB_RECOVERY_LOCK"
51
52 # build up CTDB_OPTIONS variable from optional parameters
53 [ -z "$LOGFILE" ]          || CTDB_OPTIONS="$CTDB_OPTIONS --logfile=$LOGFILE"
54 [ -z "$NODES" ]            || CTDB_OPTIONS="$CTDB_OPTIONS --nlist=$NODES"
55 [ -z "$CTDB_SOCKET" ]      || CTDB_OPTIONS="$CTDB_OPTIONS --socket=$CTDB_SOCKET"
56 [ -z "$PUBLIC_ADDRESSES" ] || CTDB_OPTIONS="$CTDB_OPTIONS --public-addresses=$PUBLIC_ADDRESSES"
57 [ -z "$PUBLIC_INTERFACE" ] || CTDB_OPTIONS="$CTDB_OPTIONS --public-interface=$PUBLIC_INTERFACE"
58 [ -z "$DBDIR" ]            || CTDB_OPTIONS="$CTDB_OPTIONS --dbdir=$DBDIR"
59 [ -z "$EVENT_SCRIPT" ]     || CTDB_OPTIONS="$CTDB_OPTIONS --event-script $EVENT_SCRIPT"
60 [ -z "$TRANSPORT" ]        || CTDB_OPTIONS="$CTDB_OPTIONS --transport $TRANSPORT"
61 [ -z "$DEBUGLEVEL" ]       || CTDB_OPTIONS="$CTDB_OPTIONS -d $DEBUGLEVEL"
62
63 if [ -x /sbin/startproc ]; then
64     init_style="suse"
65 else if [ -x /sbin/start-stop-daemon ]; then
66         init_style="ubuntu"
67     else
68         init_style="redhat"
69     fi
70 fi
71
72 start() {
73         killall -q ctdbd
74         echo -n $"Starting ctdbd service: "
75         case $init_style in
76             suse)
77                 startproc /usr/sbin/ctdbd $CTDB_OPTIONS
78                 rc_status -v
79                 ;;
80             redhat)
81                 daemon ctdbd $CTDB_OPTIONS
82                 RETVAL=$?
83                 echo
84                 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ctdb || RETVAL=1
85                 return $RETVAL
86                 ;;
87             ubuntu)
88                 start-stop-daemon --start --quiet --background --exec /usr/sbin/ctdbd -- $CTDB_OPTIONS
89                 return $?
90                 ;;
91         esac
92 }       
93
94 stop() {
95         echo -n $"Shutting down ctdbd service: "
96         ctdb shutdown
97         RETVAL=$?
98         case $init_style in
99             suse)
100                 rc_status -v
101                 ;;
102             redhat)
103                 echo
104                 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb
105                 echo ""
106                 return $RETVAL
107                 ;;
108         esac
109 }       
110
111 restart() {
112         stop
113         start
114 }       
115
116 status() {
117         ctdb status
118 }       
119
120
121 case "$1" in
122   start)
123         start
124         ;;
125   stop)
126         stop
127         ;;
128   restart)
129         restart
130         ;;
131   status)
132         status
133         ;;
134   condrestart)
135         ctdb status > /dev/null && restart || :
136         ;;
137   cron)
138         # used from cron to auto-restart ctdb
139         ctdb status > /dev/null || restart
140         ;;
141   *)
142         echo $"Usage: $0 {start|stop|restart|status|cron|condrestart}"
143         exit 1
144 esac
145
146 exit $?