2
# init fragment for O2CB.
4
# chkconfig: 2345 24 20
5
# description: Load O2CB cluster services at system boot.
9
# Required-Start: $network
12
# Default-Start: 2 3 5
14
# Short-Description: Load O2CB cluster services at system boot.
15
# Description: Load O2CB cluster services at system boot.
21
CLUSTERCONF=/etc/ocfs2/cluster.conf
23
if [ -f /etc/sysconfig/o2cb ]
26
CONFIGURATION=/etc/sysconfig/o2cb
27
elif [ -f /etc/default/o2cb ]
30
CONFIGURATION=/etc/default/o2cb
32
elif [ -d /etc/sysconfig ]
34
CONFIGURATION=/etc/sysconfig/o2cb
36
CONFIGURATION=/etc/default/o2cb
39
# The default values should always be in sync with the kernel
40
DEF_HEARTBEAT_THRESHOLD=31
41
DEF_IDLE_TIMEOUT_MS=30000
42
DEF_KEEPALIVE_DELAY_MS=2000
43
DEF_RECONNECT_DELAY_MS=2000
45
# Minimum timeout values
46
MIN_HEARTBEAT_THRESHOLD=7
47
MIN_IDLE_TIMEOUT_MS=5000
48
MIN_KEEPALIVE_DELAY_MS=1000
49
MIN_RECONNECT_DELAY_MS=2000
51
# Source configuration,
52
[ -f "${CONFIGURATION}" ] && . "${CONFIGURATION}"
56
# Note that this is only valid *after* configfs is loaded
57
if [ -d /sys/kernel/config ]
59
echo /sys/kernel/config
66
# This is a tricky bit of eval work. There are many steps involved in
67
# O2CB startup/shutdown, so we collect them here. Each line is a line
68
# of shell code that needs to be run. The code is run via eval as
72
# Eval of the exact lines, in order. So, the first call is
73
# "eval load_module configfs".
76
# Eval of the lines with "check_" prepended, in order. So the first
77
# call is "eval check_load_module configfs".
80
# Eval of the lines with "un" prepened, in reverse order. So the
81
# *last* call is "eval unload_module configfs".
83
# To provide an action, create a set of shell functions or commands
84
# "foo", "check_foo", and "unfoo". Then add "foo arguments" to the
85
# appropriate place. Be careful, eval requires quoting to be right.
87
LOAD_ACTIONS=("load_module configfs"
88
"mount_fs configfs "'$(configfs_path)'
89
"load_module ocfs2_nodemanager"
90
"load_module ocfs2_dlm"
91
"load_module ocfs2_dlmfs"
92
"load_module ocfs2_stackglue"
93
"mount_fs ocfs2_dlmfs /dlm")
99
# Evaluates return codes. If 0, prints "OK", if 1, prints "Failed"
100
# and exits. If 2, status is "already done" and nothing is printed.
101
# The rest of the functions in here all honor this convention.
116
if [ -n "${REASON}" ]
127
# Writes the system configuration out
131
echo -n "Writing O2CB configuration: "
132
cat >"${CONFIGURATION}" <<EOF
134
# This is a configuration file for automatic startup of the O2CB
135
# driver. It is generated by running /etc/init.d/o2cb configure.
136
# On Debian based systems the preferred method is running
137
# 'dpkg-reconfigure ocfs2-tools'.
140
# O2CB_ENABLED: 'true' means to load the driver on boot.
141
O2CB_ENABLED=${O2CB_ENABLED:-false}
143
# O2CB_BOOTCLUSTER: If not empty, the name of a cluster to start.
144
O2CB_BOOTCLUSTER=${O2CB_BOOTCLUSTER}
146
# O2CB_HEARTBEAT_THRESHOLD: Iterations before a node is considered dead.
147
O2CB_HEARTBEAT_THRESHOLD=${O2CB_HEARTBEAT_THRESHOLD}
149
# O2CB_IDLE_TIMEOUT_MS: Time in ms before a network connection is considered dead.
150
O2CB_IDLE_TIMEOUT_MS=${O2CB_IDLE_TIMEOUT_MS}
152
# O2CB_KEEPALIVE_DELAY_MS: Max time in ms before a keepalive packet is sent
153
O2CB_KEEPALIVE_DELAY_MS=${O2CB_KEEPALIVE_DELAY_MS}
155
# O2CB_RECONNECT_DELAY_MS: Min time in ms between connection attempts
156
O2CB_RECONNECT_DELAY_MS=${O2CB_RECONNECT_DELAY_MS}
169
# Returns timeout value provided by user to caller in RET_VAL
173
if [ "$#" -lt "4" ]; then
174
echo "read_timeout(): Requires more arguments" >&2
186
if [ -z $ATTRIB_VAL ]; then
191
echo -n "Specify ${ATTRIB_NAME} (>=$MIN_ATTRIB_VAL) [$CUR]: "
195
RET_VAL="$ATTRIB_VAL"
200
echo "Invalid ${ATTRIB_NAME} value: $LINE" >&2
203
if [ $LINE -lt $MIN_ATTRIB_VAL ]; then
204
echo "${ATTRIB_NAME} cannot be less than $MIN_ATTRIB_VAL" >&2
216
O2CB_HEARTBEAT_THRESHOLD_FILE_OLD=/proc/fs/ocfs2_nodemanager/hb_dead_threshold
217
O2CB_HEARTBEAT_THRESHOLD_FILE=$(configfs_path)/cluster/${CLUSTER}/heartbeat/dead_threshold
218
if [ -n "$O2CB_HEARTBEAT_THRESHOLD" ]; then
219
if [ -f "$O2CB_HEARTBEAT_THRESHOLD_FILE" ]; then
220
echo "$O2CB_HEARTBEAT_THRESHOLD" > "$O2CB_HEARTBEAT_THRESHOLD_FILE"
221
elif [ -f "$O2CB_HEARTBEAT_THRESHOLD_FILE_OLD" ]; then
222
echo "$O2CB_HEARTBEAT_THRESHOLD" > "$O2CB_HEARTBEAT_THRESHOLD_FILE_OLD"
226
O2CB_IDLE_TIMEOUT_MS_FILE=$(configfs_path)/cluster/${CLUSTER}/idle_timeout_ms
227
if [ -n "$O2CB_IDLE_TIMEOUT_MS" ]; then
228
if [ -f "$O2CB_IDLE_TIMEOUT_MS_FILE" ]; then
229
echo "$O2CB_IDLE_TIMEOUT_MS" > "$O2CB_IDLE_TIMEOUT_MS_FILE"
233
O2CB_KEEPALIVE_DELAY_MS_FILE=$(configfs_path)/cluster/${CLUSTER}/keepalive_delay_ms
234
if [ -n "$O2CB_KEEPALIVE_DELAY_MS" ]; then
235
if [ -f "$O2CB_KEEPALIVE_DELAY_MS_FILE" ]; then
236
echo "$O2CB_KEEPALIVE_DELAY_MS" > "$O2CB_KEEPALIVE_DELAY_MS_FILE"
240
O2CB_RECONNECT_DELAY_MS_FILE=$(configfs_path)/cluster/${CLUSTER}/reconnect_delay_ms
241
if [ -n "$O2CB_RECONNECT_DELAY_MS" ]; then
242
if [ -f "$O2CB_RECONNECT_DELAY_MS_FILE" ]; then
243
echo "$O2CB_RECONNECT_DELAY_MS" > "$O2CB_RECONNECT_DELAY_MS_FILE"
251
O2CB_HEARTBEAT_THRESHOLD_FILE_OLD=/proc/fs/ocfs2_nodemanager/hb_dead_threshold
252
O2CB_HEARTBEAT_THRESHOLD_FILE=$(configfs_path)/cluster/${CLUSTER}/heartbeat/dead_threshold
253
if [ -f "$O2CB_HEARTBEAT_THRESHOLD_FILE" ]; then
254
VAL=`cat "$O2CB_HEARTBEAT_THRESHOLD_FILE"`
255
echo "Heartbeat dead threshold = ${VAL}"
256
elif [ -f "$O2CB_HEARTBEAT_THRESHOLD_FILE_OLD" ]; then
257
VAL=`cat "$O2CB_HEARTBEAT_THRESHOLD_FILE_OLD"`
258
echo " Heartbeat dead threshold: ${VAL}"
261
O2CB_IDLE_TIMEOUT_MS_FILE=$(configfs_path)/cluster/${CLUSTER}/idle_timeout_ms
262
if [ -f "$O2CB_IDLE_TIMEOUT_MS_FILE" ]; then
263
VAL=`cat "$O2CB_IDLE_TIMEOUT_MS_FILE"`
264
echo " Network idle timeout: ${VAL}"
267
O2CB_KEEPALIVE_DELAY_MS_FILE=$(configfs_path)/cluster/${CLUSTER}/keepalive_delay_ms
268
if [ -f "$O2CB_KEEPALIVE_DELAY_MS_FILE" ]; then
269
VAL=`cat "$O2CB_KEEPALIVE_DELAY_MS_FILE"`
270
echo " Network keepalive delay: ${VAL}"
273
O2CB_RECONNECT_DELAY_MS_FILE=$(configfs_path)/cluster/${CLUSTER}/reconnect_delay_ms
274
if [ -f "$O2CB_RECONNECT_DELAY_MS_FILE" ]; then
275
VAL=`cat "$O2CB_RECONNECT_DELAY_MS_FILE"`
276
echo " Network reconnect delay: ${VAL}"
283
# Ask configuration questions, setting the shell vars.
287
if [ -n "$DPKGRECONF" ]; then
289
Configuring the O2CB driver.
291
Please configure this service in the Debian way:
293
dpkg-reconfigure ocfs2-tools
300
Configuring the O2CB driver.
302
This will configure the on-boot properties of the O2CB driver.
303
The following questions will determine whether the driver is loaded on
304
boot. The current values will be shown in brackets ('[]'). Hitting
305
<ENTER> without typing an answer will keep that current value. Ctrl-C
312
if [ "$O2CB_ENABLED" = "true" ]
318
echo -n "Load O2CB driver on boot (y/n) [$CUR]: "
333
echo "Invalid answer: $LINE" >&2
340
echo -n "Cluster to start on boot (Enter \"none\" to clear) [$O2CB_BOOTCLUSTER]: "
352
echo "Invalid cluster name: $LINE" >&2
355
O2CB_BOOTCLUSTER="$LINE"
361
read_timeout "heartbeat dead threshold" "$O2CB_HEARTBEAT_THRESHOLD" "$MIN_HEARTBEAT_THRESHOLD" "$DEF_HEARTBEAT_THRESHOLD"
362
O2CB_HEARTBEAT_THRESHOLD="$RET_VAL"
364
read_timeout "network idle timeout in ms" "$O2CB_IDLE_TIMEOUT_MS" "$MIN_IDLE_TIMEOUT_MS" "$DEF_IDLE_TIMEOUT_MS"
365
O2CB_IDLE_TIMEOUT_MS="$RET_VAL"
367
read_timeout "network keepalive delay in ms" "$O2CB_KEEPALIVE_DELAY_MS" "$MIN_KEEPALIVE_DELAY_MS" "$DEF_KEEPALIVE_DELAY_MS"
368
O2CB_KEEPALIVE_DELAY_MS="$RET_VAL"
370
read_timeout "network reconnect delay in ms" "$O2CB_RECONNECT_DELAY_MS" "$MIN_RECONNECT_DELAY_MS" "$DEF_RECONNECT_DELAY_MS"
371
O2CB_RECONNECT_DELAY_MS="$RET_VAL"
373
# XXX ask about mount point base
381
# Returns 0 on success, 1 on error, 2 if it already exists.
385
if [ "$#" -lt "1" -o -z "$1" ]
387
echo "make_dir(): Requires an argument" >&2
397
echo "make_dir(): File $DIR is not a directory" >&2
401
echo -n "Creating directory '$DIR': "
402
mkdir -p "$DIR" 2>/dev/null
405
echo "Unable to create directory '$DIR'" >&2
416
# 0 is success, 1 is error, 2 is already loaded
420
if [ "$#" -lt "1" -o -z "$1" ]
422
echo "load_module(): Requires an argument" >&2
427
MODOUT="`awk '$1 ~ /^'$MODNAME'$/{print $1;exit}' < /proc/modules 2>/dev/null`"
433
echo -n "Loading module \"$MODNAME\": "
434
modprobe -s "$MODNAME"
437
echo "Unable to load module \"$MODNAME\"" >&2
447
# 0 is hb not active, 1 is error, 2 is hb active
451
if [ "$#" -lt "1" -o -z "$1" ]
453
echo "check_heartbeat(): Requires an argument" >&2
459
if [ -d "$(configfs_path)/cluster/${CLUSTER}/heartbeat/" ]
461
ls -1 "$(configfs_path)/cluster/${CLUSTER}/heartbeat/" | while read HBUUID
463
if [ -d "$(configfs_path)/cluster/${CLUSTER}/heartbeat/${HBUUID}" ]
479
# Removes the inactive heartbeat regions
483
if [ "$#" -lt "1" -o -z "$1" ]
485
echo "clean_heartbeat(): Requires an argument" >&2
490
if [ ! -f "$(configfs_path)/cluster/${CLUSTER}/heartbeat/*" ]
495
echo -n "Cleaning heartbeat on ${CLUSTER}: "
497
ls -1 "$(configfs_path)/cluster/${CLUSTER}/heartbeat/" | while read HBUUID
499
if [ ! -d "$(configfs_path)/cluster/${CLUSTER}/heartbeat/${HBUUID}" ]
504
OUTPUT="`ocfs2_hb_ctl -I -u ${HBUUID} 2>&1`"
512
REF="`echo ${OUTPUT} | awk '/refs/ {print $2; exit;}' 2>&1`"
516
echo "At least one heartbeat region still active" >&2
519
OUTPUT="`ocfs2_hb_ctl -K -u ${HBUUID} 2>&1`"
531
# Force cleans configured cluster
533
# 0 is clean, 1 is error, 2 is not clean
537
if [ "$#" -lt "1" -o -z "$1" ]
539
echo "clean_cluster(): Requires an argument" >&2
544
if [ -d "$(configfs_path)/cluster/${CLUSTER}/node/" ]
546
ls -1 "$(configfs_path)/cluster/${CLUSTER}/node/" | while read NODE
548
rmdir "$(configfs_path)/cluster/${CLUSTER}/node/${NODE}" >/dev/null 2>&1
552
if [ -d "$(configfs_path)/cluster/${CLUSTER}" ]
554
rmdir "$(configfs_path)/cluster/${CLUSTER}" >/dev/null 2>&1
557
if [ -d "$(configfs_path)/cluster/${CLUSTER}" ]
569
# 0 is success, 1 is error, 2 is not loaded
573
if [ "$#" -lt "1" -o -z "$1" ]
575
echo "unload_module(): Requires an argument" >&2
580
MODOUT="`awk '$1 ~ /^'$MODNAME'$/{print $1,$3;exit}' < /proc/modules 2>/dev/null`"
592
echo -n "Invalid module parsing! "
597
echo -n "Unloading module \"$MODNAME\": "
598
modprobe -rs "$MODNAME"
601
echo "Unable to unload module \"$MODNAME\"" >&2
609
# check_load_module()
611
# 0 is not loaded, 1 is error, 2 is already loaded
615
if [ "$#" -lt "1" -o -z "$1" ]
617
echo "check_load_module(): Requires an argument" >&2
622
echo -n "Module \"$MODNAME\": "
623
MODOUT="`awk '$1 ~ /^'$MODNAME'$/{print $1,$3;exit}' < /proc/modules 2>/dev/null`"
636
# Mount a filesystem.
638
# 0 is success, 1 is error, 2 is already mounted
644
FULL_MOUNTSEARCH="`echo "$FULL_MOUNT" | sed -e 's/\//\\\\\//g'`"
645
MOUNTOUT="`awk '$2 ~ /^'$FULL_MOUNTSEARCH'$/{print $2; exit}' < /proc/mounts 2>/dev/null`"
647
if [ -n "$MOUNTOUT" ]
653
if [ ! -e "$FULL_MOUNT" ]; then
658
echo -n "Mounting ${TYPE} filesystem at $FULL_MOUNT: "
659
mount -t ${TYPE} ${TYPE} $FULL_MOUNT
662
echo "Unable to mount ${TYPE} filesystem" >&2
672
# 0 is not mounted, 1 is error, 2 is already mounted
678
FULL_MOUNTSEARCH="`echo "$FULL_MOUNT" | sed -e 's/\//\\\\\//g'`"
679
MOUNTOUT="`awk '$2 ~ /^'$FULL_MOUNTSEARCH'$/{print $2; exit}' < /proc/mounts 2>/dev/null`"
681
echo -n "Filesystem \"$TYPE\": "
682
if [ -n "$MOUNTOUT" ]
693
# Unmount a filesystem
695
# 0 is success, 1 is error, 2 is not mounted
701
FULL_MOUNTSEARCH="`echo "$FULL_MOUNT" | sed -e 's/\//\\\\\//g'`"
702
MOUNTOUT="`awk '$2 ~ /^'$FULL_MOUNTSEARCH'$/{print $2; exit}' < /proc/mounts 2>/dev/null`"
704
if [ -z "$MOUNTOUT" ]
709
echo -n "Unmounting ${TYPE} filesystem: "
713
echo "Unable to unmount ${TYPE} filesystem" >&2
722
for i in $(seq 0 $((${#LOAD_ACTIONS[*]} - 1)) ); do
723
eval ${LOAD_ACTIONS[i]}
730
for i in $(seq 0 $((${#LOAD_ACTIONS[*]} - 1)) ); do
731
eval "check_${LOAD_ACTIONS[i]}"
738
CLUSTER="${1:-${O2CB_BOOTCLUSTER}}"
741
echo "O2CB cluster not known"
745
check_online $CLUSTER
748
echo "O2CB cluster ${CLUSTER} already online"
752
if ! [ -f ${CLUSTERCONF} ]
754
echo -n "Checking O2CB cluster configuration : "
758
echo -n "Starting O2CB cluster ${CLUSTER}: "
759
OUTPUT="`o2cb_ctl -H -n "${CLUSTER}" -t cluster -a online=yes 2>&1`"
770
echo -n "Stopping O2CB cluster ${CLUSTER}: "
771
OUTPUT="`o2cb_ctl -H -n "${CLUSTER}" -t cluster -a online=no 2>&1`"
772
if_fail "$?" "$OUTPUT"
778
# 0 is not online, 1 is error, 2 is online
782
if [ "$#" -lt "1" -o -z "$1" ]
784
echo "check_online(): Requires an argument" >&2
790
if [ -d "$(configfs_path)/cluster/${CLUSTER}/node/" ]
792
ls -1 "$(configfs_path)/cluster/${CLUSTER}/node/" | while read NODE
794
LOCAL="`cat \"$(configfs_path)/cluster/${CLUSTER}/node/${NODE}/local\"`"
810
CLUSTER="${1:-${O2CB_BOOTCLUSTER}}"
823
if [ ! -e "$(configfs_path)/cluster/${CLUSTER}" ]
828
clean_heartbeat $CLUSTER
830
echo -n "Stopping O2CB cluster ${CLUSTER}: "
831
check_heartbeat $CLUSTER
835
echo "Unable to stop cluster as heartbeat region still active" >&2
841
clean_cluster $CLUSTER
842
if_fail "$?" "Unable to force-offline cluster $CLUSTER" >&2
844
OUTPUT="`o2cb_ctl -H -n "${CLUSTER}" -t cluster -a online=no 2>&1`"
845
if_fail "$?" "$OUTPUT - Try to force-offline the O2CB cluster"
854
if [ "$O2CB_ENABLED" != "true" ]
865
if [ -d "$(configfs_path)/cluster/" ]
867
ls -1 $(configfs_path)/cluster/ | while read CLUSTER
869
echo "Unable to unload modules as O2CB cluster ${CLUSTER} is still online" >&2
878
for i in $(seq $((${#LOAD_ACTIONS[*]} - 1)) -1 0); do
879
eval "un${LOAD_ACTIONS[i]}"
893
if [ -z "$DPKGRECONF" ]; then
895
if_fail "$?" "Unable to write the driver configuration"
907
CLUSTER="${1:-${O2CB_BOOTCLUSTER}}"
913
echo -n "Checking O2CB cluster $CLUSTER: "
914
check_online $CLUSTER
925
echo -n "Checking O2CB heartbeat: "
926
check_heartbeat $CLUSTER
937
echo -n "Checking if O2CB is loaded: "
939
for MODSPEC in $MODULE_LIST
941
MODULE_NAME="`echo $MODSPEC | cut -d: -f1`"
942
FSTYPE="`echo $MODSPEC | cut -d: -f2`"
943
MOUNT_POINT="`echo $MODSPEC | cut -d: -f3`"
945
if grep "^${MODULE_NAME} " /proc/modules >/dev/null 2>&1
947
echo -n "${MODULE_NAME} "
955
echo -n "Checking O2CB mount points: "
956
for MODSPEC in $MODULE_LIST
958
MODULE_NAME="`echo $MODSPEC | cut -d: -f1`"
959
FSTYPE="`echo $MODSPEC | cut -d: -f2`"
960
MOUNT_POINT="`echo $MODSPEC | cut -d: -f3`"
962
if [ -z "$FSTYPE" -o -z "$MOUNT_POINT" ]
967
FULL_MOUNT="${O2CB_MANAGER}/${MOUNT_POINT}"
968
FULL_MOUNTSEARCH="`echo "$FULL_MOUNT" | sed -e 's/\//\\\\\//g'`"
969
if grep "^${FSTYPE} ${FULL_MOUNTSEARCH} ${FSTYPE}" /proc/mounts >/dev/null 2>&1
971
echo -n "${MOUNT_POINT} "
1029
if [ "$O2CB_ENABLED" = "true" ]
1040
if_fail "$?" "Unable to write the driver configuration"
1047
if_fail "$?" "Unable to write the driver configuration"
1052
echo "Usage: $0 {start|stop|restart|force-reload|enable|disable|configure|load|unload|online|offline|force-offline|status}"