#!/bin/sh
#
# Copyright 2007 VMware, Inc.  All rights reserved.
#
# moxa_v2100_wdt:
#   Moxa DA-820 ESXi 5.x superio driver
#
# chkconfig: on 91 09
# description: Moxa DA-820 ESXi 5.x superio driver
#

MOXA_V2100_WDT="/usr/lib/vmware/vmkmod/moxa_v2100_wdt"

#
# Sanity check
#
[ -e "${MOXA_V2100_WDT}" ] || exit 0

#
# Log action
#
moxa_v2100_wdt_log() {
   echo "${1}"
   logger moxa_v2100_wdt "${1}"
}

#
# Start moxa_v2100_wdt
#
moxa_v2100_wdt_start() {
   moxa_v2100_wdt_log "Load moxa_v2100_wdt module"
   vmkload_mod ${MOXA_V2100_WDT}
}

#
# Stop moxa_v2100_wdt
#
moxa_v2100_wdt_stop() {
   moxa_v2100_wdt_log "Unload moxa_v2100_wdt module"
   vmkload_mod -u moxa_v2100_wdt
}

#
# Process comand line options
#
case "${1}" in
   start)
      moxa_v2100_wdt_start
   ;;

   stop)
      moxa_v2100_wdt_stop
   ;;

   status)
      if [ -n "$(vmkload_mod -l |grep "moxa_v2100_wdt")" ] ; then
         echo "moxa_v2100_wdt is loadded"
         exit 0
      else
         echo "moxa_v2100_wdt is not loadded"
         exit 3
      fi
   ;;

   restart)
      moxa_v2100_wdt_stop

      # wait till all instances have stopped
      while [ -n "$(vmkload_mod -l |grep "moxa_v2100_wdt")"  ] ; do
         sleep 1
      done

      moxa_v2100_wdt_start
   ;;

   *)
      echo "Usage: $(basename "$0") {start|stop|status|restart}"
      exit 1
   ;;
esac

