Whamcloud - gitweb
LU-2302 scripts: prevent lfs_migrate data disclosure
[fs/lustre-release.git] / lustre / scripts / Lustre.ha_v2
1 #!/bin/bash
2 #
3 # Lustre - Heartbeat R1 Resource Agent for the Lustre file system
4 #
5 # Usage: Lustre <resource-name> start|stop|status
6 #  where <resource-name> has the form "<hostname>-targets"
7 #
8
9 warn ()
10 {
11     if [ -e /etc/logd.cf ] && [ -x /usr/sbin/ha_logger ]; then
12         /usr/sbin/ha_logger -t heartbeat "Lustre: $*"
13     elif [ -x /usr/bin/logger ]; then
14         /usr/bin/logger -t heartbeat "Lustre: $*"
15     elif [ -x /bin/logger ]; then
16         /bin/logger -t heartbeat "Lustre: $*"
17     else
18        echo "Lustre: $*"
19     fi
20 }
21
22 die ()
23 {
24     warn "$*"
25     exit 1
26 }
27
28
29 if [ $# != 2 ]; then
30     die "wrong number of arguments: $*"
31 fi
32 if ! [ "$2" == "start" -o "$2" == "stop" -o "$2" == "status" ]; then
33     die "bad action arg[2]: $*"
34 fi
35
36 if ! [ -x /usr/sbin/ldev ]; then
37     die "/usr/sbin/ldev is missing or not executable"
38 fi
39 if ! [ -x /etc/init.d/lustre ]; then
40     die "/etc/init.d/lustre is missing or not executable"
41 fi
42
43 action=$2
44 if [ "`uname -n`-targets" == "$1" ]; then
45     service=local
46 elif [ "`/usr/sbin/ldev -p`-targets" == "$1" ]; then
47     service=foreign
48 else
49     die: "bad service arg[1]: $*"
50 fi
51
52 # Until multi-mount protect is implemented for ZFS we allow heartbeat to
53 # force import a pool.  This is required because ZFS will not allow you to
54 # import a pool on a new host unless you have cleanly exported it.
55 export ZPOOL_IMPORT_ARGS='-f'
56
57 # N.B. If status action reports "running", this must pass through to
58 # heartbeat unmodified.  Otherwise, stdout/stderr is discarded by heartbeat,
59 # so if we want to log diagnostic output from init scripts, we have to
60 # redirect it here.
61
62 warn /etc/init.d/lustre $action $service
63
64 tmpout=`mktemp` || die "mktemp failed"
65 /etc/init.d/lustre $action $service >$tmpout
66 result=$?
67 cat $tmpout | while read line; do
68     echo "$line"
69     warn "$line"
70 done
71 rm -f $tmpout
72
73 exit $result