Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # These are config files to my answer to the following question:
- # http://serverfault.com/questions/462993/vmware-esxi-shutdown-triggered-by-apc-ups-connected-via-usb
- /etc/nut/nut.conf:
- MODE=netserver
- /etc/nut/ups.conf
- # UPS Variables:
- # battery.runtime.low: 660
- # input.sensitivity: low
- # ups.beeper.status: disabled
- [smart-ups]
- driver = usbhid-ups
- port = auto
- desc = "ESXi Server APC Smart-UPS"
- offdelay = 180
- ondelay = 240
- pollfreq = 30
- /etc/nut/upsd.conf:
- LISTEN 127.0.0.1
- LISTEN 172.16.4.250
- /etc/nut/upsd.users:
- [upsmon]
- password = ********
- upsmon master
- actions = SET
- instcmds = ALL
- [esxi]
- password = ********
- upsmon slave
- /etc/nut/upsmon.conf:
- MONITOR smart-ups@localhost 1 upsmon ******** master
- #SHUTDOWNCMD "/sbin/shutdown -H now"
- SHUTDOWNCMD "/usr/bin/logger \"Should run /sbin/shutdown -H now, but waiting for ESXi host instead\""
- NOTIFYCMD /sbin/upssched
- NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC
- NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
- NOTIFYFLAG COMMBAD SYSLOG+WALL+EXEC
- NOTIFYFLAG NOCOMM SYSLOG+WALL+EXEC
- /etc/nut/upssched.conf:
- CMDSCRIPT /usr/local/sbin/upssched-cmd
- PIPEFN /var/run/nut/upssched.pipe
- LOCKFN /var/run/nut/upssched.lock
- AT ONBATT * START-TIMER ups-on-battery 300
- AT ONLINE * CANCEL-TIMER ups-on-battery
- AT NOCOMM * START-TIMER ups-no-comm 30
- AT COMMBAD * START-TIMER ups-comm-bad 30
- /usr/local/sbin/upssched-cmd:
- #!/bin/sh
- NAME=`basename $0`
- LOGGER="/usr/bin/logger -t $NAME"
- UPSCMD="/bin/upscmd -uupsmon -p*******"
- UPSMON="/sbin/upsmon"
- case $1 in
- ups-on-battery)
- $LOGGER "Timer event '$1' fired, executing UPS panel test..."
- $UPSCMD smart-ups test.panel.start
- $UPSMON -c fsd
- ;;
- ups-no-comm|ups-comm-bad)
- $LOGGER "Timer event '$1' fired, restarting NUT..."
- /usr/sbin/service nut stop
- sleep 15
- /usr/sbin/service nut start
- ;;
- *)
- $LOGGER "Unrecognized command: '$1'"
- ;;
- esac
- /etc/vmware-tools/scripts/poweroff-vm-default.d/ups-monitor:
- #!/bin/bash
- #
- # /etc/vmware-tools/scripts/poweroff-vm-default.d/ups-monitor
- # Written by Oleg Semyonov
- #
- # This script should shutdown UPS if powerdown flag is set (/etc/killpower, for intance).
- # It is called by the ESXi when it powers off all VMs (and this one should be last).
- # UPS should give enought time to ESXi to completely shutdown. Usually it takes around 2-3
- # minutes since all VMs are already suspended to this moment.
- UPSMON=/etc/init.d/ups-monitor
- MAXWAIT=15
- if [ -x $UPSMON ]; then
- # Looking for the powerdown flag. If not found - wait for some time.
- # The ESXi host may be quicker than local upsmon and shutdown this
- # machine before the local upsmon creates the powerdown flag.
- flag=`sed -ne 's#^ *POWERDOWNFLAG *\(.*\)$#\1#p' /etc/nut/upsmon.conf`
- echo -n "Looking for the powerdown flag ($MAXWAIT seconds max)"
- for ((i = 1; i <= $MAXWAIT; i++)); do
- [ -f "$flag" ] && break
- sleep 1
- echo -n "."
- done
- # Finally shutdown the UPS if flag has appeared (UPS-initiated shutdown)
- if [ ! -f "$flag" ]; then
- echo " - not found, just halt the machine"
- else
- echo " - found"
- $UPSMON poweroff
- fi
- fi
- # Return success regardless of script result
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement