blob: a9fc5ffd76dacb15901776ee14947eaeb33f0bd0 (
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
#!/bin/sh
#
# Resource script for Proftpd
#
# Description: Manages Proftpd as an OCF resource in
# an Active-Passive High Availability setup.
#
# Author: Rajat Upadhyaya <urajat@novell.com> : Pure-FTPd script
# Author: Achim Stumpf <hakim.news@googlemail.com> : Rewrite as Proftpd
# License: GNU General Public License (GPL)
#
#
# usage: $0 {start|stop|status|monitor|validate-all|meta-data}
#
# The "start" arg starts Proftpd.
#
# The "stop" arg stops it.
#
# OCF parameters:
# OCF_RESKEY_binary
# OCF_RESKEY_conffile
# OCF_RESKEY_pidfile
# OCF_RESKEY_curl_binary
# OCF_RESKEY_curl_url
# OCF_RESKEY_test_user
# OCF_RESKEY_test_pass
#
##########################################################################
# Initialization:
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
# Parameter defaults
OCF_RESKEY_binary_default="/usr/sbin/proftpd"
OCF_RESKEY_conffile_default="/etc/proftpd.conf"
OCF_RESKEY_pidfile_default="/var/run/proftpd.pid"
OCF_RESKEY_curl_binary_default="/usr/bin/curl"
OCF_RESKEY_curl_url_default="ftp://localhost/"
OCF_RESKEY_test_user_default="test"
OCF_RESKEY_test_pass_default=""
: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}}
: ${OCF_RESKEY_conffile=${OCF_RESKEY_conffile_default}}
: ${OCF_RESKEY_pidfile=${OCF_RESKEY_pidfile_default}}
: ${OCF_RESKEY_curl_binary=${OCF_RESKEY_curl_binary_default}}
: ${OCF_RESKEY_curl_url=${OCF_RESKEY_curl_url_default}}
: ${OCF_RESKEY_test_user=${OCF_RESKEY_test_user_default}}
: ${OCF_RESKEY_test_pass=${OCF_RESKEY_test_pass_default}}
USAGE="Usage: $0 {start|stop|status|monitor|validate-all|meta-data}";
##########################################################################
usage() {
echo $USAGE >&2
}
meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="proftpd" version="1.0">
<version>1.0</version>
<longdesc lang="en">
This script manages Proftpd in an Active-Passive setup
</longdesc>
<shortdesc lang="en">OCF Resource Agent compliant FTP script.</shortdesc>
<parameters>
<parameter name="binary" unique="0" required="0">
<longdesc lang="en">The Proftpd binary</longdesc>
<shortdesc lang="en">The Proftpd binary</shortdesc>
<content type="string" default="${OCF_RESKEY_binary_default}" />
</parameter>
<parameter name="conffile" unique="0" required="0">
<longdesc lang="en">
The Proftpd configuration file name with full path.
For example, "/etc/proftpd.conf"
</longdesc>
<shortdesc lang="en">Configuration file name with full path</shortdesc>
<content type="string" default="${OCF_RESKEY_conffile_default}" />
</parameter>
<parameter name="pidfile" unique="0" required="0">
<longdesc lang="en">The Proftpd PID file. The location of the PID file is configured in the Proftpd configuration file.</longdesc>
<shortdesc lang="en">PID file</shortdesc>
<content type="string" default="${OCF_RESKEY_pidfile_default}" />
</parameter>
<parameter name="curl_binary" unique="0" required="0">
<longdesc lang="en">The absolute path to the curl binary for monitoring with OCF_CHECK_LEVEL greater zero.</longdesc>
<shortdesc lang="en">The absolute path to the curl binary</shortdesc>
<content type="string" default="${OCF_RESKEY_curl_binary_default}" />
</parameter>
<parameter name="curl_url" unique="0" required="0">
<longdesc lang="en">The URL which is checked by curl with OCF_CHECK_LEVEL greater zero.</longdesc>
<shortdesc lang="en">The URL which is checked by curl</shortdesc>
<content type="string" default="${OCF_RESKEY_curl_url_default}" />
</parameter>
<parameter name="test_user" unique="0" required="0">
<longdesc lang="en">The name of the ftp user for monitoring with OCF_CHECK_LEVEL greater zero.</longdesc>
<shortdesc lang="en">The name of the ftp user</shortdesc>
<content type="string" default="${OCF_RESKEY_test_user_default}" />
</parameter>
<parameter name="test_pass" unique="0" required="0">
<longdesc lang="en">The password of the ftp user for monitoring with OCF_CHECK_LEVEL greater zero.</longdesc>
<shortdesc lang="en">The password of the ftp user</shortdesc>
<content type="string" default="${OCF_RESKEY_test_pass_default}" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="20s" />
<action name="stop" timeout="20s" />
<action name="monitor" depth="0" timeout="20s" interval="60s" />
<action name="monitor" depth="10" timeout="20s" interval="120s" />
<action name="validate-all" timeout="20s" />
<action name="meta-data" timeout="5s" />
</actions>
</resource-agent>
END
exit $OCF_SUCCESS
}
isRunning()
{
kill -s 0 "$1" > /dev/null 2>&1
}
proftpd_status()
{
if [ -f "$OCF_RESKEY_pidfile" ]
then
# Proftpd is probably running
PID=`head -n 1 $OCF_RESKEY_pidfile`
if [ ! -z "$PID" ] ; then
isRunning "$PID" && `ps -p $PID | grep proftpd > /dev/null 2>&1`
return $?
fi
fi
# Proftpd is not running
return $OCF_NOT_RUNNING;
}
proftpd_start()
{
# make a few checks and start Proftpd
if ocf_is_root ; then : ; else
ocf_log err "You must be root"
exit $OCF_ERR_PERM
fi
# if Proftpd is running return success
if proftpd_status ; then
ocf_log info "Proftpd is running already"
exit $OCF_SUCCESS
fi
# starting Proftpd
${OCF_RESKEY_binary} --config ${OCF_RESKEY_conffile} 2>/dev/null
if [ "$?" -ne 0 ]; then
ocf_log err "Proftpd returned error" $?
exit $OCF_ERR_GENERIC
fi
exit $OCF_SUCCESS
}
proftpd_stop()
{
if proftpd_status ; then
PID=`head -n 1 $OCF_RESKEY_pidfile`
if [ ! -z "$PID" ]; then
ocf_log info "Killing Proftpd PID $PID"
kill $PID > /dev/null 2>&1
if [ "$?" -eq 0 ]; then
TRIES=0
while isRunning "$PID" && [ "$TRIES" -lt 30 ]
do
sleep 1
ocf_log info "Proftpd PID $PID is still running"
TRIES=`expr $TRIES + 1`
done
isRunning "$PID"
RET=$?
if [ "$RET" -eq 0 ]; then
ocf_log info "Killing Proftpd PID $PID with SIGKILL"
kill -s 9 $PID > /dev/null 2>&1
while isRunning "$PID"
do
sleep 1
ocf_log info "Proftpd PID $PID is still running"
done
fi
else
ocf_log err "Killing Proftpd PID $PID FAILED"
exit $OCF_ERR_GENERIC
fi
fi
fi
exit $OCF_SUCCESS
}
proftpd_monitor()
{
proftpd_status
RET=$?
if [ "$RET" -ne 0 -o "$OCF_CHECK_LEVEL" = 0 ]; then
if [ "$RET" -eq 0 ]; then
PID=`head -n 1 $OCF_RESKEY_pidfile`
ocf_log debug "Proftpd monitor on PID $PID succeeded"
return $OCF_SUCCESS
else
ocf_log debug "Proftpd monitor on PID $PID failed"
return $OCF_NOT_RUNNING
fi
else
${OCF_RESKEY_curl_binary} -sS -u "${OCF_RESKEY_test_user}:${OCF_RESKEY_test_pass}" ${OCF_RESKEY_curl_url} > /dev/null 2>&1
if [ "$?" -eq 0 ]; then
ocf_log debug "Proftpd monitor with curl on URL $OCF_RESKEY_curl_url succeeded"
return $OCF_SUCCESS
else
ocf_log err "Proftpd monitor with curl on URL $OCF_RESKEY_curl_url failed"
return $OCF_NOT_RUNNING
fi
fi
}
proftpd_validate_all()
{
# check that the proftpd binary exists
if [ ! -x "$OCF_RESKEY_binary" ]; then
ocf_log err "Proftpd binary $OCF_RESKEY_binary does not exist"
exit $OCF_ERR_INSTALLED
fi
# check that the Proftpd config file exists
if [ ! -f "$OCF_RESKEY_conffile" ]; then
ocf_log err "Proftpd config file $OCF_RESKEY_conffile does not exist"
exit $OCF_ERR_CONFIGURED
fi
# check that the curl binary exists
if [ ! -x "$OCF_RESKEY_curl_binary" ]; then
ocf_log err "$OCF_RESKEY_curl_binary does not exist"
exit $OCF_ERR_INSTALLED
fi
}
#
# Main
#
if [ $# -ne 1 ]
then
usage
exit $OCF_ERR_ARGS
fi
case $1 in
start) proftpd_validate_all
proftpd_start
;;
stop) proftpd_stop
;;
status) if proftpd_status
then
ocf_log info "Proftpd is running"
exit $OCF_SUCCESS
else
ocf_log info "Proftpd is stopped"
exit $OCF_NOT_RUNNING
fi
;;
monitor) proftpd_monitor
exit $?
;;
validate-all) proftpd_validate_all
exit $OCF_SUCCESS
;;
meta-data) meta_data
;;
usage) usage
exit $OCF_SUCCESS
;;
*) usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
|