allow extra option override in /etc/sysconfig/ctdb
[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 [ -z "$CTDB_RECOVERY_LOCK" ] && {
45     echo "You must configure the location of the CTDB_RECOVERY_LOCK"
46     exit 1
47 }
48 CTDB_OPTIONS="$CTDB_OPTIONS --reclock=$CTDB_RECOVERY_LOCK"
49
50 # build up CTDB_OPTIONS variable from optional parameters
51 [ -z "$CTDB_LOGFILE" ]          || CTDB_OPTIONS="$CTDB_OPTIONS --logfile=$CTDB_LOGFILE"
52 [ -z "$CTDB_NODES" ]            || CTDB_OPTIONS="$CTDB_OPTIONS --nlist=$CTDB_NODES"
53 [ -z "$CTDB_SOCKET" ]           || CTDB_OPTIONS="$CTDB_OPTIONS --socket=$CTDB_SOCKET"
54 [ -z "$CTDB_PUBLIC_ADDRESSES" ] || CTDB_OPTIONS="$CTDB_OPTIONS --public-addresses=$CTDB_PUBLIC_ADDRESSES"
55 [ -z "$CTDB_PUBLIC_INTERFACE" ] || CTDB_OPTIONS="$CTDB_OPTIONS --public-interface=$CTDB_PUBLIC_INTERFACE"
56 [ -z "$CTDB_DBDIR" ]            || CTDB_OPTIONS="$CTDB_OPTIONS --dbdir=$CTDB_DBDIR"
57 [ -z "$CTDB_EVENT_SCRIPT" ]     || CTDB_OPTIONS="$CTDB_OPTIONS --event-script $CTDB_EVENT_SCRIPT"
58 [ -z "$CTDB_TRANSPORT" ]        || CTDB_OPTIONS="$CTDB_OPTIONS --transport $CTDB_TRANSPORT"
59 [ -z "$CTDB_DEBUGLEVEL" ]       || CTDB_OPTIONS="$CTDB_OPTIONS -d $CTDB_DEBUGLEVEL"
60
61 if [ -x /sbin/startproc ]; then
62     init_style="suse"
63 else if [ -x /sbin/start-stop-daemon ]; then
64         init_style="ubuntu"
65     else
66         init_style="redhat"
67     fi
68 fi
69
70 start() {
71         killall -q ctdbd
72         echo -n $"Starting ctdbd service: "
73         case $init_style in
74             suse)
75                 startproc /usr/sbin/ctdbd $CTDB_OPTIONS
76                 rc_status -v
77                 ;;
78             redhat)
79                 daemon ctdbd $CTDB_OPTIONS
80                 RETVAL=$?
81                 echo
82                 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ctdb || RETVAL=1
83                 return $RETVAL
84                 ;;
85             ubuntu)
86                 start-stop-daemon --start --quiet --background --exec /usr/sbin/ctdbd -- $CTDB_OPTIONS
87                 return $?
88                 ;;
89         esac
90 }       
91
92 stop() {
93         echo -n $"Shutting down ctdbd service: "
94         ctdb shutdown
95         RETVAL=$?
96         case $init_style in
97             suse)
98                 rc_status -v
99                 ;;
100             redhat)
101                 echo
102                 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb
103                 echo ""
104                 return $RETVAL
105                 ;;
106         esac
107 }       
108
109 restart() {
110         stop
111         start
112 }       
113
114 status() {
115         ctdb status
116 }       
117
118
119 case "$1" in
120   start)
121         start
122         ;;
123   stop)
124         stop
125         ;;
126   restart)
127         restart
128         ;;
129   status)
130         status
131         ;;
132   condrestart)
133         ctdb status > /dev/null && restart || :
134         ;;
135   cron)
136         # used from cron to auto-restart ctdb
137         ctdb status > /dev/null || restart
138         ;;
139   *)
140         echo $"Usage: $0 {start|stop|restart|status|cron|condrestart}"
141         exit 1
142 esac
143
144 exit $?