#!/bin/sh
#
# Script to start ifacefailover2.sh in _respawnService mode
# Starts ifacefailover2.sh
#

exec 2> /dev/null

ROOTACT=_REPLACEWITHROOTACT_
export ROOTACT

[ -f "/var/run/lrrsystem" ] && . "/var/run/lrrsystem"
. "${ROOTACT}/lrr/com/system_setting.sh"
_system_api_loaded 2> /dev/null || . "${ROOTACT}/lrr/com/system_api.sh"
. "${ROOTACT}/lrr/com/functionsservice.sh"
[ -f "${ROOTACT}/usr/etc/lrr/_parameters.sh" ] && . "${ROOTACT}/usr/etc/lrr/_parameters.sh"

OPTIONS=""
SERVICE="ipfailover2"
SERVICE_RUNDIR="${ROOTACT}/lrr/failovermgr"
SERVICE_COMMAND="ifacefailover2.sh"
COMMAND="${SERVICE_RUNDIR}/${SERVICE_COMMAND}"

initServiceDataDefaultVars

usage() {
    echo "Usage: $0 {start|stop|restart|clean}"
    echo " Where options are:"
    echo "  -h|--help   Print this help message"
}

serviceCommand() {
    echo "${COMMAND} ${OPTIONS}"
}

stopService() {
    IPFAILOVER2_PID=$(getPids "${SERVICE_COMMAND}" ifacerescuesvp2.sh)
    for p in $IPFAILOVER2_PID; do
        kill -9 $p
    done
}

abortService() {
    IPF2SERVICE_PID=$(getPids "${SERVICE}")
    for p in $IPF2SERVICE_PID; do
        [ "$p" != "$$" ] && kill -9 $p
    done
    stopService
    cleanServiceDataFiles
}

case "$1" in
  *)
     handleParams $*
     ;;
esac

exit $?
