forked from brianjmurrell/iml-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Target
executable file
·164 lines (142 loc) · 3.85 KB
/
Target
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
#!/bin/sh
#
# Target
# Description: Manages a Lustre target on a shared storage medium.
#
# usage: ./Target {start|stop|status|monitor|validate-all|meta-data}
#
# OCF parameters are as below:
# OCF_RESKEY_target
#
# OCF_RESKEY_target : name of the target the chroma-agent should operate on
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/resource.d/heartbeat}
. ${OCF_FUNCTIONS_DIR}/.ocf-shellfuncs
usage() {
echo "usage: $0 {start|stop|status|monitor|meta-data}"
}
meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="Target">
<version>1.0</version>
<longdesc lang="en">
Resource script for a Chroma-managed Lustre Target.
</longdesc>
<shortdesc lang="en">Manages Chroma-managed Lustre Targets</shortdesc>
<parameters>
<parameter name="target" required="1">
<longdesc lang="en">
The name of the target.
</longdesc>
<shortdesc lang="en">target</shortdesc>
<content type="string" default="" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="60" />
<action name="stop" timeout="60" />
<action name="notify" timeout="60" />
<action name="monitor" depth="0" timeout="40" interval="20" />
<action name="validate-all" timeout="5" />
<action name="meta-data" timeout="5" />
</actions>
</resource-agent>
END
}
dbg() {
# shellcheck disable=SC2102
echo "$(date +[%d/%b/%Y:%H:%M:%S]) RA $1" >> /var/log/chroma-agent.log
}
Target_start() {
dbg "Target_start()"
# See if the device is already mounted.
if Target_status >/dev/null 2>&1; then
# ocf_log info "Target $TARGET is already started."
dbg "Target $TARGET is already started."
return $OCF_SUCCESS
fi
if ! grep -e 'lustre$' /proc/filesystems >/dev/null; then
# ocf_log err "Couldn't find the lustre module in /proc/filesystems"
dbg "Couldn't find the lustre module in /proc/filesystems"
return $OCF_ERR_ARGS
fi
# start the target
dbg "Starting: chroma-agent mount_target --uuid $TARGET --pacemaker_ha_operation 1"
if ! chroma-agent mount_target --uuid $TARGET --pacemaker_ha_operation 1; then
# ocf_log err "Couldn't start target $TARGET"
dbg "Couldn't start target $TARGET"
return $OCF_ERR_GENERIC
fi
dbg "Leaving Target_start() with success"
return $OCF_SUCCESS
}
Target_notify() {
dbg "Target_notify()"
return $OCF_SUCCESS
}
Target_stop() {
dbg "Target_stop()"
# started already?
Target_status >/dev/null 2>&1
if [ $? -eq $OCF_NOT_RUNNING ]; then
# woo! nothing to do.
rc=$OCF_SUCCESS
else
dbg "Unmounting: chroma-agent unmount_target --uuid $TARGET"
chroma-agent unmount_target --uuid $TARGET
fi
return $rc
}
Target_status() {
# call the agent to see if it's running
if chroma-agent target_running --uuid $TARGET >/dev/null 2>&1; then
rc=$OCF_SUCCESS
msg="$TARGET is started (running)"
else
rc=$OCF_NOT_RUNNING
msg="$TARGET is stopped"
fi
if [ "$OP" = "status" ]; then
dbg "$msg"
# ocf_log info "$msg"
fi
return $rc
}
Target_validate_all() {
dbg "Target_validate_all()"
return $OCF_SUCCESS
}
if [ $# -ne 1 ]; then
usage
exit $OCF_ERR_ARGS
fi
TARGET=$OCF_RESKEY_target
OP=$1
# These operations do not require instance parameters
case $OP in
meta-data) meta_data
exit $OCF_SUCCESS
;;
usage) usage
exit $OCF_SUCCESS
;;
status) Target_status
exit $?
;;
monitor) Target_status
exit $?
;;
validate-all) Target_validate_all
exit $?
;;
stop) Target_stop
exit $?
;;
start) Target_start
;;
*) usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
exit $?