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
"--listen" "$CTDB_NODE_ADDRESS"
97 maybe_set
"--dbdir" "$CTDB_DBDIR"
98 maybe_set
"--dbdir-persistent" "$CTDB_DBDIR_PERSISTENT"
99 maybe_set
"--dbdir-state" "$CTDB_DBDIR_STATE"
100 maybe_set
"--transport" "$CTDB_TRANSPORT"
101 maybe_set
"-d" "$CTDB_DEBUGLEVEL"
102 maybe_set
"--notification-script" "$CTDB_NOTIFY_SCRIPT"
103 maybe_set
"--start-as-disabled" "$CTDB_START_AS_DISABLED" "yes"
104 maybe_set
"--start-as-stopped " "$CTDB_START_AS_STOPPED" "yes"
105 maybe_set
"--no-recmaster" "$CTDB_CAPABILITY_RECMASTER" "no"
106 maybe_set
"--no-lmaster" "$CTDB_CAPABILITY_LMASTER" "no"
107 maybe_set
"--nosetsched" "$CTDB_NOSETSCHED" "yes"
108 maybe_set
"--script-log-level" "$CTDB_SCRIPT_LOG_LEVEL"
109 maybe_set
"--max-persistent-check-errors" "$CTDB_MAX_PERSISTENT_CHECK_ERRORS"
112 export_debug_variables
()
114 [ -n "$CTDB_DEBUG_HUNG_SCRIPT" ] && export CTDB_DEBUG_HUNG_SCRIPT
115 [ -n "$CTDB_DEBUG_LOCKS" ] && export CTDB_DEBUG_LOCKS
118 ############################################################
124 # build_ctdb_options() takes no arguments
125 # shellcheck disable=SC2119
128 export_debug_variables
130 # Explicitly trying to disable core files, no other way
131 # shellcheck disable=SC2039
132 if [ "$CTDB_SUPPRESS_COREFILE" = "yes" ]; then
138 # Unsupported option easily avoided by not using configuration variable
139 # shellcheck disable=SC2039
140 if [ -n "$CTDB_MAX_OPEN_FILES" ]; then
141 ulimit -n "$CTDB_MAX_OPEN_FILES"
144 if [ -n "$CTDB_VALGRIND" -a "$CTDB_VALGRIND" != "no" ] ; then
145 if [ "$CTDB_VALGRIND" = "yes" ] ; then
146 ctdbd
="valgrind -q --log-file=/usr/local/var/log/ctdb_valgrind ${ctdbd}"
148 ctdbd
="${CTDB_VALGRIND} ${ctdbd}"
150 ctdb_options
="${ctdb_options} --valgrinding"
153 case "$CTDB_LOGGING" in
154 syslog
:udp|syslog
:udp-rfc5424
)
155 logger
-t ctdbd
"CTDB is being run with ${CTDB_LOGGING}. If nothing is logged then check your syslogd configuration"
157 syslog|syslog
:*) : ;;
159 logger
-t ctdbd
"CTDB is being run without syslog enabled. Logs will be in ${CTDB_LOGGING#file:}"
162 logger
-t ctdbd
"CTDB is being run without syslog enabled. Logs will be in log.ctdb"
165 eval "$ctdbd" "$ctdb_options" ||
return 1
167 # Wait until ctdbd has started and is ready to respond to clients.
168 _timeout
="${CTDB_STARTUP_TIMEOUT:-10}"
170 while [ "$_count" -lt "$_timeout" ] ; do
171 if $CTDB runstate first_recovery startup running
>/dev
/null
2>&1 ; then
175 _count
=$
((_count
+ 1))
179 echo "Timed out waiting for initialisation - check logs"
180 # Attempt a shutdown just in case things are still running
181 $CTDB shutdown
>/dev
/null
2>&1
182 drop_all_public_ips
>/dev
/null
2>&1
190 # The above command is important and needs to stand out, so
191 # post-check exit status
192 # shellcheck disable=SC2181
193 if [ $?
-ne 0 ] ; then
194 echo "Error while shutting down CTDB"
195 drop_all_public_ips
>/dev
/null
2>&1
204 ############################################################
206 # Allow notifications for start/stop.
207 if [ -x "$CTDB_BASE/rc.ctdb" ] ; then
208 "$CTDB_BASE/rc.ctdb" "$action"
215 echo "usage: $0 {start|stop}"