3 # ctdbd wrapper - start or stop CTDB
7 echo "usage: ctdbd_wrapper { start | stop }"
15 ############################################################
17 if [ -z "$CTDB_BASE" ] ; then
18 export CTDB_BASE="/usr/local/etc/ctdb"
21 . "${CTDB_BASE}/functions"
25 ctdbd="${CTDBD:-/usr/local/sbin/ctdbd}"
27 ############################################################
29 # Only the nested function references its arguments
30 # shellcheck disable=SC2120
40 # If the given variable isn't set then do nothing
41 [ -n "$_val" ] || return
42 # If a value is required for the variable and it doesn't
43 # match, then do nothing
44 if [ -n "$_check" -a "$_check" != "$_val" ] ; then
48 # Configuration file handling needs true/false, not yes/no
54 if grep -q "^\\[${_section}\\]\\$" "$_conf_file" ; then
55 # Section already exists...
56 # Must escape leading TAB or sed eats it
57 sed -i -e "/\\[${_section}\\]/a\
61 # Section does not exist and needs to be created...
62 # Note literal TAB for indentation in here document
63 cat >>"${_conf_file}" <<EOF
71 # Only write a new style configuration file if it doesn't already
73 _conf_file="${CTDB_BASE}/ctdb.conf"
74 if [ -f "$_conf_file" ] ; then
80 # Create configuration file from old style options
81 maybe_set "cluster" "recovery lock" "$CTDB_RECOVERY_LOCK"
82 maybe_set "logging" "location" "$CTDB_LOGGING"
83 maybe_set "cluster" "node address" "$CTDB_NODE_ADDRESS"
84 maybe_set "database" "volatile database directory" \
86 maybe_set "database" "persistent database directory" \
87 "$CTDB_DBDIR_PERSISTENT"
88 maybe_set "database" "state database directory" \
90 maybe_set "cluster" "transport" "$CTDB_TRANSPORT"
91 maybe_set "logging" "log level" "$CTDB_DEBUGLEVEL"
92 maybe_set "legacy" "start as disabled" "$CTDB_START_AS_DISABLED" "yes"
93 maybe_set "legacy" "start as stopped" "$CTDB_START_AS_STOPPED" "yes"
94 maybe_set "legacy" "recmaster capability" \
95 "$CTDB_CAPABILITY_RECMASTER" "no"
96 maybe_set "legacy" "lmaster capability" \
97 "$CTDB_CAPABILITY_LMASTER" "no"
98 maybe_set "legacy" "no realtime" "$CTDB_NOSETSCHED" "yes"
99 maybe_set "legacy" "script log level" "$CTDB_SCRIPT_LOG_LEVEL"
100 maybe_set "database" "volatile uses tmpfs" \
101 "$CTDB_DBDIR_USES_TMPFS" "yes"
104 export_debug_variables ()
106 [ -n "$CTDB_DEBUG_HUNG_SCRIPT" ] && export CTDB_DEBUG_HUNG_SCRIPT
107 [ -n "$CTDB_DEBUG_LOCKS" ] && export CTDB_DEBUG_LOCKS
110 ############################################################
114 # build_ctdb_options() takes no arguments
115 # shellcheck disable=SC2119
118 export_debug_variables
120 eval "$ctdbd" || return 1
122 # Wait until ctdbd has started and is ready to respond to clients.
123 _timeout="${CTDB_STARTUP_TIMEOUT:-10}"
125 while [ "$_count" -lt "$_timeout" ] ; do
126 if $CTDB runstate first_recovery startup running >/dev/null 2>&1 ; then
130 _count=$((_count + 1))
134 echo "Timed out waiting for initialisation - check logs"
135 # Attempt a shutdown just in case things are still running
136 $CTDB shutdown >/dev/null 2>&1
137 drop_all_public_ips >/dev/null 2>&1
145 # The above command is important and needs to stand out, so
146 # post-check exit status
147 # shellcheck disable=SC2181
148 if [ $? -ne 0 ] ; then
149 echo "Error while shutting down CTDB"
150 drop_all_public_ips >/dev/null 2>&1
157 ############################################################
159 # Allow notifications for start/stop.
160 if [ -x "$CTDB_BASE/rc.ctdb" ] ; then
161 "$CTDB_BASE/rc.ctdb" "$action"
168 echo "usage: $0 {start|stop}"