3 ##############################
4 # ctdb: Starts the clustered tdb daemon
8 # description: Starts and stops the clustered tdb daemon
9 # pidfile: /var/run/ctdbd/ctdbd.pid
14 # Required-Start: $network
15 # Required-Stop: $network
18 # Short-Description: start and stop ctdb service
19 # Description: initscript for the ctdb service
22 # Source function library.
23 if [ -f /etc/init.d/functions ] ; then
24 . /etc/init.d/functions
25 elif [ -f /etc/rc.d/init.d/functions ] ; then
26 . /etc/rc.d/init.d/functions
29 [ -f /etc/rc.status ] && {
35 # Avoid using root's TMPDIR
38 [ -z "$CTDB_BASE" ] && {
39 export CTDB_BASE="/etc/ctdb"
42 . $CTDB_BASE/functions
46 # check networking is up (for redhat)
47 [ "$NETWORKING" = "no" ] && exit 0
50 export CTDB_INIT_STYLE
52 ctdbd=${CTDBD:-/usr/sbin/ctdbd}
54 if [ "$CTDB_VALGRIND" = "yes" ]; then
57 init_style="$CTDB_INIT_STYLE"
60 build_ctdb_options () {
61 [ -z "$CTDB_RECOVERY_LOCK" ] && {
62 echo "You must configure the location of the CTDB_RECOVERY_LOCK"
67 # If the 2nd arg is null then return - don't set anything.
68 # Else if the 3rd arg is set and it doesn't match the 2nd arg
70 [ -z "$2" -o \( -n "$3" -a "$3" != "$2" \) ] && return
77 # For these options we're only passing a value-less flag.
83 CTDB_OPTIONS="${CTDB_OPTIONS}${CTDB_OPTIONS:+ }${1}${sep}${val}"
86 maybe_set "--reclock" "$CTDB_RECOVERY_LOCK"
88 # build up CTDB_OPTIONS variable from optional parameters
89 maybe_set "--logfile" "$CTDB_LOGFILE"
90 maybe_set "--nlist" "$CTDB_NODES"
91 maybe_set "--socket" "$CTDB_SOCKET"
92 maybe_set "--public-addresses" "$CTDB_PUBLIC_ADDRESSES"
93 maybe_set "--public-interface" "$CTDB_PUBLIC_INTERFACE"
94 maybe_set "--dbdir" "$CTDB_DBDIR"
95 maybe_set "--dbdir-persistent" "$CTDB_DBDIR_PERSISTENT"
96 maybe_set "--event-script-dir" "$CTDB_EVENT_SCRIPT_DIR"
97 maybe_set "--transport" "$CTDB_TRANSPORT"
98 maybe_set "-d" "$CTDB_DEBUGLEVEL"
99 maybe_set "--notification-script" "$CTDB_NOTIFY_SCRIPT"
100 maybe_set "--start-as-disabled" "$CTDB_START_AS_DISABLED" "yes"
101 maybe_set "--no-recmaster" "$CTDB_CAPABILITY_RECMASTER" "no"
102 maybe_set "--no-lmaster" "$CTDB_CAPABILITY_LMASTER" "no"
103 maybe_set "--lvs --single-public-ip" "$CTDB_LVS_PUBLIC_IP"
104 maybe_set "--script-log-level" "$CTDB_SCRIPT_LOG_LEVEL"
107 check_persistent_databases () {
108 PERSISTENT_DB_DIR="${CTDB_DBDIR:-/var/ctdb}/persistent"
109 mkdir -p $PERSISTENT_DB_DIR 2>/dev/null
110 for PDBASE in `ls $PERSISTENT_DB_DIR/*.tdb.[0-9] 2>/dev/null`; do
111 /usr/bin/tdbdump $PDBASE >/dev/null 2>/dev/null || {
112 echo "Persistent database $PDBASE is corrupted! CTDB will not start."
118 set_ctdb_variables () {
119 # set any tunables from the config file
120 set | grep ^CTDB_SET_ | cut -d_ -f3- |
122 varname=`echo $v | cut -d= -f1`
123 value=`echo $v | cut -d= -f2`
124 ctdb setvar $varname $value || RETVAL=1
133 echo -n $"Starting ctdbd service: "
135 ctdb ping >/dev/null 2>&1 && {
136 echo $"CTDB is already running"
142 check_persistent_databases || return $?
146 valgrind -q --log-file=/var/log/ctdb_valgrind \
147 $ctdbd --nosetsched $CTDB_OPTIONS
152 startproc $ctdbd $CTDB_OPTIONS
157 daemon $ctdbd $CTDB_OPTIONS
160 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ctdb || RETVAL=1
163 start-stop-daemon --start --quiet --background \
164 --exec $ctdbd -- $CTDB_OPTIONS
177 echo -n $"Shutting down ctdbd service: "
178 pkill -0 -f $ctdbd || {
179 echo -n " Warning: ctdbd not running ! "
190 ctdb shutdown >/dev/null 2>&1
193 while pkill -0 -f $ctdbd ; do
195 count=$(($count + 1))
196 [ $count -gt 10 ] && {
197 echo -n $"killing ctdbd "
199 pkill -9 -f $CTDB_BASE/events.d/
204 # re-set the return code to the recorded RETVAL in order
205 # to print the correct status message
211 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb
224 echo -n $"Checking for ctdbd service: "
225 ctdb ping >/dev/null 2>&1 || {
227 echo -n " ctdbd not running. "
258 ctdb status > /dev/null && restart || :
261 # used from cron to auto-restart ctdb
262 ctdb status > /dev/null || restart
265 echo $"Usage: $0 {start|stop|restart|status|cron|condrestart}"