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"
24 ctdbd="${CTDBD:-/usr/local/sbin/ctdbd}"
26 ############################################################
28 # If necessary, mount volatile database directory on tmpfs
31 if [ -z "$CTDB_DBDIR_TMPFS_OPTIONS" ] ; then
35 # Shortcut for readability
36 _opts="$CTDB_DBDIR_TMPFS_OPTIONS"
38 mkdir -p "$CTDB_DBDIR" || exit $?
40 # If already mounted then remount, otherwise mount
41 if findmnt -t tmpfs "$CTDB_DBDIR" >/dev/null ; then
42 mount -t tmpfs -o "remount,$_opts" none "$CTDB_DBDIR" || \
45 mount -t tmpfs -o "$_opts" none "$CTDB_DBDIR" || exit $?
49 # If necessary, unmount volatile database tmpfs directory on exit
52 if [ -z "$CTDB_DBDIR_TMPFS_OPTIONS" ] ; then
56 if [ -d "$CTDB_DBDIR" ] && findmnt -t tmpfs "$CTDB_DBDIR" >/dev/null ; then
61 # Only the nested function references its arguments
62 # shellcheck disable=SC2120
69 # If the given variable isn't set then do nothing
71 # If a required value for the variable and it doesn't match,
73 [ -z "$3" -o "$3" = "$2" ] || return
80 # For these options we're only passing a value-less flag.
86 ctdb_options="${ctdb_options}${ctdb_options:+ }${1}${sep}${val}"
89 if [ -z "$CTDB_RECOVERY_LOCK" ] ; then
90 echo "No recovery lock specified. Starting CTDB without split brain prevention."
92 maybe_set "--reclock" "$CTDB_RECOVERY_LOCK"
94 # build up ctdb_options variable from optional parameters
95 maybe_set "--logging" "$CTDB_LOGGING"
96 maybe_set "--nlist" "$CTDB_NODES"
97 maybe_set "--listen" "$CTDB_NODE_ADDRESS"
98 maybe_set "--public-interface" "$CTDB_PUBLIC_INTERFACE"
99 maybe_set "--dbdir" "$CTDB_DBDIR"
100 maybe_set "--dbdir-persistent" "$CTDB_DBDIR_PERSISTENT"
101 maybe_set "--dbdir-state" "$CTDB_DBDIR_STATE"
102 maybe_set "--transport" "$CTDB_TRANSPORT"
103 maybe_set "-d" "$CTDB_DEBUGLEVEL"
104 maybe_set "--notification-script" "$CTDB_NOTIFY_SCRIPT"
105 maybe_set "--start-as-disabled" "$CTDB_START_AS_DISABLED" "yes"
106 maybe_set "--start-as-stopped " "$CTDB_START_AS_STOPPED" "yes"
107 maybe_set "--no-recmaster" "$CTDB_CAPABILITY_RECMASTER" "no"
108 maybe_set "--no-lmaster" "$CTDB_CAPABILITY_LMASTER" "no"
109 maybe_set "--nosetsched" "$CTDB_NOSETSCHED" "yes"
110 maybe_set "--script-log-level" "$CTDB_SCRIPT_LOG_LEVEL"
111 maybe_set "--max-persistent-check-errors" "$CTDB_MAX_PERSISTENT_CHECK_ERRORS"
114 export_debug_variables ()
116 [ -n "$CTDB_DEBUG_HUNG_SCRIPT" ] && export CTDB_DEBUG_HUNG_SCRIPT
117 [ -n "$CTDB_DEBUG_LOCKS" ] && export CTDB_DEBUG_LOCKS
120 ############################################################
126 # build_ctdb_options() takes no arguments
127 # shellcheck disable=SC2119
130 export_debug_variables
132 # Explicitly trying to disable core files, no other way
133 # shellcheck disable=SC2039
134 if [ "$CTDB_SUPPRESS_COREFILE" = "yes" ]; then
140 # Unsupported option easily avoided by not using configuration variable
141 # shellcheck disable=SC2039
142 if [ -n "$CTDB_MAX_OPEN_FILES" ]; then
143 ulimit -n "$CTDB_MAX_OPEN_FILES"
146 if [ -n "$CTDB_VALGRIND" -a "$CTDB_VALGRIND" != "no" ] ; then
147 if [ "$CTDB_VALGRIND" = "yes" ] ; then
148 ctdbd="valgrind -q --log-file=/usr/local/var/log/ctdb_valgrind ${ctdbd}"
150 ctdbd="${CTDB_VALGRIND} ${ctdbd}"
152 ctdb_options="${ctdb_options} --valgrinding"
155 case "$CTDB_LOGGING" in
156 syslog:udp|syslog:udp-rfc5424)
157 logger -t ctdbd "CTDB is being run with ${CTDB_LOGGING}. If nothing is logged then check your syslogd configuration"
159 syslog|syslog:*) : ;;
161 logger -t ctdbd "CTDB is being run without syslog enabled. Logs will be in ${CTDB_LOGGING#file:}"
164 logger -t ctdbd "CTDB is being run without syslog enabled. Logs will be in log.ctdb"
167 eval "$ctdbd" "$ctdb_options" || return 1
169 # Wait until ctdbd has started and is ready to respond to clients.
170 _timeout="${CTDB_STARTUP_TIMEOUT:-10}"
172 while [ "$_count" -lt "$_timeout" ] ; do
173 if $CTDB runstate first_recovery startup running >/dev/null 2>&1 ; then
177 _count=$((_count + 1))
181 echo "Timed out waiting for initialisation - check logs"
182 # Attempt a shutdown just in case things are still running
183 $CTDB shutdown >/dev/null 2>&1
184 drop_all_public_ips >/dev/null 2>&1
192 # The above command is important and needs to stand out, so
193 # post-check exit status
194 # shellcheck disable=SC2181
195 if [ $? -ne 0 ] ; then
196 echo "Error while shutting down CTDB"
197 drop_all_public_ips >/dev/null 2>&1
206 ############################################################
208 # Allow notifications for start/stop.
209 if [ -x "$CTDB_BASE/rc.ctdb" ] ; then
210 "$CTDB_BASE/rc.ctdb" "$action"
217 echo "usage: $0 {start|stop}"