diff --git a/heartbeat/vsftpd b/heartbeat/vsftpd index 6af2b9987..544429d73 100755 --- a/heartbeat/vsftpd +++ b/heartbeat/vsftpd @@ -1,243 +1,241 @@ #!/bin/bash # # Resource script for vsftpd # # Description: Manages vsftpd as an OCF resource in # an Active-Passive High Availability setup. # # Author: Michel Rode : vsftpd script # License: GNU General Public License (GPLv2) # # # usage: $0 {start|stop|status|monitor|validate-all|meta-data} # # The "start" arg starts vsftpd. # # The "stop" arg stops it. # # OCF parameters: # OCF_RESKEY_binpath # OCF_RESKEY_conffile # OCF_RESKEY_pidfile # ########################################################################## # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs : ${OCF_RESKEY_binpath="/usr/sbin/vsftpd"} : ${OCF_RESKEY_conffile="/etc/vsftpd/vsftpd.conf"} : ${OCF_RESKEY_pidfile="/var/run/vsftpd.pid"} USAGE="Usage: $0 {start|stop|status|monitor|validate-all|meta-data}"; ########################################################################## usage() { echo $USAGE >&2 } meta_data() { cat < 1.0 This script manages vsftpd Manages an vsftpd The vsftpd binary path. For example, "/usr/sbin/vsftpd" Full path to the vsftpd binary The vsftpd configuration file name with full path. For example, "/etc/vsftpd/vsftpd.conf" Configuration file name with full path The vsftpd pidfile with full path. For example, "/var/run/vsftpd.pid" PID file with full path END exit $OCF_SUCCESS } get_pidfile() { PIDFILE=$OCF_RESKEY_pidfile } vsftpd_status() { if [ -n "$PIDFILE" -a -f $PIDFILE ]; then # vsftpd is probably running PID=`cat $PIDFILE` if [ -n "$PID" ]; then if ps -p $PID | grep vsftpd >/dev/null ; then ocf_log info "vsftpd daemon running" return $OCF_SUCCESS else ocf_log info "vsftpd daemon is not running but pid file exists" return $OCF_ERR_GENERIC fi else ocf_log err "PID file empty!" return $OCF_ERR_GENERIC fi fi # vsftpd is not running ocf_log info "vsftpd daemon is not running" return $OCF_NOT_RUNNING } vsftpd_start() { # if vsftpd is running return success vsftpd_status retVal=$? if [ $retVal -eq $OCF_SUCCESS ]; then exit $OCF_SUCCESS elif [ $retVal -ne $OCF_NOT_RUNNING ]; then ocf_log err "Error. Unknown status." exit $OCF_ERR_GENERIC fi if [ -n "$OCF_RESKEY_binpath" ]; then COMMAND="$OCF_RESKEY_binpath" fi if [ -n "$OCF_RESKEY_conffile" ]; then COMMAND="$COMMAND $OCF_RESKEY_conffile" fi $COMMAND; if [ $? -ne 0 ]; then ocf_log err "Error. vsftpd returned error $?." exit $OCF_ERR_GENERIC fi pidof vsftpd > $PIDFILE if [ $? -ne 0 ]; then ocf_log err "Error getting pid. Error: $?." exit $OCF_ERR_GENERIC fi - ocf_log info "Started vsftpd." + ocf_log info "Started vsftpd." exit $OCF_SUCCESS } vsftpd_stop() { if vsftpd_status ; then PID=`cat $PIDFILE` if [ -n "$PID" ] ; then kill $PID if [ $? -ne 0 ]; then kill -s KILL $PID if [ $? -ne 0 ]; then ocf_log err "Error. Could not stop vsftpd daemon." return $OCF_ERR_GENERIC fi fi rm $PIDFILE 2>/dev/null fi fi ocf_log info "Stopped vsftpd daemon." exit $OCF_SUCCESS } vsftpd_monitor() { vsftpd_status } vsftpd_validate_all() { - if [ -n "$OCF_RESKEY_binpath" -a ! -x "$OCF_RESKEY_binpath" ]; then - ocf_log err "Binary path $OCF_RESKEY_binpath does not exist." - exit $OCF_ERR_ARGS - fi + check_binary $OCF_RESKEY_binpath + if [ -n "$OCF_RESKEY_conffile" -a ! -f "$OCF_RESKEY_conffile" ]; then ocf_log err "Config file $OCF_RESKEY_conffile does not exist." exit $OCF_ERR_ARGS fi return $OCF_SUCCESS } # # Main # if [ $# -ne 1 ]; then usage exit $OCF_ERR_ARGS fi case $1 in start) get_pidfile vsftpd_start ;; stop) get_pidfile vsftpd_stop ;; status) get_pidfile vsftpd_status ;; monitor)get_pidfile vsftpd_monitor ;; validate-all) vsftpd_validate_all ;; meta-data) meta_data ;; usage) usage exit $OCF_SUCCESS ;; *) usage exit $OCF_ERR_UNIMPLEMENTED ;; esac