2013-07-09 09:22:07 +04:00
#!/bin/sh
# ctdbd wrapper - start or stop CTDB
usage ()
{
2018-03-05 13:02:40 +03:00
echo "usage: ctdbd_wrapper { start | stop }"
2013-07-09 09:22:07 +04:00
exit 1
}
2018-03-05 13:02:40 +03:00
[ $# -eq 1 ] || usage
2013-07-09 09:22:07 +04:00
2018-03-05 13:02:40 +03:00
action="$1"
2013-07-09 09:22:07 +04:00
############################################################
2015-08-17 13:47:58 +03:00
if [ -z "$CTDB_BASE" ] ; then
export CTDB_BASE="/usr/local/etc/ctdb"
fi
2013-07-09 09:22:07 +04:00
. "${CTDB_BASE}/functions"
2018-02-06 03:25:56 +03:00
2018-04-24 08:55:11 +03:00
load_system_config "ctdb"
2013-07-09 09:22:07 +04:00
2015-08-17 13:47:58 +03:00
ctdbd="${CTDBD:-/usr/local/sbin/ctdbd}"
2013-07-09 09:22:07 +04:00
############################################################
start()
{
2018-04-16 06:20:36 +03:00
eval "$ctdbd" || return 1
2013-07-09 09:22:07 +04:00
# Wait until ctdbd has started and is ready to respond to clients.
_timeout="${CTDB_STARTUP_TIMEOUT:-10}"
_count=0
2016-07-06 10:31:51 +03:00
while [ "$_count" -lt "$_timeout" ] ; do
2017-10-23 03:50:51 +03:00
if $CTDB runstate first_recovery startup running >/dev/null 2>&1 ; then
return 0
2013-07-09 09:22:07 +04:00
fi
2016-07-06 09:50:30 +03:00
_count=$((_count + 1))
2013-07-09 09:22:07 +04:00
sleep 1
done
2018-03-05 12:16:00 +03: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 09:22:07 +04:00
drop_all_public_ips >/dev/null 2>&1
return 1
}
stop()
{
2018-03-05 12:26:08 +03: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 06:04:04 +03:00
fi
2013-07-09 09:22:07 +04:00
2018-03-05 12:26:08 +03:00
return 0
2013-07-09 09:22:07 +04: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