Title: NUT - Network Ups Tool Subject: Have all your computers shutdown before ups goes down. One master computer has a serial to the ups. Slave computers listen to the masater. http://localhost/cgi-bin/multimon.cgi Once upsd is running: Look to the file: /var/state/ups/smartups-ttyS0 Run this: /usr/local/ups/bin/upsc localhost Enviornmet: ----- Serial ---------- Network Running NUT apps | UPS |---------| Computer |------| 1. module driver | |---------| (Master) | | 2. upsd ----- Power | ---------- | 3. upsmon as master | | | ---------- | |-| Computer |------| 1. upsmon as slave | (Slave) | ---------- Communication: -------- shared mem network | UPS | serial /var/state/ups /----->cgi-bin |hardware|<------->driver<--------------->upsd<------>upsmon -------- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# ############## On the master server: ############## #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# 1. install gd and gd-devel. 2. tar -zxvpf nut-0.50.0.tar.gz 3. cd nut-0.50.0/ 4. ./configure 5. make 6. make cgi 7. make install 8. make install-cgi 9. chmod 666 /dev/ttyS0 10 Create the config files: hosts.conf, multimon.conf, ups.conf, upsd.conf, upsd.users, upsmon.conf, upssched.conf, upsset.confups.conf # ----------------ups.conf --------------------- cat > /usr/local/ups/etc/ups.conf << UPS_CONF # List all the UPSes connected to this system via serial or usb. # Used by upsdrvctl (to start/stop driver ) and upsd [ups] driver = apcsmart port = /dev/ttyS0 cable = 940-0024C UPS_CONF #-------------------upsd.conf------------------- cat > /usr/local/ups/etc/upsd.conf << UPSD_CONF # Contains passwords # File sets the Access Control Lists, and access rights # ACL # ACCESS [] ACL all 0.0.0.0/0 ACL localhost 127.0.0.1/32 ACL webber 192.168.0.10/24 ACL internal 192.168.0.0/24 ACCESS grant all localhost My_PassWord ACCESS grant all webber My_PassWord ACCESS grant monitor internal My_PassWord ACCESS grant monitor all My_PassWord # If successful, starting upsmon on slave will leave this in syslog. #Jul 23 13:15:18 mother upsd[25088]: Connection from 192.168.0.10 #Jul 23 13:15:18 mother upsd[25088]: Client 192.168.0.10 logged into UPS [ups] UPSD_CONF #-------------------upsd.users-------------------- cat > /usr/local/ups/etc/upsd.users << UPSD_USERS # Settings set on per user basis. # Sets users, passwds, commands, and "connect-from" hosts. [admin] password = mypassword allowfrom = all actions = SET instcmds = ALL UPSD_USERS #-------------------hosts.conf--------------------- cat > /usr/local/ups/etc/hosts.conf << HOSTS_CONF # Controls which hosts appear in the CGI programs. # multimon, upsstats, and upsimage use this file. # List systems running upsd that you wish to monitor. MONITOR ups@localhost "Yo Mama UPS" HOSTS_CONF #-------------------multimon.conf------------------ cat > /usr/local/ups/etc/multimon.conf << MULTIMON_CONF # Sets web page field layout # Run this, and see what fields are returned: # /usr/local/ups/bin/upsc localhost TEMPF FIELD MODEL "Model" "" FIELD STATUS "Status" "" FIELD battpct "Battery Chg" "%" FIELD BATTVOLT "Battery Voltage" "VDC" FIELD BATTDATE "Battery Date" "" FIELD loadpct "UPS Load" "%" FIELD UPSTEMP "UPS Temp" "" FIELD utility "Utility" "VAC" FIELD OUTVOLT "Output Voltage" "VAC" FIELD LOWXFER "Low Xfer" "VAC" FIELD HIGHXFER "High Xfer" "VAC" FIELD ACFREQ "AC Frequency" "Hz" FIELD UPSIDENT "UPS Identifier" "" FIELD MFR "Manufacturer" "" MULTIMON_CONF #-------------------upsmon.conf--------------------- cat > /usr/local/ups/etc/upsmon.conf << UPSMON_CONF # Must chown this file to a user nutmon. # List systems you want to monitor, but not all must run mond. # must match ACCESS entry in that system's upsd.conf. # MONITOR ("master"|"slave") RUN_AS_USER nutmon MONITOR ups@mother.stilen.com 1 mypassword master MONITOR webber.stilen.com 0 mypassword slave MINSUPPLIES 1 SHUTDOWNCMD "/sbin/shutdown -h +0" NOTIFYCMD /usr/local/ups/bin/notifyme POLLFREQ 5 POLLFREQALERT 5 HOSTSYNC 15 DEADTIME 15 POWERDOWNFLAG /etc/killpower RBWARNTIME 43200 NOCOMMWARNTIME 300 FINALDELAY 5 UPSMON_CONF #-------------------upssched.conf-------------------- cat > /usr/local/ups/etc/upsmon.conf << UPSSCHED_CONF # I haven CMDSCRIPT /usr/local/ups/bin/upssched-cmd PIPEFN /var/run/upssched.pipe UPSSCHED_CONF #----------------------------------------------- 11. Start the driver /usr/local/ups/bin/upsdrvctl start 12. Start upsd /usr/local/ups/sbin/upsd 13. Start monitor /usr/local/ups/sbin/upsmon 14. Start logging /usr/local/ups/bin/upslog \ ups@mother.stilen.com \ /var/log/ups \ 5 \ %TIME @Y@m@d @H@M@S% \ %VAR battpct% \ %VAR BATTVOLT% \ %VAR BATTDATE% \ %VAR UPSTEMPE% \ %VAR loadpct% \ %VAR utility% \ %VAR OUTVOLT% \ %VAR LOWXFER% \ %VAR HIGHXFER% \ %VAR ACFREQ% \ %VAR UPSIDENT% # Test it: # Every value known to upsd about your ups is returned by upsc # /usr/local/ups/bin/upsc localhost # over udp # /usr/local/ups/bin/upsct localhost # over tcp # changing read/write settings # /usr/local/ups/bin/upsct2 # View the configurable options # /usr/local/ups/bin/upscmd -l localhost # To stop stuff correctly, and /var/state/ups will be empty: # /usr/local/ups/sbin/upsmon -c stop # /usr/local/ups/sbin/upsd stop # /usr/local/ups/bin/upsdrvctl stop # To start stuff correctly: # /usr/local/ups/bin/upsdrvctl start # /usr/local/ups/sbin/upsd # /usr/local/ups/sbin/upsmon # You can add "&refresh=nn" to your multimon.cgi URL if you want it to # instruct your web browser to reload the page every nn seconds. cat >> /usr/local/apache/htdocs/ups.html << UPS_HTML UPS UPS_HTML #http://stilen.com/ups/multimon.cgi?host=ups@localhost&use_celsius=0&refresh=05 # Testing shutdowns /usr/local/ups/bin/upsdrvctl -t 14. Install on slave machine. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# ############## On the slave server: ############## #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# 15. Setup slave conifg files: #-------------------upsmon.conf--------------------- cat > /usr/local/ups/etc/upsmon.conf << UPSMON_CONF # setup the ups the machine is monitoring. # Fill in path to NOTIFYCMD (any prog that takes double quoted string) RUN_AS_USER ups MONITOR ups@mother.stilen.com 1 mypassword slave MINSUPPLIES 1 SHUTDOWNCMD "/sbin/shutdown -h +0" NOTIFYCMD /usr/local/sbin/ups-shutdown-init POLLFREQ 5 POLLFREQALERT 5 HOSTSYNC 15 DEADTIME 15 POWERDOWNFLAG /var/lib/ups/killpower RBWARNTIME 43200 NOCOMMWARNTIME 300 FINALDELAY 5 UPSMON_CONF #-------------------upssched.conf--------------------- cat > /usr/local/ups/etc/upssched.conf << UPSSCHED_CONF CMDSCRIPT /usr/local/bin/upssched-cmd CMDSCRIPT /usr/local/sbin/ups-shutdown-init PIPEFN /var/lib/ups/upssched.pipe AT ONBATT * START-TIMER onbattwarn 120 AT ONLINE * CANCEL-TIMER onbattwarn UPSSCHED_CONF 15. Run upsmon. /usr/local/bin/upsmon #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # Startup scripts are not included with the package. #!/bin/bash # # Purpsose: Restart Netwrok UPS tool on restart # description: The ups daemon automatically starts a shutdown # processname: upsd # config: /usr/local/ups/etc PROGRAM=/usr/local/ups case "$1" in start) echo -e $"Starting $0:\n " ${PROGRAM}/bin/upsdrvctl start ${PROGRAM}/sbin/upsd ${PROGRAM}/sbin/upsmon ;; stop) echo -n $"Stopping $0: " ${PROGRAM}/sbin/upsmon -c stop ${PROGRAM}/sbin/upsd -c stop ${PROGRAM}/bin/upsdrvctl stop ;; restart) $0 stop $0 start ;; *) echo "Usage: $0 {start|stop|restart}" esac