make the persistent dbdir configurable
[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 [ -z "$CTDB_BASE" ] && {
38     export CTDB_BASE="/etc/ctdb"
39 }
40
41 . $CTDB_BASE/functions
42 loadconfig network
43 loadconfig ctdb
44
45 # check networking is up (for redhat)
46 [ "${NETWORKING}" = "no" ] && exit 0
47
48 [ -z "$CTDB_RECOVERY_LOCK" ] && {
49     echo "You must configure the location of the CTDB_RECOVERY_LOCK"
50     exit 1
51 }
52 CTDB_OPTIONS="$CTDB_OPTIONS --reclock=$CTDB_RECOVERY_LOCK"
53
54 # build up CTDB_OPTIONS variable from optional parameters
55 [ -z "$CTDB_LOGFILE" ]          || CTDB_OPTIONS="$CTDB_OPTIONS --logfile=$CTDB_LOGFILE"
56 [ -z "$CTDB_NODES" ]            || CTDB_OPTIONS="$CTDB_OPTIONS --nlist=$CTDB_NODES"
57 [ -z "$CTDB_SOCKET" ]           || CTDB_OPTIONS="$CTDB_OPTIONS --socket=$CTDB_SOCKET"
58 [ -z "$CTDB_PUBLIC_ADDRESSES" ] || CTDB_OPTIONS="$CTDB_OPTIONS --public-addresses=$CTDB_PUBLIC_ADDRESSES"
59 [ -z "$CTDB_PUBLIC_INTERFACE" ] || CTDB_OPTIONS="$CTDB_OPTIONS --public-interface=$CTDB_PUBLIC_INTERFACE"
60 [ -z "$CTDB_DBDIR" ]            || CTDB_OPTIONS="$CTDB_OPTIONS --dbdir=$CTDB_DBDIR"
61 [ -z "$CTDB_DBDIR_PERSISTENT" ] || CTDB_OPTIONS="$CTDB_OPTIONS --dbdir-persistent=$CTDB_DBDIR_PERSISTENT"
62 [ -z "$CTDB_EVENT_SCRIPT_DIR" ] || CTDB_OPTIONS="$CTDB_OPTIONS --event-script-dir $CTDB_EVENT_SCRIPT_DIR"
63 [ -z "$CTDB_TRANSPORT" ]        || CTDB_OPTIONS="$CTDB_OPTIONS --transport $CTDB_TRANSPORT"
64 [ -z "$CTDB_DEBUGLEVEL" ]       || CTDB_OPTIONS="$CTDB_OPTIONS -d $CTDB_DEBUGLEVEL"
65
66 if [ -x /sbin/startproc ]; then
67     init_style="suse"
68 else if [ -x /sbin/start-stop-daemon ]; then
69         init_style="ubuntu"
70     else
71         init_style="redhat"
72     fi
73 fi
74
75 start() {
76         killall -q ctdbd
77         echo -n $"Starting ctdbd service: "
78         case $init_style in
79             suse)
80                 startproc /usr/sbin/ctdbd $CTDB_OPTIONS
81                 rc_status -v
82                 ;;
83             redhat)
84                 daemon ctdbd $CTDB_OPTIONS
85                 RETVAL=$?
86                 echo
87                 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ctdb || RETVAL=1
88                 return $RETVAL
89                 ;;
90             ubuntu)
91                 start-stop-daemon --start --quiet --background --exec /usr/sbin/ctdbd -- $CTDB_OPTIONS
92                 return $?
93                 ;;
94         esac
95 }       
96
97 stop() {
98         echo -n $"Shutting down ctdbd service: "
99         ctdb shutdown
100         RETVAL=$?
101         count=0
102         while killall -q -0 ctdbd; do
103             sleep 1
104             count=`expr $count + 1`
105             [ $count -gt 10 ] && {
106                 echo -n $"killing ctdbd "
107                 killall -q -9 ctdbd
108                 pkill -9 -f $CTDB_BASE/events.d/
109             }
110         done
111         case $init_style in
112             suse)
113                 rc_status -v
114                 ;;
115             redhat)
116                 echo
117                 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb
118                 echo ""
119                 return $RETVAL
120                 ;;
121         esac
122 }       
123
124 restart() {
125         stop
126         start
127 }       
128
129 status() {
130         ctdb status
131 }       
132
133
134 case "$1" in
135   start)
136         start
137         ;;
138   stop)
139         stop
140         ;;
141   restart)
142         restart
143         ;;
144   status)
145         status
146         ;;
147   condrestart)
148         ctdb status > /dev/null && restart || :
149         ;;
150   cron)
151         # used from cron to auto-restart ctdb
152         ctdb status > /dev/null || restart
153         ;;
154   *)
155         echo $"Usage: $0 {start|stop|restart|status|cron|condrestart}"
156         exit 1
157 esac
158
159 exit $?