1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-24 21:34:56 +03:00
samba-mirror/ctdb/config/ctdb.init
Martin Schwenke b499775527 ctdb-scripts: Split CTDB configuration loading
loadconfig() currently tries to load the CTDB configuration and also
any system configuration relevant to the current (event) script.

Instead add a new function load_system_config() to load the
distribution-specific system configuration for a component.  Call this
directly in the rare scripts that need the system configuration.

Also call load_system_config when loading the CTDB configuration to
pull in anything from the CTDB system configuration.  This is partly
for backward compatibility but also to get options that can be used
anywhere.

loadconfig() no longer takes an argument.  It simply loads the CTDB
configuration.

Drop support for falling back to /etc/ctdb/sysconfig/ctdb (or
similar).  Surely there's nobody who uses that!

Also, drop the indirection where loadconfig() calls _loadconfig().
This was used years ago as a test hook and is no longer required.

Inexplicably, this change introduces a new shellcheck test failure, so
silence this.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2018-03-28 02:57:20 +02:00

165 lines
3.2 KiB
Bash
Executable File

#!/bin/sh
# Start and stop CTDB (Clustered TDB daemon)
#
# chkconfig: - 90 01
#
# description: Starts and stops CTDB
# pidfile: /var/run/ctdb/ctdbd.pid
# config: /etc/sysconfig/ctdb
### BEGIN INIT INFO
# Provides: ctdb
# Required-Start: $local_fs $syslog $network $remote_fs
# Required-Stop: $local_fs $syslog $network $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop ctdb service
# Description: Start and stop CTDB (Clustered TDB daemon)
### END INIT INFO
# Source function library.
if [ -f /etc/init.d/functions ] ; then
# Red Hat
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
# Red Hat
. /etc/rc.d/init.d/functions
elif [ -f /etc/rc.status ] ; then
# SUSE
. /etc/rc.status
rc_reset
LC_ALL=en_US.UTF-8
elif [ -f /lib/lsb/init-functions ] ; then
# Debian
. /lib/lsb/init-functions
fi
# Avoid using root's TMPDIR
unset TMPDIR
[ -n "$CTDB_BASE" ] || export CTDB_BASE="/etc/ctdb"
. "${CTDB_BASE}/functions"
load_system_config "network"
# check networking is up (for redhat)
if [ "$NETWORKING" = "no" ] ; then
exit 0
fi
load_system_config "ctdb"
detect_init_style
export CTDB_INIT_STYLE
ctdbd="${CTDBD:-/usr/sbin/ctdbd}"
ctdbd_wrapper="${CTDBD_WRAPPER:-/usr/sbin/ctdbd_wrapper}"
pidfile="/var/run/ctdb/ctdbd.pid"
############################################################
start()
{
printf "Starting ctdbd service: "
case "$CTDB_INIT_STYLE" in
suse)
startproc \
"$ctdbd_wrapper" "start"
rc_status -v
;;
redhat)
daemon --pidfile "$pidfile" \
"$ctdbd_wrapper" "start"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/ctdb || RETVAL=1
return $RETVAL
;;
debian)
eval start-stop-daemon --start --quiet --background --exec \
"$ctdbd_wrapper" "start"
;;
esac
}
stop()
{
printf "Shutting down ctdbd service: "
case "$CTDB_INIT_STYLE" in
suse)
"$ctdbd_wrapper" "stop"
rc_status -v
;;
redhat)
"$ctdbd_wrapper" "stop"
RETVAL=$?
# Common idiom in Red Hat init scripts - success() always
# succeeds so this does behave like if-then-else
# shellcheck disable=SC2015
[ $RETVAL -eq 0 ] && success || failure
echo ""
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb
return $RETVAL
;;
debian)
"$ctdbd_wrapper" "stop"
log_end_msg $?
;;
esac
}
restart()
{
stop
start
}
check_status ()
{
case "$CTDB_INIT_STYLE" in
suse)
checkproc -p "$pidfile" "$ctdbd"
rc_status -v
;;
redhat)
status -p "$pidfile" -l "ctdb" "$ctdbd"
;;
debian)
status_of_proc -p "$pidfile" "$ctdbd" "ctdb"
;;
esac
}
############################################################
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload|force-reload)
restart
;;
status)
check_status
;;
condrestart|try-restart)
if check_status >/dev/null ; then
restart
fi
;;
cron)
# used from cron to auto-restart ctdb
check_status >/dev/null 2>&1 || restart
;;
*)
echo "Usage: $0 {start|stop|restart|reload|force-reload|status|cron|condrestart|try-restart}"
exit 1
esac