summaryrefslogtreecommitdiffstats
path: root/ctdb/config/ctdb.init
blob: c83c091a73a023cf1e7a73726a622c96d602bfc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/sh
#
##############################
# init info for redhat distros
# chkconfig: - 90 36
# description: Starts and stops the clustered tdb daemon
# pidfile: /var/run/ctdbd/ctdbd.pid
##############################

##############################
# SLES/OpenSuSE init info
### BEGIN INIT INFO
# Provides:       ctdb
# Required-Start: $network
# Required-Stop:
# Default-Start:  3 5
# Default-Stop:
# Description:    initscript for the ctdb service
### END INIT INFO

# Source function library.
if [ -f /etc/init.d/functions ] ; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
  . /etc/rc.d/init.d/functions
fi

[ -f /etc/rc.status ] && {
    . /etc/rc.status
    rc_reset
    LC_ALL=en_US.UTF-8
}

# Avoid using root's TMPDIR
unset TMPDIR

[ -z "$CTDB_BASE" ] && {
    export CTDB_BASE="/etc/ctdb"
}

. $CTDB_BASE/functions
loadconfig network
loadconfig ctdb

# check networking is up (for redhat)
[ "${NETWORKING}" = "no" ] && exit 0

[ -z "$CTDB_RECOVERY_LOCK" ] && {
    echo "You must configure the location of the CTDB_RECOVERY_LOCK"
    exit 1
}
CTDB_OPTIONS="$CTDB_OPTIONS --reclock=$CTDB_RECOVERY_LOCK"

# build up CTDB_OPTIONS variable from optional parameters
[ -z "$CTDB_LOGFILE" ]          || CTDB_OPTIONS="$CTDB_OPTIONS --logfile=$CTDB_LOGFILE"
[ -z "$CTDB_NODES" ]            || CTDB_OPTIONS="$CTDB_OPTIONS --nlist=$CTDB_NODES"
[ -z "$CTDB_SOCKET" ]           || CTDB_OPTIONS="$CTDB_OPTIONS --socket=$CTDB_SOCKET"
[ -z "$CTDB_PUBLIC_ADDRESSES" ] || CTDB_OPTIONS="$CTDB_OPTIONS --public-addresses=$CTDB_PUBLIC_ADDRESSES"
[ -z "$CTDB_PUBLIC_INTERFACE" ] || CTDB_OPTIONS="$CTDB_OPTIONS --public-interface=$CTDB_PUBLIC_INTERFACE"
[ -z "$CTDB_SINGLE_PUBLIC_IP" ] || CTDB_OPTIONS="$CTDB_OPTIONS --single-public-ip=$CTDB_SINGLE_PUBLIC_IP"
[ -z "$CTDB_DBDIR" ]            || CTDB_OPTIONS="$CTDB_OPTIONS --dbdir=$CTDB_DBDIR"
[ -z "$CTDB_DBDIR_PERSISTENT" ] || CTDB_OPTIONS="$CTDB_OPTIONS --dbdir-persistent=$CTDB_DBDIR_PERSISTENT"
[ -z "$CTDB_EVENT_SCRIPT_DIR" ] || CTDB_OPTIONS="$CTDB_OPTIONS --event-script-dir $CTDB_EVENT_SCRIPT_DIR"
[ -z "$CTDB_TRANSPORT" ]        || CTDB_OPTIONS="$CTDB_OPTIONS --transport $CTDB_TRANSPORT"
[ -z "$CTDB_DEBUGLEVEL" ]       || CTDB_OPTIONS="$CTDB_OPTIONS -d $CTDB_DEBUGLEVEL"
[ -z "$CTDB_START_AS_DISABLED" ] || [ "$CTDB_START_AS_DISABLED" != "yes" ] || {
	CTDB_OPTIONS="$CTDB_OPTIONS --start-as-disabled"
}
[ -z "$CTDB_CAPABILITY_RECMASTER" ] || [ "$CTDB_CAPABILITY_RECMASTER" != "yes" ] || {
	CTDB_OPTIONS="$CTDB_OPTIONS --no-recmaster"
}
[ -z "$CTDB_CAPABILITY_LMASTER" ] || [ "$CTDB_CAPABILITY_LMASTER" != "yes" ] || {
	CTDB_OPTIONS="$CTDB_OPTIONS --no-lmaster"
}

if [ -x /sbin/startproc ]; then
    init_style="suse"
else if [ -x /sbin/start-stop-daemon ]; then
	init_style="ubuntu"
    else
	init_style="redhat"
    fi
fi

start() {
        killall -q ctdbd
	echo -n $"Starting ctdbd service: "
	case $init_style in
	    suse)
		startproc /usr/sbin/ctdbd $CTDB_OPTIONS
		rc_status -v
		RETVAL=$?
		;;
	    redhat)
		daemon ctdbd $CTDB_OPTIONS
		RETVAL=$?
		echo
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/ctdb || RETVAL=1
		;;
	    ubuntu)
		start-stop-daemon --start --quiet --background --exec /usr/sbin/ctdbd -- $CTDB_OPTIONS
		RETVAL=$?
		;;
	esac

	sleep 1
	# set any tunables from the config file
	set | grep ^CTDB_SET_ | cut -d_ -f3- | 
	while read v; do
	    varname=`echo $v | cut -d= -f1`
	    value=`echo $v | cut -d= -f2`
	    ctdb setvar $varname $value || RETVAL=1
	done || exit 1

	return $RETVAL
}	

stop() {
	echo -n $"Shutting down ctdbd service: "
	ctdb shutdown
	RETVAL=$?
	count=0
	while killall -q -0 ctdbd; do
	    sleep 1
	    count=`expr $count + 1`
	    [ $count -gt 10 ] && {
		echo -n $"killing ctdbd "
		killall -q -9 ctdbd
		pkill -9 -f $CTDB_BASE/events.d/
	    }
	done
	case $init_style in
	    suse)
		rc_status -v
		;;
	    redhat)
		echo
		[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb
		echo ""
		return $RETVAL
		;;
	esac
}	

restart() {
	stop
	start
}	

status() {
	ctdb status
}	


case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
  	restart
	;;
  status)
  	status
	;;
  condrestart)
  	ctdb status > /dev/null && restart || :
	;;
  cron)
	# used from cron to auto-restart ctdb
  	ctdb status > /dev/null || restart
	;;
  *)
	echo $"Usage: $0 {start|stop|restart|status|cron|condrestart}"
	exit 1
esac

exit $?