diff --git a/heartbeat/proftpd b/heartbeat/proftpd index 38c4dcf06..e5cf36eec 100755 --- a/heartbeat/proftpd +++ b/heartbeat/proftpd @@ -1,301 +1,311 @@ #!/bin/sh # # Resource script for Proftpd # # Description: Manages Proftpd as an OCF resource in # an Active-Passive High Availability setup. # # Author: Rajat Upadhyaya : Pure-FTPd script # Author: Achim Stumpf : 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 -: ${OCF_RESKEY_binary="/usr/sbin/proftpd"} -: ${OCF_RESKEY_conffile="/etc/proftpd.conf"} -: ${OCF_RESKEY_pidfile="/var/run/proftpd.pid"} -: ${OCF_RESKEY_curl_binary="/usr/bin/curl"} -: ${OCF_RESKEY_curl_url="ftp://localhost/"} -: ${OCF_RESKEY_test_user="test"} -: ${OCF_RESKEY_test_pass=""} +# 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 < 1.0 This script manages Proftpd in an Active-Passive setup OCF Resource Agent compliant FTP script. The Proftpd binary The Proftpd binary - + The Proftpd configuration file name with full path. For example, "/etc/proftpd.conf" Configuration file name with full path - + The Proftpd PID file. The location of the PID file is configured in the Proftpd configuration file. PID file - + The absolute path to the curl binary for monitoring with OCF_CHECK_LEVEL greater zero. The absolute path to the curl binary - + The URL which is checked by curl with OCF_CHECK_LEVEL greater zero. The URL which is checked by curl - + The name of the ftp user for monitoring with OCF_CHECK_LEVEL greater zero. The name of the ftp user - + The password of the ftp user for monitoring with OCF_CHECK_LEVEL greater zero. The password of the ftp user - + 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