2013-07-09 15:22:07 +10:00
#!/bin/sh
# ctdbd wrapper - start or stop CTDB
usage ()
{
2018-03-05 21:02:40 +11:00
echo "usage: ctdbd_wrapper { start | stop }"
2013-07-09 15:22:07 +10:00
exit 1
}
2018-03-05 21:02:40 +11:00
[ $# -eq 1 ] || usage
2013-07-09 15:22:07 +10:00
2018-03-05 21:02:40 +11:00
action="$1"
2013-07-09 15:22:07 +10:00
############################################################
2015-08-17 20:47:58 +10:00
if [ -z "$CTDB_BASE" ] ; then
export CTDB_BASE="/usr/local/etc/ctdb"
fi
2013-07-09 15:22:07 +10:00
. "${CTDB_BASE}/functions"
2018-02-06 11:25:56 +11:00
2018-04-24 15:55:11 +10:00
load_system_config "ctdb"
2013-07-09 15:22:07 +10:00
2015-08-17 20:47:58 +10:00
ctdbd="${CTDBD:-/usr/local/sbin/ctdbd}"
2013-07-09 15:22:07 +10:00
############################################################
start()
{
2018-04-16 13:20:36 +10:00
eval "$ctdbd" || return 1
2013-07-09 15:22:07 +10:00
# Wait until ctdbd has started and is ready to respond to clients.
_timeout="${CTDB_STARTUP_TIMEOUT:-10}"
_count=0
2016-07-06 17:31:51 +10:00
while [ "$_count" -lt "$_timeout" ] ; do
2017-10-23 11:50:51 +11:00
if $CTDB runstate first_recovery startup running >/dev/null 2>&1 ; then
return 0
2013-07-09 15:22:07 +10:00
fi
2016-07-06 16:50:30 +10:00
_count=$((_count + 1))
2013-07-09 15:22:07 +10:00
sleep 1
done
2018-03-05 20:16:00 +11:00
echo "Timed out waiting for initialisation - check logs"
# Attempt a shutdown just in case things are still running
$CTDB shutdown >/dev/null 2>&1
2013-07-09 15:22:07 +10:00
drop_all_public_ips >/dev/null 2>&1
return 1
}
stop()
{
2018-03-05 20:26:08 +11:00
$CTDB shutdown
# The above command is important and needs to stand out, so
# post-check exit status
# shellcheck disable=SC2181
if [ $? -ne 0 ] ; then
echo "Error while shutting down CTDB"
drop_all_public_ips >/dev/null 2>&1
return 1
2015-10-23 14:04:04 +11:00
fi
2013-07-09 15:22:07 +10:00
2018-03-05 20:26:08 +11:00
return 0
2013-07-09 15:22:07 +10:00
}
############################################################
# Allow notifications for start/stop.
if [ -x "$CTDB_BASE/rc.ctdb" ] ; then
"$CTDB_BASE/rc.ctdb" "$action"
fi
case "$action" in
start) start ;;
stop) stop ;;
*)
echo "usage: $0 {start|stop}"
exit 1
esac