Skip to content

Commit

Permalink
Ironed out bugs in XenServer shutdown script
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan committed Jul 11, 2017
1 parent a47151d commit 2a23c5e
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 78 deletions.
4 changes: 2 additions & 2 deletions master/upsmon.conf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ RUN_AS_USER root
#
# slave: means this system shuts down immediately when power goes critical.

MONITOR UPS-ES-07@localhost 0 upsmaster <masterpassword> master
MONITOR <upsname>@localhost 0 upsmaster <masterpassword> master

# --------------------------------------------------------------------------

Expand Down Expand Up @@ -149,7 +149,7 @@ NOTIFYMSG NOPARENT "upsmon parent process died - shutdown impossible"

NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC
NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
NOTIFYFLAG LOWBATT SYSLOG+WALL
NOTIFYFLAG LOWBATT SYSLOG+WALL+EXEC
NOTIFYFLAG FSD SYSLOG+WALL+EXEC
NOTIFYFLAG COMMOK SYSLOG+WALL+EXEC
NOTIFYFLAG COMMBAD SYSLOG+WALL+EXEC
Expand Down
25 changes: 13 additions & 12 deletions master/upssched-cmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,27 @@ main() {

case $1 in

replbatt)
replace_battery)
notification_subject="Bad Battery"
notification_body="UPS ${ups_name} has a bad battery, replacement necessary"
send_notification_email "${notification_subject}" "${notification_body}"
;;

onbatt)
on_battery
notification_subject="On Battery"
notification_body="UPS ${ups_name} has been on battery for over five minutes"
send_notification_email "${notification_subject}" "${notification_body}"
touch /etc/nut/shutdown.key
;;

fsd)
low_battery)
notification_subject="Low Battery"
notification_body="UPS ${ups_name} battery is getting low. Client shutdown will happen soon"
send_notification_email "${notification_subject}" "${notification_body}"
touch /etc/nut/shutdown.key
;;

forced_shutdown)
notification_subject="Forced Shutdown in progress"
notification_body="UPS ${ups_name} is forcing shutdown of this system"
send_notification_email "${notification_subject}" "${notification_body}"
Expand All @@ -40,25 +47,19 @@ main() {
send_notification_email "${notification_subject}" "${notification_body}"
;;

online)
on_line)
notification_subject="Power Restored"
notification_body="Power has been restored to UPS ${ups_name}."
send_notification_email "${notification_subject}" "${notification_body}"
;;

nocomm)
notification_subject="Unavailable"
notification_body="Communications with UPS ${ups_name} cannot be established"
send_notification_email "${notification_subject}" "${notification_body}"
;;

commbad)
communications_bad)
notification_subject="Communication Lost"
notification_body="Communications with the UPS ${ups_name} are lost"
send_notification_email "${notification_subject}" "${notification_body}"
;;

commok)
communications_ok)
notification_subject="Communication Restored"
notification_body="Communications with the UPS ${ups_name} are established"
send_notification_email "${notification_subject}" "${notification_body}"
Expand Down
40 changes: 22 additions & 18 deletions master/upssched.conf
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,34 @@ LOCKFN "/etc/nut/upssched.lock"
# EXECUTE <command>
# Immediately pass <command> as an argument to CMDSCRIPT.

# Will start the timer "onbatt" if any monitors send an ONBATT event
# If the timer reachs zero it will execute "onbatt" in the CMDSCRIPT script
AT ONBATT * START-TIMER onbatt 300
# Will start the timer "on_battery" if any monitors send an ONBATT event
# If the timer reachs zero it will execute "on_battery" in the CMDSCRIPT script
AT ONBATT * START-TIMER on_battery 300

# Will cancel the timer "onbatt" if any monitors send an ONLINE event and execute
# "online" in the CMDSCRIPT script
AT ONLINE * CANCEL-TIMER onbatt online
# Will cancel the timer "on_battery" if any monitors send an ONLINE event and execute
# "on_line" in the CMDSCRIPT script
AT ONLINE * CANCEL-TIMER on_battery on_line

# Will execute "onbatt" in the CMDSCRIPT script if any monitors send a LOWBATT event
AT LOWBATT * EXECUTE onbatt
# Will execute "low_battery" in the CMDSCRIPT script if any monitors send a LOWBATT event
AT LOWBATT * EXECUTE low_battery

# Will start the timer "commbad" if any monitors send a COMMBAD event
# If the timer reachs zero it will execute "commbad" in the CMDSCRIPT script
AT COMMBAD * START-TIMER commbad 30
# Will start the timer "communications_bad" if any monitors send a COMMBAD event
# If the timer reachs zero it will execute "communications_bad" in the CMDSCRIPT script
AT COMMBAD * START-TIMER communications_bad 30

# Will cancel the timer "commbad" if any monitors send an COMMOK event and execute
# "commok" in the CMDSCRIPT script
AT COMMOK * CANCEL-TIMER commbad commok
# Will cancel the timer "communications_bad" if any monitors send an COMMOK event and execute
# "communications_ok" in the CMDSCRIPT script
AT COMMOK * CANCEL-TIMER communications_bad communications_ok

# Will execute "commbad" in the CMDSCRIPT script if any monitors send a NOCOMM event
AT NOCOMM * EXECUTE commbad
# Will start the timer "communications_bad" if any monitors send a NOCOMM event
# If the timer reachs zero it will execute "communications_bad" in the CMDSCRIPT script
AT NOCOMM * START-TIMER communications_bad 30

# Will execute "powerdown" in the CMDSCRIPT script if any monitors send a SHUTDOWN event
AT SHUTDOWN * EXECUTE powerdown

# Will execute "replbatt" in the CMDSCRIPT script if any monitors send a REPLBATT event
AT REPLBATT * EXECUTE replbatt
# Will execute "replace_battery" in the CMDSCRIPT script if any monitors send a REPLBATT event
AT REPLBATT * EXECUTE replace_battery

# Will execute "forced_shutdown" in the CMDSCRIPT script if any monitors send a FSD event
AT FSD * EXECUTE forced_shutdown
58 changes: 58 additions & 0 deletions misc/evolution500.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# dummy-ups example power sequence file
#
# Base is the same as .dev files, generated using:
# $ upsc ups@host > evolution500.seq
#
# TIMER have then been added to generate power events.

battery.charge: 90
battery.charge.low: 30
battery.runtime: 3690
battery.voltage: 230.0
driver.name: usbhid-ups
driver.parameter.port: auto
driver.version: 2.2.0
driver.version.data: MGE HID 0.7
driver.version.internal: 0.23
input.frequency: 49.0
input.transfer.boost.low: 184.0
input.transfer.high: 294.0
input.transfer.low: 160.0
input.transfer.trim.high: 265.0
input.voltage: 230.0
outlet.desc: Main Outlet
outlet.id: 0
outlet.switchable: 0
outlet.1.autoswitch.charge.low: 0
outlet.1.delay.shutdown: -1
outlet.1.delay.start: -1
outlet.1.desc: PowerShare Outlet 1
outlet.1.id: 1
outlet.1.switch: 1
outlet.1.switchable: 1
outlet.2.autoswitch.charge.low: 0
outlet.2.delay.shutdown: -1
outlet.2.delay.start: -1
outlet.2.desc: PowerShare Outlet 2
outlet.2.id: 2
outlet.2.switch: 1
outlet.2.switchable: 1
output.current: 0.00
output.frequency: 49.0
output.voltage: 230.0
output.voltage.nominal: 230.0
ups.delay.shutdown: -1
ups.delay.start: -10
ups.load: 10
ups.mfr: MGE UPS SYSTEMS
ups.model: Pulsar Evolution 500
ups.power.nominal: 500
ups.serial: AV2G3300L
ups.status: OL CHRG
ups.test.interval: 604800
ups.test.result: Done and passed
TIMER 300
ups.status: OB DISCHRG
TIMER 300
ups.status: OB LB DISCHRG
TIMER 60
File renamed without changes.
2 changes: 1 addition & 1 deletion slave/osx/upsmon.conf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ RUN_AS_USER root
#
# slave: means this system shuts down immediately when power goes critical.

MONITOR UPS-HS-02@upsmon 1 upsslave <slavepassword> slave
MONITOR <upsname>@upsmon 1 upsslave <slavepassword> slave

# --------------------------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions slave/xen/upsmon.conf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ RUN_AS_USER root
#
# slave: means this system shuts down immediately when power goes critical.

MONITOR ups01@utilp 1 upsslave 5Q8z60 slave
MONITOR <upsname>@upsmon 1 upsslave <slavepassword> slave

# --------------------------------------------------------------------------

Expand All @@ -55,7 +55,7 @@ MINSUPPLIES 1

# upsmon runs this command when the system needs to be brought down.

SHUTDOWNCMD "/etc/ups/xenshutdown.sh"
SHUTDOWNCMD "/etc/ups/xen-shutdown.sh"

# --------------------------------------------------------------------------

Expand Down
Loading

0 comments on commit 2a23c5e

Please sign in to comment.