recoverd: Improve log message when nodes disagree on recmaster
[ctdb.git] / config / ctdb.init
1 #!/bin/sh
2
3 # Start and stop CTDB (Clustered TDB daemon)
4 #
5 # chkconfig: - 90 01
6 #
7 # description: Starts and stops CTDB
8 # pidfile: /var/run/ctdb/ctdbd.pid
9 # config: /etc/sysconfig/ctdb
10
11 ### BEGIN INIT INFO
12 # Provides:            ctdb
13 # Required-Start:      $local_fs $syslog $network
14 # Required-Stop:       $local_fs $syslog $network
15 # Default-Start:       2 3 4 5
16 # Default-Stop:        0 1 6
17 # Short-Description:   start and stop ctdb service
18 # Description:         Start and stop CTDB (Clustered TDB daemon)
19 ### END INIT INFO
20
21 # Source function library.
22 if [ -f /etc/init.d/functions ] ; then
23     # Red Hat
24     . /etc/init.d/functions
25 elif [ -f /etc/rc.d/init.d/functions ] ; then
26     # Red Hat
27     . /etc/rc.d/init.d/functions
28 elif [ -f /etc/rc.status ] ; then
29     # SUSE
30     . /etc/rc.status
31     rc_reset
32     LC_ALL=en_US.UTF-8
33 elif [ -f /lib/lsb/init-functions ] ; then
34     # Debian
35     . /lib/lsb/init-functions
36 fi
37
38 # Avoid using root's TMPDIR
39 unset TMPDIR
40
41 [ -n "$CTDB_BASE" ] || export CTDB_BASE="/etc/ctdb"
42
43 . "${CTDB_BASE}/functions"
44 loadconfig "network"
45 loadconfig "ctdb"
46
47 # check networking is up (for redhat)
48 if [ "$NETWORKING" = "no" ] ; then
49     exit 0
50 fi
51
52 detect_init_style
53 export CTDB_INIT_STYLE
54
55 ctdbd="${CTDBD:-/usr/sbin/ctdbd}"
56 ctdbd_wrapper="${CTDBD_WRAPPER:-/usr/sbin/ctdbd_wrapper}"
57 pidfile="${CTDB_PIDFILE:-/var/run/ctdb/ctdbd.pid}"
58
59 ############################################################
60
61 start()
62 {
63     echo -n "Starting ctdbd service: "
64
65     case "$CTDB_INIT_STYLE" in
66         suse)
67             startproc \
68                 "$ctdbd_wrapper" "$pidfile" "start"
69             rc_status -v
70             ;;
71         redhat)
72             daemon --pidfile "$pidfile" \
73                 "$ctdbd_wrapper" "$pidfile" "start"
74             RETVAL=$?
75             echo
76             [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ctdb || RETVAL=1
77             return $RETVAL
78             ;;
79         debian)
80             eval start-stop-daemon --start --quiet --background --exec \
81                 "$ctdbd_wrapper" "$pidfile" "start"
82             ;;
83     esac
84 }
85
86 stop()
87 {
88     echo -n "Shutting down ctdbd service: "
89
90     case "$CTDB_INIT_STYLE" in
91         suse)
92             "$ctdbd_wrapper" "$pidfile" "stop"
93             rc_status -v
94             ;;
95         redhat)
96             "$ctdbd_wrapper" "$pidfile" "stop"
97             RETVAL=$?
98             [ $RETVAL -eq 0 ] && success || failure
99             echo ""
100             [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb
101             return $RETVAL
102             ;;
103         debian)
104             "$ctdbd_wrapper" "$pidfile" "stop"
105             log_end_msg $?
106             ;;
107     esac
108 }
109
110 restart()
111 {
112     stop
113     start
114 }
115
116 check_status ()
117 {
118     # Backward compatibility.  When we arrange to pass --pidfile to
119     # ctdbd we also create the directory that will contain it.  If
120     # that directory is missing then we don't use the pidfile to check
121     # status.  Note that this probably won't work if
122     # $CTDB_VALGRIND="yes" but this doesn't need full backward
123     # compatibility because it is a debug option.
124     if [ -d $(dirname "$pidfile") ] ; then
125         _pf_opt="-p $pidfile"
126     else
127         _pf_opt=""
128     fi
129
130     case "$CTDB_INIT_STYLE" in
131         suse)
132             checkproc $_pf_opt "$ctdbd"
133             rc_status -v
134             ;;
135         redhat)
136             status $_pf_opt -l "ctdb" "$ctdbd"
137             ;;
138         debian)
139             status_of_proc $_pf_opt "$ctdbd" "ctdb"
140             ;;
141     esac
142 }
143
144 ############################################################
145
146 case "$1" in
147     start)
148         start
149         ;;
150     stop)
151         stop
152         ;;
153     restart|reload|force-reload)
154         restart
155         ;;
156     status)
157         check_status
158         ;;
159     condrestart|try-restart)
160         if check_status >/dev/null ; then
161             restart
162         fi
163         ;;
164     cron)
165         # used from cron to auto-restart ctdb
166         check_status >/dev/null 2>&1 || restart
167         ;;
168     *)
169         echo "Usage: $0 {start|stop|restart|reload|force-reload|status|cron|condrestart|try-restart}"
170         exit 1
171 esac