diff --git a/heartbeat/Xinetd b/heartbeat/Xinetd index f18e0fbd0..36a93e354 100755 --- a/heartbeat/Xinetd +++ b/heartbeat/Xinetd @@ -1,228 +1,228 @@ #!/bin/sh # # Startup/shutdown script for services managed by xinetd. # # Copyright (C) 2003 Charlie Brooks # Copyright (C) 2011 Ulrich Windl # # WARNING: Tested ONLY on SLES11 SP1 at this time. # # Author: Charlie Brooks # Description: given parameters of a service name and start|stop|status, # will enable, disable or report on a specified xinetd service # Config: all services must have a descriptor file in /etc/xinetd.d # Support: linux-ha@lists.linux-ha.org # License: GNU General Public License (GPL) # # OCF parameters are as below: # OCF_RESKEY_service ####################################################################### # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs service=$OCF_RESKEY_service SVCDEF=/etc/xinetd.d/$service ####################################################################### meta_data() { cat < 1.0 Resource script for Xinetd. It starts/stops services managed by xinetd by enabling or disabling them in the configuration file. Important notes: The xinetd daemon itself must be running: we are not going to start or stop it ourselves. All services should have a line saying either "disable=yes" or "disable=no". The script just changes those settings before reloading xinetd. Important: in case the services managed by the cluster are the only ones enabled, you should specify the -stayalive option for xinetd or it will exit on Heartbeat stop. Alternatively, you may enable some internal service such as echo. Manages a service of Xinetd The name of the service managed by xinetd. service name END } # force xinetd to reload the service descriptions hup_inetd () { # don't rely on the pid file, but lookup xinetd in the list of # processes pid=`ps -e -o pid,command | $AWK '$2 ~ /\/[x]inetd/ { print $1 }'` if [ "$pid" ]; then if kill -s HUP $pid; then ocf_log info "Asked xinetd to reload by sending SIGHUP to PID $pid!" else ocf_log err "Failed to send SIGHUP to xinetd PID $pid!" exit $OCF_ERR_GENERIC fi else ocf_log err "PID of xinetd not found!" exit $OCF_ERR_GENERIC fi } # check "disable = X", printing X check_service() { ocf_log "info" "$0: checking \"disable\" in $1" typeset result=$(sed -nre 's/^[ ]*disable[ ]*=[ ]*([^ ]+)[# ]*/\1/p' $1) echo "$result" } # change "disable = X" to desired value change_service() { ocf_log "info" "$0: setting \"disable = $1\" in $2" if ! sed -i -re 's/^([ ]*disable[ ]*=[ ]*)([^ ]+)([# ]*)/\1'"$1"'\3/' $2 then ocf_log "err" "Failed to change $2" return 1 fi return 0 } xup_status () { typeset disabled="$(check_service $SVCDEF)" if [ "${disabled:=no}" = no ]; then echo running return $OCF_SUCCESS elif [ "$disabled" = yes ]; then echo stopped return $OCF_NOT_RUNNING else echo unknown return $OCF_ERR_CONFIGURED fi } xup_start () { if [ "running" = "`xup_status`" ]; then ocf_log info "Service $service already started" exit $OCF_SUCCESS fi ocf_log "info" "$0: enabling in $SVCDEF" if change_service "no" $SVCDEF; then hup_inetd fi } xup_stop () { if [ "stopped" = "`xup_status`" ]; then ocf_log info "Service $service already stopped" exit $OCF_SUCCESS fi ocf_log "info" "$0: disabling in $SVCDEF" if change_service "yes" $SVCDEF; then hup_inetd fi } xup_usage () { echo "Usage: $0 {start|stop|restart|status|monitor|validate-all|meta-data}" return 0 } xup_validate_all () { if [ ! -f "$SVCDEF" ]; then ocf_log err "$0: service $service missing $SVCDEF" return $OCF_ERR_INSTALLED fi return $OCF_SUCCESS } if [ $# -ne 1 ]; then xup_usage exit $OCF_ERR_ARGS fi # These operations do not require OCF instance parameters to be set case "$1" in meta-data) meta_data exit $OCF_SUCCESS ;; usage) xup_usage exit $OCF_SUCCESS ;; esac if [ -z "$OCF_RESKEY_service" ]; then ocf_log err "Please define \"service\" parameter" if [ "$1" = "start" ]; then - exit $OCF_ERR_ARGS + exit $OCF_ERR_CONFIGURED else exit $OCF_NOT_RUNNING fi fi # Make sure the OCF_RESKEY_service is a valid xinetd service name if [ ! -f $SVCDEF ]; then ocf_log err "Service definition $SVCDEF not found!" if [ "$1" = "start" ]; then - exit $OCF_ERR_ARGS + exit $OCF_ERR_INSTALLED else exit $OCF_NOT_RUNNING fi fi # See how we were called. case "$1" in start) xup_start ;; stop) xup_stop ;; restart) $0 stop $0 start ;; status) xup_status ;; monitor) xup_status > /dev/null ;; validate-all) xup_validate_all ;; *) xup_usage exit $OCF_ERR_UNIMPLEMENTED esac exit $?