~davewalker/ubuntu/natty/ocfs2-tools/bug_363877

« back to all changes in this revision

Viewing changes to vendor/common/o2cb.init

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2009-07-06 07:26:30 UTC
  • mfrom: (1.1.7 upstream) (0.1.5 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090706072630-59335sl51k3rvu74
Tags: 1.4.2-1
* New upstream release (Closes: #535471).
* Drop patch for limits.h, included upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
# init fragment for O2CB.
3
 
#
4
 
# chkconfig: 2345 24 20
5
 
# description: Load O2CB cluster services at system boot.
6
 
#
7
 
### BEGIN INIT INFO
8
 
# Provides: o2cb
9
 
# Required-Start: $network
10
 
# Should-Start:
11
 
# Required-Stop:
12
 
# Default-Start: 2 3 5
13
 
# Default-Stop:
14
 
# Short-Description: Load O2CB cluster services at system boot.
15
 
# Description: Load O2CB cluster services at system boot.
16
 
### END INIT INFO
17
 
 
18
 
# Force LC_ALL=C
19
 
export LC_ALL=C
20
 
 
21
 
CLUSTERCONF=/etc/ocfs2/cluster.conf
22
 
 
23
 
if [ -f /etc/sysconfig/o2cb ]
24
 
then
25
 
    # Red Hat and Novell
26
 
    CONFIGURATION=/etc/sysconfig/o2cb
27
 
elif [ -f /etc/default/o2cb ]
28
 
then
29
 
    # Debian
30
 
    CONFIGURATION=/etc/default/o2cb
31
 
    DPKGRECONF=yes
32
 
elif [ -d /etc/sysconfig ]
33
 
then
34
 
    CONFIGURATION=/etc/sysconfig/o2cb
35
 
else
36
 
    CONFIGURATION=/etc/default/o2cb
37
 
fi
38
 
 
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
44
 
 
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
50
 
 
51
 
# Source configuration, 
52
 
[ -f "${CONFIGURATION}" ] && . "${CONFIGURATION}"
53
 
 
54
 
configfs_path()
55
 
{
56
 
    # Note that this is only valid *after* configfs is loaded
57
 
    if [ -d /sys/kernel/config ]
58
 
    then
59
 
        echo /sys/kernel/config
60
 
    else
61
 
        echo /config
62
 
    fi
63
 
}
64
 
 
65
 
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
69
 
# follows:
70
 
#
71
 
# start/load:
72
 
#    Eval of the exact lines, in order.  So, the first call is
73
 
#    "eval load_module configfs".
74
 
#
75
 
# status:
76
 
#    Eval of the lines with "check_" prepended, in order.  So the first
77
 
#    call is "eval check_load_module configfs".
78
 
#
79
 
# stop/unload:
80
 
#    Eval of the lines with "un" prepened, in reverse order.  So the
81
 
#    *last* call is "eval unload_module configfs".
82
 
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.
86
 
#
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")
94
 
 
95
 
 
96
 
#
97
 
# if_fail()
98
 
#
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.
102
 
#
103
 
if_fail()
104
 
{
105
 
    RC="$1"
106
 
    REASON="$2"
107
 
    if [ "$RC" = "0" ]
108
 
    then
109
 
        echo "OK"
110
 
        return
111
 
    elif [ "$RC" = "2" ]
112
 
    then
113
 
        return
114
 
    fi
115
 
    echo "Failed"
116
 
    if [ -n "${REASON}" ]
117
 
    then
118
 
        echo "${REASON}" >&2
119
 
    fi
120
 
    exit 1
121
 
}
122
 
 
123
 
 
124
 
#
125
 
# write_sysconfig()
126
 
#
127
 
# Writes the system configuration out
128
 
#
129
 
write_sysconfig()
130
 
{
131
 
    echo -n "Writing O2CB configuration: "
132
 
    cat >"${CONFIGURATION}" <<EOF
133
 
#
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'.
138
 
#
139
 
 
140
 
# O2CB_ENABLED: 'true' means to load the driver on boot.
141
 
O2CB_ENABLED=${O2CB_ENABLED:-false}
142
 
 
143
 
# O2CB_BOOTCLUSTER: If not empty, the name of a cluster to start.
144
 
O2CB_BOOTCLUSTER=${O2CB_BOOTCLUSTER}
145
 
 
146
 
# O2CB_HEARTBEAT_THRESHOLD: Iterations before a node is considered dead.
147
 
O2CB_HEARTBEAT_THRESHOLD=${O2CB_HEARTBEAT_THRESHOLD}
148
 
 
149
 
# O2CB_IDLE_TIMEOUT_MS: Time in ms before a network connection is considered dead.
150
 
O2CB_IDLE_TIMEOUT_MS=${O2CB_IDLE_TIMEOUT_MS}
151
 
 
152
 
# O2CB_KEEPALIVE_DELAY_MS: Max time in ms before a keepalive packet is sent
153
 
O2CB_KEEPALIVE_DELAY_MS=${O2CB_KEEPALIVE_DELAY_MS}
154
 
 
155
 
# O2CB_RECONNECT_DELAY_MS: Min time in ms between connection attempts
156
 
O2CB_RECONNECT_DELAY_MS=${O2CB_RECONNECT_DELAY_MS}
157
 
 
158
 
EOF
159
 
 
160
 
    if [ $? != 0 ]
161
 
    then
162
 
        return 1
163
 
    fi
164
 
    return 0
165
 
}
166
 
 
167
 
#
168
 
# read_timeout()
169
 
#   Returns timeout value provided by user to caller in RET_VAL
170
 
#
171
 
read_timeout()
172
 
{
173
 
    if [ "$#" -lt "4" ]; then
174
 
        echo "read_timeout(): Requires more arguments" >&2
175
 
        exit 1
176
 
    fi
177
 
 
178
 
    ATTRIB_NAME=$1
179
 
    ATTRIB_VAL=$2
180
 
    MIN_ATTRIB_VAL=$3
181
 
    DEF_ATTRIB_VAL=$4
182
 
    RET_VAL=0
183
 
 
184
 
    while :
185
 
    do
186
 
        if [ -z $ATTRIB_VAL ]; then
187
 
            CUR=$DEF_ATTRIB_VAL
188
 
        else
189
 
            CUR=$ATTRIB_VAL
190
 
        fi
191
 
        echo -n "Specify ${ATTRIB_NAME} (>=$MIN_ATTRIB_VAL) [$CUR]: "
192
 
        read LINE
193
 
        case "$LINE" in
194
 
        "")
195
 
            RET_VAL="$ATTRIB_VAL"
196
 
            break
197
 
            ;;
198
 
 
199
 
        *[^0-9]*)
200
 
            echo "Invalid ${ATTRIB_NAME} value: $LINE" >&2
201
 
            ;;
202
 
        *)
203
 
            if [ $LINE -lt $MIN_ATTRIB_VAL ]; then
204
 
                echo "${ATTRIB_NAME} cannot be less than $MIN_ATTRIB_VAL" >&2
205
 
            else
206
 
                RET_VAL="$LINE"
207
 
                break
208
 
            fi
209
 
            ;;
210
 
        esac
211
 
    done
212
 
}
213
 
 
214
 
set_timeouts()
215
 
{
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"
223
 
        fi
224
 
    fi
225
 
 
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"
230
 
        fi
231
 
    fi
232
 
 
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"
237
 
        fi
238
 
    fi
239
 
 
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"
244
 
        fi
245
 
    fi
246
 
}
247
 
 
248
 
show_timeouts()
249
 
{
250
 
 
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}"
259
 
    fi
260
 
 
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}"
265
 
    fi
266
 
 
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}"
271
 
    fi
272
 
 
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}"
277
 
    fi
278
 
}
279
 
 
280
 
#
281
 
# configure_ask()
282
 
#
283
 
# Ask configuration questions, setting the shell vars.
284
 
#
285
 
configure_ask()
286
 
{
287
 
    if [ -n "$DPKGRECONF" ]; then
288
 
        cat <<EOF
289
 
Configuring the O2CB driver.
290
 
 
291
 
Please configure this service in the Debian way:
292
 
 
293
 
 dpkg-reconfigure ocfs2-tools
294
 
EOF
295
 
 
296
 
        exit 0
297
 
    fi
298
 
 
299
 
    cat <<EOF
300
 
Configuring the O2CB driver.
301
 
 
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
306
 
will abort.
307
 
 
308
 
EOF
309
 
 
310
 
    while :
311
 
    do
312
 
        if [ "$O2CB_ENABLED" = "true" ]
313
 
        then
314
 
            CUR=y
315
 
        else
316
 
            CUR=n
317
 
        fi
318
 
        echo -n "Load O2CB driver on boot (y/n) [$CUR]: "
319
 
        read LINE
320
 
        case "$LINE" in
321
 
        "")
322
 
            break
323
 
            ;;
324
 
        y|Y)
325
 
            O2CB_ENABLED=true
326
 
            break
327
 
            ;;
328
 
        n|N)
329
 
            O2CB_ENABLED=false
330
 
            break
331
 
            ;;
332
 
        *)
333
 
            echo "Invalid answer: $LINE" >&2
334
 
            ;;
335
 
        esac
336
 
    done
337
 
 
338
 
    while :
339
 
    do
340
 
        echo -n "Cluster to start on boot (Enter \"none\" to clear) [$O2CB_BOOTCLUSTER]: "
341
 
        read LINE
342
 
        case "$LINE" in
343
 
        "")
344
 
            break
345
 
            ;;
346
 
        none)
347
 
            O2CB_BOOTCLUSTER=
348
 
            break
349
 
            ;;
350
 
 
351
 
        *[^a-zA-Z0-9]*)
352
 
            echo "Invalid cluster name: $LINE" >&2
353
 
            ;;
354
 
        *)
355
 
            O2CB_BOOTCLUSTER="$LINE"
356
 
            break
357
 
            ;;
358
 
        esac
359
 
    done
360
 
 
361
 
    read_timeout "heartbeat dead threshold" "$O2CB_HEARTBEAT_THRESHOLD" "$MIN_HEARTBEAT_THRESHOLD" "$DEF_HEARTBEAT_THRESHOLD"
362
 
    O2CB_HEARTBEAT_THRESHOLD="$RET_VAL"
363
 
 
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"
366
 
 
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"
369
 
 
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"
372
 
 
373
 
    # XXX ask about mount point base
374
 
}
375
 
 
376
 
 
377
 
#
378
 
# make_dir()
379
 
#
380
 
# Create $1
381
 
# Returns 0 on success, 1 on error, 2 if it already exists.
382
 
#
383
 
make_dir()
384
 
{
385
 
    if [ "$#" -lt "1" -o -z "$1" ]
386
 
    then
387
 
        echo "make_dir(): Requires an argument" >&2
388
 
        return 1
389
 
    fi
390
 
    DIR="$1"
391
 
    if [ -e "$DIR" ]
392
 
    then
393
 
        if [ -d "$DIR" ]
394
 
        then
395
 
            return 2
396
 
        fi
397
 
        echo "make_dir(): File $DIR is not a directory" >&2
398
 
        return 1
399
 
    fi
400
 
 
401
 
    echo -n "Creating directory '$DIR': "
402
 
    mkdir -p "$DIR" 2>/dev/null
403
 
    if [ $? != 0 ]
404
 
    then
405
 
        echo "Unable to create directory '$DIR'" >&2
406
 
        return 1
407
 
    fi
408
 
    return 0
409
 
}
410
 
 
411
 
 
412
 
#
413
 
# load_module()
414
 
# Load a module
415
 
#
416
 
# 0 is success, 1 is error, 2 is already loaded
417
 
418
 
load_module()
419
 
{
420
 
    if [ "$#" -lt "1" -o -z "$1" ]
421
 
    then
422
 
        echo "load_module(): Requires an argument" >&2
423
 
        return 1
424
 
    fi
425
 
    MODNAME="$1"
426
 
 
427
 
    MODOUT="`awk '$1 ~ /^'$MODNAME'$/{print $1;exit}' < /proc/modules 2>/dev/null`"
428
 
    if [ -n "$MODOUT" ]
429
 
    then
430
 
        return 2
431
 
    fi
432
 
 
433
 
    echo -n "Loading module \"$MODNAME\": "
434
 
    modprobe -s "$MODNAME"
435
 
    if [ "$?" != 0 ]
436
 
    then
437
 
        echo "Unable to load module \"$MODNAME\"" >&2
438
 
        return 1
439
 
    fi
440
 
 
441
 
    return 0
442
 
}
443
 
 
444
 
#
445
 
# check_heartbeat()
446
 
#
447
 
# 0 is hb not active, 1 is error, 2 is hb active
448
 
#
449
 
check_heartbeat()
450
 
{
451
 
    if [ "$#" -lt "1" -o -z "$1" ]
452
 
    then
453
 
        echo "check_heartbeat(): Requires an argument" >&2
454
 
        return 1
455
 
    fi
456
 
    CLUSTER="$1"
457
 
 
458
 
    RC=0
459
 
    if [ -d "$(configfs_path)/cluster/${CLUSTER}/heartbeat/" ]
460
 
    then
461
 
        ls -1 "$(configfs_path)/cluster/${CLUSTER}/heartbeat/" | while read HBUUID
462
 
        do
463
 
            if [ -d "$(configfs_path)/cluster/${CLUSTER}/heartbeat/${HBUUID}" ]
464
 
            then
465
 
                return 2;
466
 
            fi
467
 
        done
468
 
        if [ $? = 2 ]
469
 
        then
470
 
            RC=2
471
 
        fi
472
 
    fi
473
 
 
474
 
    return $RC
475
 
}
476
 
 
477
 
#
478
 
# clean_heartbeat()
479
 
# Removes the inactive heartbeat regions
480
 
481
 
clean_heartbeat()
482
 
{
483
 
    if [ "$#" -lt "1" -o -z "$1" ]
484
 
    then
485
 
        echo "clean_heartbeat(): Requires an argument" >&2
486
 
        return 1
487
 
    fi
488
 
    CLUSTER="$1"
489
 
 
490
 
    if [ ! -f "$(configfs_path)/cluster/${CLUSTER}/heartbeat/*" ]
491
 
    then
492
 
        return
493
 
    fi
494
 
 
495
 
    echo -n "Cleaning heartbeat on ${CLUSTER}: "
496
 
 
497
 
    ls -1 "$(configfs_path)/cluster/${CLUSTER}/heartbeat/" | while read HBUUID
498
 
    do
499
 
        if [ ! -d "$(configfs_path)/cluster/${CLUSTER}/heartbeat/${HBUUID}" ]
500
 
        then
501
 
            continue
502
 
        fi
503
 
 
504
 
        OUTPUT="`ocfs2_hb_ctl -I -u ${HBUUID} 2>&1`"
505
 
        if [ $? != 0 ]
506
 
        then
507
 
            echo "Failed"
508
 
            echo "${OUTPUT}" >&2
509
 
            exit 1
510
 
        fi
511
 
 
512
 
        REF="`echo ${OUTPUT} | awk '/refs/ {print $2; exit;}' 2>&1`"
513
 
        if [ $REF != 0 ]
514
 
        then
515
 
           echo "Failed"
516
 
           echo "At least one heartbeat region still active" >&2
517
 
           exit 1
518
 
        else
519
 
           OUTPUT="`ocfs2_hb_ctl -K -u ${HBUUID} 2>&1`"
520
 
        fi
521
 
    done
522
 
    if [ $? = 1 ]
523
 
    then
524
 
        exit 1
525
 
    fi
526
 
    echo "OK"
527
 
}
528
 
 
529
 
#
530
 
# clean_cluster()
531
 
# Force cleans configured cluster
532
 
#
533
 
# 0 is clean, 1 is error, 2 is not clean
534
 
#
535
 
clean_cluster()
536
 
{
537
 
    if [ "$#" -lt "1" -o -z "$1" ]
538
 
    then
539
 
        echo "clean_cluster(): Requires an argument" >&2
540
 
        return 1
541
 
    fi
542
 
    CLUSTER="$1"
543
 
 
544
 
    if [ -d "$(configfs_path)/cluster/${CLUSTER}/node/" ]
545
 
    then
546
 
        ls -1 "$(configfs_path)/cluster/${CLUSTER}/node/" | while read NODE
547
 
        do
548
 
            rmdir "$(configfs_path)/cluster/${CLUSTER}/node/${NODE}" >/dev/null 2>&1
549
 
        done
550
 
    fi
551
 
 
552
 
    if [ -d "$(configfs_path)/cluster/${CLUSTER}" ]
553
 
    then
554
 
        rmdir "$(configfs_path)/cluster/${CLUSTER}" >/dev/null 2>&1
555
 
    fi
556
 
 
557
 
    if [ -d "$(configfs_path)/cluster/${CLUSTER}" ]
558
 
    then
559
 
        return 2
560
 
    fi
561
 
 
562
 
    return 0
563
 
}
564
 
 
565
 
#
566
 
# unload_module()
567
 
# Unload a module
568
 
#
569
 
# 0 is success, 1 is error, 2 is not loaded
570
 
571
 
unload_module()
572
 
{
573
 
    if [ "$#" -lt "1" -o -z "$1" ]
574
 
    then
575
 
        echo "unload_module(): Requires an argument" >&2
576
 
        return 1
577
 
    fi
578
 
    MODNAME="$1"
579
 
 
580
 
    MODOUT="`awk '$1 ~ /^'$MODNAME'$/{print $1,$3;exit}' < /proc/modules 2>/dev/null`"
581
 
    if [ -z "$MODOUT" ]
582
 
    then
583
 
        return 2
584
 
    fi
585
 
    case "$MODOUT" in
586
 
    $MODNAME\ 0)
587
 
        ;;
588
 
    $MODNAME\ *)
589
 
        return 2
590
 
        ;;
591
 
    *)
592
 
        echo -n "Invalid module parsing! "
593
 
        return 1
594
 
        ;;
595
 
    esac
596
 
 
597
 
    echo -n "Unloading module \"$MODNAME\": "
598
 
    modprobe -rs "$MODNAME"
599
 
    if [ "$?" != 0 ]
600
 
    then
601
 
        echo "Unable to unload module \"$MODNAME\"" >&2
602
 
        return 1
603
 
    fi
604
 
 
605
 
    return 0
606
 
}
607
 
 
608
 
#
609
 
# check_load_module()
610
 
#
611
 
# 0 is not loaded, 1 is error, 2 is already loaded
612
 
#
613
 
check_load_module()
614
 
{
615
 
    if [ "$#" -lt "1" -o -z "$1" ]
616
 
    then
617
 
        echo "check_load_module(): Requires an argument" >&2
618
 
        return 1
619
 
    fi
620
 
    MODNAME="$1"
621
 
 
622
 
    echo -n "Module \"$MODNAME\": "
623
 
    MODOUT="`awk '$1 ~ /^'$MODNAME'$/{print $1,$3;exit}' < /proc/modules 2>/dev/null`"
624
 
    if [ -z "$MODOUT" ]
625
 
    then
626
 
        echo "Not loaded"
627
 
        return 0
628
 
    fi
629
 
    echo "Loaded"
630
 
    return 2
631
 
}
632
 
 
633
 
 
634
 
#
635
 
# mount_fs()
636
 
# Mount a filesystem.
637
 
#
638
 
# 0 is success, 1 is error, 2 is already mounted
639
 
#
640
 
mount_fs()
641
 
{
642
 
    TYPE="$1"
643
 
    FULL_MOUNT="$2"
644
 
    FULL_MOUNTSEARCH="`echo "$FULL_MOUNT" | sed -e 's/\//\\\\\//g'`"
645
 
    MOUNTOUT="`awk '$2 ~ /^'$FULL_MOUNTSEARCH'$/{print $2; exit}' < /proc/mounts 2>/dev/null`"
646
 
 
647
 
    if [ -n "$MOUNTOUT" ]
648
 
    then
649
 
        return 2
650
 
    fi
651
 
 
652
 
    # XXX some policy?
653
 
    if [ ! -e "$FULL_MOUNT" ]; then
654
 
        make_dir $FULL_MOUNT
655
 
        if_fail "$?"
656
 
    fi
657
 
 
658
 
    echo -n "Mounting ${TYPE} filesystem at $FULL_MOUNT: "
659
 
    mount -t ${TYPE} ${TYPE} $FULL_MOUNT
660
 
    if [ $? != 0 ]
661
 
    then
662
 
        echo "Unable to mount ${TYPE} filesystem" >&2
663
 
        return 1
664
 
    fi
665
 
 
666
 
    return 0
667
 
}
668
 
 
669
 
#
670
 
# check_mount_fs()
671
 
#
672
 
# 0 is not mounted, 1 is error, 2 is already mounted
673
 
#
674
 
check_mount_fs()
675
 
{
676
 
    TYPE="$1"
677
 
    FULL_MOUNT="$2"
678
 
    FULL_MOUNTSEARCH="`echo "$FULL_MOUNT" | sed -e 's/\//\\\\\//g'`"
679
 
    MOUNTOUT="`awk '$2 ~ /^'$FULL_MOUNTSEARCH'$/{print $2; exit}' < /proc/mounts 2>/dev/null`"
680
 
 
681
 
    echo -n "Filesystem \"$TYPE\": "
682
 
    if [ -n "$MOUNTOUT" ]
683
 
    then
684
 
        echo "Mounted"
685
 
        return 2
686
 
    fi
687
 
    echo "Not mounted"
688
 
    return 0
689
 
}
690
 
 
691
 
#
692
 
# unmount_fs()
693
 
# Unmount a filesystem
694
 
#
695
 
# 0 is success, 1 is error, 2 is not mounted
696
 
#
697
 
unmount_fs()
698
 
{
699
 
    TYPE="$1"
700
 
    FULL_MOUNT="$2"
701
 
    FULL_MOUNTSEARCH="`echo "$FULL_MOUNT" | sed -e 's/\//\\\\\//g'`"
702
 
    MOUNTOUT="`awk '$2 ~ /^'$FULL_MOUNTSEARCH'$/{print $2; exit}' < /proc/mounts 2>/dev/null`"
703
 
 
704
 
    if [ -z "$MOUNTOUT" ]
705
 
    then
706
 
        return 2
707
 
    fi
708
 
 
709
 
    echo -n "Unmounting ${TYPE} filesystem: "
710
 
    umount $FULL_MOUNT
711
 
    if [ $? != 0 ]
712
 
    then
713
 
        echo "Unable to unmount ${TYPE} filesystem" >&2
714
 
        return 1
715
 
    fi
716
 
 
717
 
    return 0
718
 
}
719
 
 
720
 
load()
721
 
{
722
 
    for i in $(seq 0 $((${#LOAD_ACTIONS[*]} - 1)) ); do
723
 
        eval ${LOAD_ACTIONS[i]}
724
 
        if_fail "$?"
725
 
    done
726
 
}
727
 
 
728
 
load_status()
729
 
{
730
 
    for i in $(seq 0 $((${#LOAD_ACTIONS[*]} - 1)) ); do
731
 
        eval "check_${LOAD_ACTIONS[i]}"
732
 
    done
733
 
    return "$?"
734
 
}
735
 
 
736
 
online()
737
 
{
738
 
    CLUSTER="${1:-${O2CB_BOOTCLUSTER}}"
739
 
    if [ -z "$CLUSTER" ]
740
 
    then
741
 
        echo "O2CB cluster not known"
742
 
        return
743
 
    fi
744
 
 
745
 
    check_online $CLUSTER
746
 
    if [ $? = 2 ]
747
 
    then
748
 
        echo "O2CB cluster ${CLUSTER} already online"
749
 
        return
750
 
    fi
751
 
 
752
 
    if ! [ -f ${CLUSTERCONF} ]
753
 
    then
754
 
        echo -n "Checking O2CB cluster configuration : "
755
 
        if_fail 1
756
 
    fi
757
 
 
758
 
    echo -n "Starting O2CB cluster ${CLUSTER}: "
759
 
    OUTPUT="`o2cb_ctl -H -n "${CLUSTER}" -t cluster -a online=yes 2>&1`"
760
 
    if [ $? = 0 ]
761
 
    then
762
 
        set_timeouts
763
 
        echo "OK"
764
 
        return
765
 
    else
766
 
        echo "Failed"
767
 
        echo "$OUTPUT"
768
 
    fi
769
 
 
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"
773
 
}
774
 
 
775
 
#
776
 
# check_online()
777
 
#
778
 
# 0 is not online, 1 is error, 2 is online
779
 
#
780
 
check_online()
781
 
{
782
 
    if [ "$#" -lt "1" -o -z "$1" ]
783
 
    then
784
 
        echo "check_online(): Requires an argument" >&2
785
 
        return 1
786
 
    fi
787
 
    CLUSTER="$1"
788
 
 
789
 
    RC=0
790
 
    if [ -d "$(configfs_path)/cluster/${CLUSTER}/node/" ]
791
 
    then
792
 
        ls -1 "$(configfs_path)/cluster/${CLUSTER}/node/" | while read NODE
793
 
        do
794
 
            LOCAL="`cat \"$(configfs_path)/cluster/${CLUSTER}/node/${NODE}/local\"`"
795
 
            if [ $LOCAL = 1 ]
796
 
            then
797
 
                return 2
798
 
            fi
799
 
        done
800
 
        if [ $? = 2 ]
801
 
        then
802
 
            RC=2
803
 
        fi
804
 
    fi
805
 
    return $RC
806
 
}
807
 
 
808
 
offline()
809
 
{
810
 
    CLUSTER="${1:-${O2CB_BOOTCLUSTER}}"
811
 
    if [ -z "$CLUSTER" ]
812
 
    then
813
 
        return
814
 
    fi
815
 
 
816
 
    if [ $# -gt 1 ]
817
 
    then
818
 
        FORCE=$2
819
 
    else
820
 
        FORCE=0
821
 
    fi
822
 
 
823
 
    if [ ! -e "$(configfs_path)/cluster/${CLUSTER}" ]
824
 
    then
825
 
        return
826
 
    fi
827
 
 
828
 
    clean_heartbeat $CLUSTER
829
 
 
830
 
    echo -n "Stopping O2CB cluster ${CLUSTER}: "
831
 
    check_heartbeat $CLUSTER
832
 
    if [ $? != 0 ]
833
 
    then
834
 
        echo "Failed"
835
 
        echo "Unable to stop cluster as heartbeat region still active" >&2
836
 
        exit 1
837
 
    fi
838
 
 
839
 
    if [ $FORCE -eq 1 ]
840
 
    then
841
 
        clean_cluster $CLUSTER
842
 
        if_fail "$?" "Unable to force-offline cluster $CLUSTER" >&2
843
 
    else
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"
846
 
    fi
847
 
 
848
 
    unload_module ocfs2
849
 
    if_fail "$?"
850
 
}
851
 
 
852
 
start()
853
 
{
854
 
    if [ "$O2CB_ENABLED" != "true" ]
855
 
    then
856
 
        exit 0
857
 
    fi
858
 
 
859
 
    load
860
 
    online "$1"
861
 
}
862
 
 
863
 
unload()
864
 
{
865
 
    if [ -d "$(configfs_path)/cluster/" ]
866
 
    then
867
 
        ls -1 $(configfs_path)/cluster/ | while read CLUSTER
868
 
        do
869
 
            echo "Unable to unload modules as O2CB cluster ${CLUSTER} is still online" >&2
870
 
            exit 1
871
 
        done
872
 
        if [ $? = 1 ]
873
 
        then
874
 
            exit 1
875
 
        fi
876
 
    fi
877
 
 
878
 
    for i in $(seq $((${#LOAD_ACTIONS[*]} - 1)) -1 0); do
879
 
        eval "un${LOAD_ACTIONS[i]}"
880
 
        if_fail "$?"
881
 
    done
882
 
}
883
 
 
884
 
stop()
885
 
{
886
 
    offline "$1"
887
 
    unload
888
 
}
889
 
 
890
 
configure()
891
 
{
892
 
    configure_ask
893
 
    if [ -z "$DPKGRECONF" ]; then
894
 
        write_sysconfig
895
 
        if_fail "$?" "Unable to write the driver configuration"
896
 
    fi
897
 
}
898
 
 
899
 
status()
900
 
{
901
 
    load_status
902
 
    if [ $? != 2 ]
903
 
    then
904
 
        return 0;
905
 
    fi
906
 
 
907
 
    CLUSTER="${1:-${O2CB_BOOTCLUSTER}}"
908
 
    if [ -z "$CLUSTER" ]
909
 
    then
910
 
        return 1;
911
 
    fi
912
 
 
913
 
    echo -n "Checking O2CB cluster $CLUSTER: "
914
 
    check_online $CLUSTER
915
 
    if [ $? = 2 ]
916
 
    then
917
 
       echo "Online"
918
 
    else
919
 
       echo "Offline"
920
 
       return 0;
921
 
    fi
922
 
 
923
 
    show_timeouts
924
 
 
925
 
    echo -n "Checking O2CB heartbeat: "
926
 
    check_heartbeat $CLUSTER
927
 
    if [ $? = 2 ]
928
 
    then
929
 
        echo "Active"
930
 
    else
931
 
        echo "Not active"
932
 
        return 0;
933
 
    fi
934
 
 
935
 
    return
936
 
 
937
 
    echo -n "Checking if O2CB is loaded: "
938
 
    RC=0
939
 
    for MODSPEC in $MODULE_LIST
940
 
    do
941
 
        MODULE_NAME="`echo $MODSPEC | cut -d: -f1`"
942
 
        FSTYPE="`echo $MODSPEC | cut -d: -f2`"
943
 
        MOUNT_POINT="`echo $MODSPEC | cut -d: -f3`"
944
 
 
945
 
        if grep "^${MODULE_NAME} " /proc/modules >/dev/null 2>&1
946
 
        then
947
 
            echo -n "${MODULE_NAME} "
948
 
        else
949
 
            RC=1
950
 
            break
951
 
        fi
952
 
    done
953
 
    if_fail "$RC"
954
 
 
955
 
    echo -n "Checking O2CB mount points: "
956
 
    for MODSPEC in $MODULE_LIST
957
 
    do
958
 
        MODULE_NAME="`echo $MODSPEC | cut -d: -f1`"
959
 
        FSTYPE="`echo $MODSPEC | cut -d: -f2`"
960
 
        MOUNT_POINT="`echo $MODSPEC | cut -d: -f3`"
961
 
 
962
 
        if [ -z "$FSTYPE" -o -z "$MOUNT_POINT" ]
963
 
        then
964
 
            continue
965
 
        fi
966
 
 
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
970
 
        then
971
 
            echo -n "${MOUNT_POINT} "
972
 
        else
973
 
            RC=1
974
 
            break
975
 
        fi
976
 
    done
977
 
    if_fail "$RC"
978
 
}
979
 
 
980
 
 
981
 
 
982
 
case "$1" in
983
 
    start)
984
 
        start "$2"
985
 
        ;;
986
 
 
987
 
    status)
988
 
        status "$2"
989
 
        ;;
990
 
 
991
 
    stop)
992
 
        stop "$2"
993
 
        ;;
994
 
 
995
 
    restart)
996
 
        stop "$2"
997
 
        start "$2"
998
 
        ;;
999
 
 
1000
 
    force-reload)
1001
 
        stop "$2"
1002
 
        start "$2"
1003
 
        ;;
1004
 
 
1005
 
    load)
1006
 
        load
1007
 
        ;;
1008
 
 
1009
 
    online)
1010
 
        load
1011
 
        online "$2"
1012
 
        ;;
1013
 
 
1014
 
    offline)
1015
 
        offline "$2"
1016
 
        ;;
1017
 
 
1018
 
    force-offline)
1019
 
        offline "$2" 1
1020
 
        ;;
1021
 
 
1022
 
    unload)
1023
 
        offline "$2"
1024
 
        unload
1025
 
        ;;
1026
 
 
1027
 
    configure)
1028
 
        configure
1029
 
        if [ "$O2CB_ENABLED" = "true" ]
1030
 
        then
1031
 
            start
1032
 
        else
1033
 
            stop
1034
 
        fi
1035
 
        ;;
1036
 
 
1037
 
    enable)
1038
 
        O2CB_ENABLED=true
1039
 
        write_sysconfig
1040
 
        if_fail "$?" "Unable to write the driver configuration"
1041
 
        start
1042
 
        ;;
1043
 
 
1044
 
    disable)
1045
 
        O2CB_ENABLED=false
1046
 
        write_sysconfig
1047
 
        if_fail "$?" "Unable to write the driver configuration"
1048
 
        stop
1049
 
        ;;
1050
 
 
1051
 
    *)
1052
 
        echo "Usage: $0 {start|stop|restart|force-reload|enable|disable|configure|load|unload|online|offline|force-offline|status}"
1053
 
        exit 1
1054
 
        ;;
1055
 
esac
1056
 
 
1057
 
exit 0