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-addresses" "$CTDB_PUBLIC_ADDRESSES"
99 maybe_set "--public-interface" "$CTDB_PUBLIC_INTERFACE"
100 maybe_set "--dbdir" "$CTDB_DBDIR"
101 maybe_set "--dbdir-persistent" "$CTDB_DBDIR_PERSISTENT"
102 maybe_set "--dbdir-state" "$CTDB_DBDIR_STATE"
103 maybe_set "--transport" "$CTDB_TRANSPORT"
104 maybe_set "-d" "$CTDB_DEBUGLEVEL"
105 maybe_set "--notification-script" "$CTDB_NOTIFY_SCRIPT"
106 maybe_set "--start-as-disabled" "$CTDB_START_AS_DISABLED" "yes"
107 maybe_set "--start-as-stopped " "$CTDB_START_AS_STOPPED" "yes"
108 maybe_set "--no-recmaster" "$CTDB_CAPABILITY_RECMASTER" "no"
109 maybe_set "--no-lmaster" "$CTDB_CAPABILITY_LMASTER" "no"
110 maybe_set "--nosetsched" "$CTDB_NOSETSCHED" "yes"
111 maybe_set "--script-log-level" "$CTDB_SCRIPT_LOG_LEVEL"
112 maybe_set "--max-persistent-check-errors" "$CTDB_MAX_PERSISTENT_CHECK_ERRORS"
115 export_debug_variables ()
117 [ -n "$CTDB_DEBUG_HUNG_SCRIPT" ] && export CTDB_DEBUG_HUNG_SCRIPT
118 [ -n "$CTDB_DEBUG_LOCKS" ] && export CTDB_DEBUG_LOCKS
121 ############################################################
127 # build_ctdb_options() takes no arguments
128 # shellcheck disable=SC2119
131 export_debug_variables
133 # Explicitly trying to disable core files, no other way
134 # shellcheck disable=SC2039
135 if [ "$CTDB_SUPPRESS_COREFILE" = "yes" ]; then
141 # Unsupported option easily avoided by not using configuration variable
142 # shellcheck disable=SC2039
143 if [ -n "$CTDB_MAX_OPEN_FILES" ]; then
144 ulimit -n "$CTDB_MAX_OPEN_FILES"
147 if [ -n "$CTDB_VALGRIND" -a "$CTDB_VALGRIND" != "no" ] ; then
148 if [ "$CTDB_VALGRIND" = "yes" ] ; then
149 ctdbd="valgrind -q --log-file=/usr/local/var/log/ctdb_valgrind ${ctdbd}"
151 ctdbd="${CTDB_VALGRIND} ${ctdbd}"
153 ctdb_options="${ctdb_options} --valgrinding"
156 case "$CTDB_LOGGING" in
157 syslog:udp|syslog:udp-rfc5424)
158 logger -t ctdbd "CTDB is being run with ${CTDB_LOGGING}. If nothing is logged then check your syslogd configuration"
160 syslog|syslog:*) : ;;
162 logger -t ctdbd "CTDB is being run without syslog enabled. Logs will be in ${CTDB_LOGGING#file:}"
165 logger -t ctdbd "CTDB is being run without syslog enabled. Logs will be in log.ctdb"
168 eval "$ctdbd" "$ctdb_options" || return 1
170 # Wait until ctdbd has started and is ready to respond to clients.
171 _timeout="${CTDB_STARTUP_TIMEOUT:-10}"
173 while [ "$_count" -lt "$_timeout" ] ; do
174 if $CTDB runstate first_recovery startup running >/dev/null 2>&1 ; then
178 _count=$((_count + 1))
182 echo "Timed out waiting for initialisation - check logs"
183 # Attempt a shutdown just in case things are still running
184 $CTDB shutdown >/dev/null 2>&1
185 drop_all_public_ips >/dev/null 2>&1
193 # The above command is important and needs to stand out, so
194 # post-check exit status
195 # shellcheck disable=SC2181
196 if [ $? -ne 0 ] ; then
197 echo "Error while shutting down CTDB"
198 drop_all_public_ips >/dev/null 2>&1
207 ############################################################
209 # Allow notifications for start/stop.
210 if [ -x "$CTDB_BASE/rc.ctdb" ] ; then
211 "$CTDB_BASE/rc.ctdb" "$action"
218 echo "usage: $0 {start|stop}"