Forzare il tempo di attesa di shutdown in nut

From RVM Wiki
Jump to navigation Jump to search

Singola macchina collegata ad un UPS

ups.delay.shutdown
  • The upsmon master notices and sets "FSD" - the "forced shutdown" flag to tell all slave systems that it will soon power down the load.
  • upsmon slave systems see "FSD" and:
   generate a NOTIFY_SHUTDOWN event
   wait FINALDELAY seconds - typically 5
   call their SHUTDOWNCMD
   disconnect from upsd 
  • The upsmon master system waits up to HOSTSYNC seconds (typically 15) for the slaves to disconnect from upsd. If any are connected after this time, upsmon stops waiting and proceeds with the shutdown process.
  • The upsmon master:
   generates a NOTIFY_SHUTDOWN event
   waits FINALDELAY seconds - typically 5
   creates the POWERDOWNFLAG file - usually /etc/killpower
   calls the SHUTDOWNCMD 
  • On most systems, init takes over, kills your processes, syncs and unmounts some filesystems, and remounts some read-only.

init then runs your shutdown script. This checks for the POWERDOWNFLAG, finds it, and tells the UPS driver(s) to power off the load.

  • The system loses power WHEN THE UPS REACHES ups.delay.shutdown timeout OR DRAINS BATTERY
  • Occorreq uindi calcolare quanto tempo occorre al sistema per effettuare uno shutdown completo, ed impostare questo valore ad un tempo in secondi superiore.

Macchina server che deve attendere lo shutdown lungo di altre macchine

  • In questo caso occorre iniziare lo shutdown pochi minuti dopo il power outage, per poter attendere abbastanza tempo
  • Occorre usare upssched sulla macchina master
  • Impostare come notifycmd upssched e poi i notifyflag desiderati:
sudoedit /etc/nut/upsmon.conf 


...
NOTIFYCMD /sbin/upssched
...
NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC
NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
NOTIFYFLAG LOWBATT SYSLOG+WALL+EXEC
NOTIFYFLAG COMMOK SYSLOG+WALL+EXEC
NOTIFYFLAG COMMBAD SYSLOG+WALL+EXEC
NOTIFYFLAG SHUTDOWN SYSLOG+WALL+EXEC
NOTIFYFLAG REPLBATT SYSLOG+WALL+EXEC
NOTIFYFLAG NOCOMM SYSLOG+WALL+EXEC
NOTIFYFLAG FSD SYSLOG+WALL+EXEC
  • Dichiarare lo script che gestirà gli eventi di upssched:
sudoedit /etc/nut/upssched.conf
CMDSCRIPT /usr/local/bin/nut-upssched
  • Impostare i file di supporto:
LOCKFN /var/lib/nut/upssched.lock
PIPEFN /var/lib/nut/upssched.pipe
  • Impostare il timer che parte all'evento ONBATT. Dopo 60 secondi, si genera l'evento onbatt
AT ONBATT * START-TIMER onbatt 60
  • Se per caso ritorna la corrente prima di 60o secondi, il timer viene azzerato
AT ONLINE * CANCEL-TIMER onbatt
  • Il nome del timer verrà passato quindi allo script CMDSCRIPT quando esso scadrà. Noi vogliamo che quando scade questo timer, venga attivato lo shutdown:
sudoedit /usr/local/bin/nut-upssched
#!/bin/bash

case $1 in
        onbatt)
                echo "The UPS has been on battery for 60 sec. Shutting down."
                /usr/bin/logger -t upsschedcmd "The UPS has been on battery for 60 sec. Shutting down."
                /sbin/upsmon -c fsd
                ;;
        *)
                echo "Unrecognized command: $1"
                /usr/bin/logger -t upsschedcmd "Unrecognized command: $1"
                ;;
esac
sudo chmod +x /usr/local/bin/nut-upssched
  • In questo modo TUTTE le macchine iniziano lo shutdown DOPO 60 SECONDI ON BATTERY.
  • Bisogna dire al MASTER di attendere il TEMPO che vogliamo prima di iniziare davvero la procedura di shutdown, specificando i secondi da attendere in
sudoedit /etc/nut/upsmon.conf 
FINALDELAY 599
  • Restartare il master
sudo invoke-rc.d nut restart
  • Scollegare l'alimentazione ed attendere 60 secondi, guardando nel sysylog:
sudo tail -f /var/log/syslog
Apr 16 22:52:52 mymasterups upsmon[1873]: UPS apc_smartups_3000_xl@localhost on ba
ttery
Apr 16 22:52:52 mymasterups upssched[2026]: Timer daemon started
Apr 16 22:52:53 mymasterups upssched[2026]: New timer: onbatt (60 seconds)
Apr 16 22:53:53 mymasterups upssched[2026]: Event: onbatt 
Apr 16 22:53:53 mymasterups upsschedcmd: The UPS has been on battery for 60 sec. Shutting down.
Apr 16 22:53:53 mymasterups upsmon[1873]: Signal 10: User requested FSD
Apr 16 22:53:53 mymasterups upsd[1869]: Client local_mon@127.0.0.1 set FSD on UPS [apc_smartups_3000_xl]
Apr 16 22:54:03 mymasterups upsmon[1873]: Executing automatic power-fail shutdown
Apr 16 22:54:03 mymasterups upsmon[1873]: Auto logout and shutdown proceeding
Apr 16 22:54:08 mymasterups upssched[2026]: Timer queue empty, exiting
  • A questo punto, le macchine slave devono cominciare IMMEDIATAMENTE lo shutdown
  • Dopo il FINALDELAY di 599 secondi, partirà anche lo shutdown locale
Apr 16 23:04:02 mymasterups shutdown[2058]: shutting down for system halt
Apr 16 23:04:02 mymasterups init: Switching to runlevel: 0
Apr 16 23:04:03 mymasterups upsd[1869]: mainloop: Interrupted system call
Apr 16 23:04:03 mymasterups upsd[1869]: Signal 15: exiting
Apr 16 23:04:03 mymasterups apcsmart[1867]: Signal 15: exiting
Apr 16 23:04:03 mymasterups acpid: exiting

Riferimenti