-# ctdbd_is_running()
-
-# 1. Check if ctdbd is running.
-# - If the PID file is being used then, if the PID file is present,
-# ctdbd is only considered to running if the PID in the file is
-# active.
-# - If the PID file is not being used (i.e. we're upgrading from a
-# version that doesn't support it) then the presence of any ctdbd
-# processes is enough proof.
-
-# 2. Print a comma-separated list of PIDs that can be
-# used with "pkill -s".
-# - If the PID file is being used then this is just the PID in that
-# file. This also happens to be the session ID, so can be used
-# to kill all CTDB processes.
-# - If the PID file is not being used (i.e. upgrading) then this is
-# just any ctdbd processes that are running. Hopefully one of
-# them is the session ID so that it can be used to kill all CTDB
-# processes.
-
-# Combining these 2 checks is an optimisation to avoid potentially
-# running too many pgrep/pkill processes on an already loaded system.
-# Trawling through /proc/ can be very expensive.
-
-ctdbd_is_running ()
-{
- # If the directory for the PID file exists then respect the
- # existence of a PID file.
- _pidfile_dir=$(dirname "$pidfile")
- if [ -d "$_pidfile_dir" ] ; then
- if read _pid 2>/dev/null <"$pidfile" ; then
- echo "$_pid"
-
- # Return value of kill is used
- kill -0 $_pid 2>/dev/null
- else
- # Missing/empty PID file
- return 1
- fi
- else
- if _pid=$(pgrep -f "${ctdbd}\>") ; then
- echo $_pid | sed -e 's@ @,@g'
- return 0
- else
- return 1
- fi
- fi
-}
-
-############################################################
-
-# If necessary, mount volatile database directory on tmpfs
-dbdir_tmpfs_start ()
-{
- if [ -z "$CTDB_DBDIR_TMPFS_OPTIONS" ] ; then
- return
- fi
-
- # Shortcut for readability
- _opts="$CTDB_DBDIR_TMPFS_OPTIONS"
-
- mkdir -p "$CTDB_DBDIR" || exit $?
-
- # If already mounted then remount, otherwise mount
- if findmnt -t tmpfs "$CTDB_DBDIR" >/dev/null ; then
- mount -t tmpfs -o "remount,$_opts" none "$CTDB_DBDIR" || \
- exit $?
- else
- mount -t tmpfs -o "$_opts" none "$CTDB_DBDIR" || exit $?
- fi
-}
-
-# If necessary, unmount volatile database tmpfs directory on exit
-dbdir_tmpfs_stop ()
-{
- if [ -z "$CTDB_DBDIR_TMPFS_OPTIONS" ] ; then
- return
- fi
-
- if [ -d "$CTDB_DBDIR" ] && findmnt -t tmpfs "$CTDB_DBDIR" >/dev/null ; then
- umount "$CTDB_DBDIR"
- fi
-}
-
-build_ctdb_options ()
-{
- ctdb_options=""
-
- maybe_set ()
- {
- # If the given variable isn't set then do nothing
- [ -n "$2" ] || return
- # If a required value for the variable and it doesn't match,
- # then do nothing
- [ -z "$3" -o "$3" = "$2" ] || return
-
- val="'$2'"
- case "$1" in
- --*) sep="=" ;;
- -*) sep=" " ;;
- esac
- # For these options we're only passing a value-less flag.
- if [ -n "$3" ] ; then
- val=""
- sep=""
- fi
-
- ctdb_options="${ctdb_options}${ctdb_options:+ }${1}${sep}${val}"
- }
-
- if [ -z "$CTDB_RECOVERY_LOCK" ] ; then
- echo "No recovery lock specified. Starting CTDB without split brain prevention."
- fi
- maybe_set "--reclock" "$CTDB_RECOVERY_LOCK"
-
- maybe_set "--pidfile" "$pidfile"
-
- # build up ctdb_options variable from optional parameters
- maybe_set "--logging" "$CTDB_LOGGING"
- maybe_set "--nlist" "$CTDB_NODES"
- maybe_set "--socket" "$CTDB_SOCKET"
- maybe_set "--listen" "$CTDB_NODE_ADDRESS"
- maybe_set "--public-addresses" "$CTDB_PUBLIC_ADDRESSES"
- maybe_set "--public-interface" "$CTDB_PUBLIC_INTERFACE"
- maybe_set "--dbdir" "$CTDB_DBDIR"
- maybe_set "--dbdir-persistent" "$CTDB_DBDIR_PERSISTENT"
- maybe_set "--dbdir-state" "$CTDB_DBDIR_STATE"
- maybe_set "--event-script-dir" "$CTDB_EVENT_SCRIPT_DIR"
- maybe_set "--transport" "$CTDB_TRANSPORT"
- maybe_set "-d" "$CTDB_DEBUGLEVEL"
- maybe_set "--notification-script" "$CTDB_NOTIFY_SCRIPT"
- maybe_set "--start-as-disabled" "$CTDB_START_AS_DISABLED" "yes"
- maybe_set "--start-as-stopped " "$CTDB_START_AS_STOPPED" "yes"
- maybe_set "--no-recmaster" "$CTDB_CAPABILITY_RECMASTER" "no"
- maybe_set "--no-lmaster" "$CTDB_CAPABILITY_LMASTER" "no"
- maybe_set "--lvs --single-public-ip" "$CTDB_LVS_PUBLIC_IP"
- maybe_set "--script-log-level" "$CTDB_SCRIPT_LOG_LEVEL"
- maybe_set "--max-persistent-check-errors" "$CTDB_MAX_PERSISTENT_CHECK_ERRORS"
-}
-
-export_debug_variables ()
-{
- [ -n "$CTDB_DEBUG_HUNG_SCRIPT" ] && export CTDB_DEBUG_HUNG_SCRIPT
- [ -n "$CTDB_EXTERNAL_TRACE" ] && export CTDB_EXTERNAL_TRACE
- [ -n "$CTDB_DEBUG_LOCKS" ] && export CTDB_DEBUG_LOCKS
-}
-
-kill_ctdbd ()
-{
- _session="$1"
-
- if [ -n "$_session" ] ; then
- pkill -9 -s "$_session" 2>/dev/null
- rm -f "$pidfile"
- fi
-}
-
-############################################################
-