ctdb: Drop configuration file ctdbd.conf
[samba.git] / ctdb / config / ctdbd_wrapper
1 #!/bin/sh
2
3 # ctdbd wrapper - start or stop CTDB
4
5 usage ()
6 {
7     echo "usage: ctdbd_wrapper { start | stop }"
8     exit 1
9 }
10
11 [ $# -eq 1 ] || usage
12
13 action="$1"
14
15 ############################################################
16
17 if [ -z "$CTDB_BASE" ] ; then
18     export CTDB_BASE="/usr/local/etc/ctdb"
19 fi
20
21 . "${CTDB_BASE}/functions"
22
23 load_system_config "ctdb"
24
25 ctdbd="${CTDBD:-/usr/local/sbin/ctdbd}"
26
27 ############################################################
28
29 start()
30 {
31     eval "$ctdbd" || return 1
32
33     # Wait until ctdbd has started and is ready to respond to clients.
34     _timeout="${CTDB_STARTUP_TIMEOUT:-10}"
35     _count=0
36     while [ "$_count" -lt "$_timeout" ] ; do
37         if $CTDB runstate first_recovery startup running >/dev/null 2>&1 ; then
38             return 0
39         fi
40
41         _count=$((_count + 1))
42         sleep 1
43     done
44
45     echo "Timed out waiting for initialisation - check logs"
46     # Attempt a shutdown just in case things are still running
47     $CTDB shutdown >/dev/null 2>&1
48     drop_all_public_ips >/dev/null 2>&1
49     return 1
50 }
51
52 stop()
53 {
54         $CTDB shutdown
55
56         # The above command is important and needs to stand out, so
57         # post-check exit status
58         # shellcheck disable=SC2181
59         if [ $? -ne 0 ] ; then
60                 echo "Error while shutting down CTDB"
61                 drop_all_public_ips >/dev/null 2>&1
62                 return 1
63         fi
64
65         return 0
66 }
67
68 ############################################################
69
70 # Allow notifications for start/stop.
71 if [ -x "$CTDB_BASE/rc.ctdb" ] ; then
72     "$CTDB_BASE/rc.ctdb" "$action"
73 fi
74
75 case "$action" in
76     start) start ;;
77     stop)  stop  ;;
78     *)
79         echo "usage: $0 {start|stop}"
80         exit 1
81 esac