printing: Avoid zombies in the background daemon
[Samba.git] / ctdb / config / ctdbd_wrapper
blob34827eaaa29c6c7379e01eea8353523fa31c93eb
1 #!/bin/sh
3 # ctdbd wrapper - start or stop CTDB
5 usage ()
7 echo "usage: ctdbd_wrapper { start | stop }"
8 exit 1
11 [ $# -eq 1 ] || usage
13 action="$1"
15 ############################################################
17 if [ -z "$CTDB_BASE" ] ; then
18 export CTDB_BASE="/usr/local/etc/ctdb"
21 . "${CTDB_BASE}/functions"
23 load_system_config "ctdb"
25 ctdbd="${CTDBD:-/usr/local/sbin/ctdbd}"
27 ############################################################
29 start()
31 eval "$ctdbd" || return 1
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
41 _count=$((_count + 1))
42 sleep 1
43 done
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
52 stop()
54 $CTDB shutdown
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
65 return 0
68 ############################################################
70 # Allow notifications for start/stop.
71 if [ -x "$CTDB_BASE/rc.ctdb" ] ; then
72 "$CTDB_BASE/rc.ctdb" "$action"
75 case "$action" in
76 start) start ;;
77 stop) stop ;;
79 echo "usage: $0 {start|stop}"
80 exit 1
81 esac