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 [ -z "$CTDB_RECOVERY_LOCK" ] && {
47 echo "No recovery lock specified. Starting CTDB without split brain prevention"
50 # check networking is up (for redhat)
51 [ "$NETWORKING" = "no" ] && exit 0
54 export CTDB_INIT_STYLE
56 ctdbd=${CTDBD:-/usr/sbin/ctdbd}
58 if [ "$CTDB_VALGRIND" = "yes" ]; then
61 init_style="$CTDB_INIT_STYLE"
64 build_ctdb_options () {
65 [ -z "$CTDB_RECOVERY_LOCK" ] && {
66 echo "You must configure the location of the CTDB_RECOVERY_LOCK"
71 # If the 2nd arg is null then return - don't set anything.
72 # Else if the 3rd arg is set and it doesn't match the 2nd arg
74 [ -z "$2" -o \( -n "$3" -a "$3" != "$2" \) ] && return
81 # For these options we're only passing a value-less flag.
87 CTDB_OPTIONS="${CTDB_OPTIONS}${CTDB_OPTIONS:+ }${1}${sep}${val}"
90 maybe_set "--reclock" "$CTDB_RECOVERY_LOCK"
92 # build up CTDB_OPTIONS variable from optional parameters
93 maybe_set "--logfile" "$CTDB_LOGFILE"
94 maybe_set "--nlist" "$CTDB_NODES"
95 maybe_set "--socket" "$CTDB_SOCKET"
96 maybe_set "--public-addresses" "$CTDB_PUBLIC_ADDRESSES"
97 maybe_set "--public-interface" "$CTDB_PUBLIC_INTERFACE"
98 maybe_set "--dbdir" "$CTDB_DBDIR"
99 maybe_set "--dbdir-persistent" "$CTDB_DBDIR_PERSISTENT"
100 maybe_set "--event-script-dir" "$CTDB_EVENT_SCRIPT_DIR"
101 maybe_set "--transport" "$CTDB_TRANSPORT"
102 maybe_set "-d" "$CTDB_DEBUGLEVEL"
103 maybe_set "--notification-script" "$CTDB_NOTIFY_SCRIPT"
104 maybe_set "--start-as-disabled" "$CTDB_START_AS_DISABLED" "yes"
105 maybe_set "--no-recmaster" "$CTDB_CAPABILITY_RECMASTER" "no"
106 maybe_set "--no-lmaster" "$CTDB_CAPABILITY_LMASTER" "no"
107 maybe_set "--lvs --single-public-ip" "$CTDB_LVS_PUBLIC_IP"
108 maybe_set "--script-log-level" "$CTDB_SCRIPT_LOG_LEVEL"
111 check_persistent_databases () {
112 PERSISTENT_DB_DIR="${CTDB_DBDIR:-/var/ctdb}/persistent"
113 mkdir -p $PERSISTENT_DB_DIR 2>/dev/null
114 for PDBASE in `ls $PERSISTENT_DB_DIR/*.tdb.[0-9] 2>/dev/null`; do
115 /usr/bin/tdbdump $PDBASE >/dev/null 2>/dev/null || {
116 echo "Persistent database $PDBASE is corrupted! CTDB will not start."
122 set_ctdb_variables () {
123 # set any tunables from the config file
124 set | grep ^CTDB_SET_ | cut -d_ -f3- |
126 varname=`echo $v | cut -d= -f1`
127 value=`echo $v | cut -d= -f2`
128 ctdb setvar $varname $value || RETVAL=1
136 ctdbd=${CTDBD:-/usr/sbin/ctdbd}
139 echo -n $"Starting ctdbd service: "
141 ctdb ping >/dev/null 2>&1 && {
142 echo $"CTDB is already running"
148 check_persistent_databases || return $?
152 valgrind -q --log-file=/var/log/ctdb_valgrind \
153 $ctdbd --nosetsched $CTDB_OPTIONS
158 startproc $ctdbd $CTDB_OPTIONS
163 daemon $ctdbd $CTDB_OPTIONS
166 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ctdb || RETVAL=1
169 start-stop-daemon --start --quiet --background \
170 --exec $ctdbd -- $CTDB_OPTIONS
183 echo -n $"Shutting down ctdbd service: "
184 pkill -0 -f $ctdbd || {
185 echo -n " Warning: ctdbd not running ! "
196 ctdb shutdown >/dev/null 2>&1
199 while pkill -0 -f $ctdbd ; do
201 count=$(($count + 1))
202 [ $count -gt 10 ] && {
203 echo -n $"killing ctdbd "
205 pkill -9 -f $CTDB_BASE/events.d/
210 # re-set the return code to the recorded RETVAL in order
211 # to print the correct status message
217 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb
230 echo -n $"Checking for ctdbd service: "
231 ctdb ping >/dev/null 2>&1 || {
233 echo -n " ctdbd not running. "
264 ctdb status > /dev/null && restart || :
267 # used from cron to auto-restart ctdb
268 ctdb status > /dev/null || restart
271 echo $"Usage: $0 {start|stop|restart|status|cron|condrestart}"