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 [ -z "$CTDB_VARDIR" ] && {
43 export CTDB_VARDIR="/var/ctdb"
46 . $CTDB_BASE/functions
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 () {
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 [ -z "$CTDB_RECOVERY_LOCK" ] && {
87 echo "No recovery lock specified. Starting CTDB without split brain prevention"
89 maybe_set "--reclock" "$CTDB_RECOVERY_LOCK"
91 # build up CTDB_OPTIONS variable from optional parameters
92 maybe_set "--logfile" "$CTDB_LOGFILE"
93 maybe_set "--nlist" "$CTDB_NODES"
94 maybe_set "--socket" "$CTDB_SOCKET"
95 maybe_set "--public-addresses" "$CTDB_PUBLIC_ADDRESSES"
96 maybe_set "--public-interface" "$CTDB_PUBLIC_INTERFACE"
97 maybe_set "--dbdir" "$CTDB_DBDIR"
98 maybe_set "--dbdir-persistent" "$CTDB_DBDIR_PERSISTENT"
99 maybe_set "--event-script-dir" "$CTDB_EVENT_SCRIPT_DIR"
100 maybe_set "--transport" "$CTDB_TRANSPORT"
101 maybe_set "-d" "$CTDB_DEBUGLEVEL"
102 maybe_set "--notification-script" "$CTDB_NOTIFY_SCRIPT"
103 maybe_set "--start-as-disabled" "$CTDB_START_AS_DISABLED" "yes"
104 maybe_set "--start-as-stopped " "$CTDB_START_AS_STOPPED" "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"
109 maybe_set "--log-ringbuf-size" "$CTDB_LOG_RINGBUF_SIZE"
110 maybe_set "--syslog" "$CTDB_SYSLOG" "yes"
111 maybe_set "--max-persistent-check-errors" "$CTDB_MAX_PERSISTENT_CHECK_ERRORS"
117 local TDBTOOL_HAS_CHECK=`echo "help" | /usr/bin/tdbtool | grep check | wc -l`
119 test x"$TDBTOOL_HAS_CHECK" = x"1" && {
121 # Note tdbtool always exits with 0
123 local OK=`/usr/bin/tdbtool $PDBASE check | grep "Database integrity is OK" | wc -l`
124 test x"$OK" = x"1" || {
131 /usr/bin/tdbdump $PDBASE >/dev/null 2>/dev/null || {
138 check_persistent_databases () {
139 PERSISTENT_DB_DIR="${CTDB_DBDIR:-/var/ctdb}/persistent"
140 mkdir -p $PERSISTENT_DB_DIR 2>/dev/null
141 local ERRCOUNT=$CTDB_MAX_PERSISTENT_CHECK_ERRORS
143 test -z "$ERRCOUNT" && {
146 test x"$ERRCOUNT" != x"0" && {
149 for PDBASE in `ls $PERSISTENT_DB_DIR/*.tdb.[0-9] 2>/dev/null`; do
150 check_tdb $PDBASE || {
151 echo "Persistent database $PDBASE is corrupted! CTDB will not start."
157 set_ctdb_variables () {
158 # set any tunables from the config file
159 set | grep ^CTDB_SET_ | cut -d_ -f3- |
161 varname=`echo $v | cut -d= -f1`
162 value=`echo $v | cut -d= -f2`
163 ctdb setvar $varname $value || RETVAL=1
171 wait_until_ready () {
172 _timeout="${1:-10}" # default is 10 seconds
175 while ! ctdb ping >/dev/null 2>&1 ; do
176 if [ $_count -ge $_timeout ] ; then
180 _count=$(($_count + 1))
184 ctdbd=${CTDBD:-/usr/sbin/ctdbd}
187 echo -n $"Starting ctdbd service: "
189 ctdb ping >/dev/null 2>&1 && {
190 echo $"CTDB is already running"
196 check_persistent_databases || return $?
198 if [ "$CTDB_SUPPRESS_COREFILE" = "yes" ]; then
206 eval valgrind -q --log-file=/var/log/ctdb_valgrind \
207 $ctdbd --valgrinding "$CTDB_OPTIONS"
212 eval startproc $ctdbd "$CTDB_OPTIONS"
216 eval $ctdbd "$CTDB_OPTIONS"
218 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ctdb || RETVAL=1
221 eval start-stop-daemon --start --quiet --background \
222 --exec $ctdbd -- "$CTDB_OPTIONS"
227 if [ $RETVAL -eq 0 ] ; then
228 if wait_until_ready ; then
232 pkill -9 -f $ctdbd >/dev/null 2>&1
242 [ $RETVAL -eq 0 ] && success || failure
251 echo -n $"Shutting down ctdbd service: "
252 pkill -0 -f $ctdbd || {
253 echo -n " Warning: ctdbd not running ! "
264 ctdb shutdown >/dev/null 2>&1
267 while pkill -0 -f $ctdbd ; do
269 count=$(($count + 1))
270 [ $count -gt 10 ] && {
271 echo -n $"killing ctdbd "
273 pkill -9 -f $CTDB_BASE/events.d/
278 # re-set the return code to the recorded RETVAL in order
279 # to print the correct status message
284 [ $RETVAL -eq 0 ] && success || failure
285 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb
298 echo -n $"Checking for ctdbd service: "
299 ctdb ping >/dev/null 2>&1 || {
301 echo -n " ctdbd not running. "
308 if [ -f /var/lock/subsys/ctdb ]; then
309 echo $"ctdb dead but subsys locked"
312 echo $"ctdb is stopped"
331 restart|reload|force-reload)
337 condrestart|try-restart)
338 ctdb status > /dev/null && restart || :
341 # used from cron to auto-restart ctdb
342 ctdb status > /dev/null || restart
345 echo $"Usage: $0 {start|stop|restart|reload|force-reload|status|cron|condrestart|try-restart}"