这里使用的 nut 对ups 进行管理 ups 使用的是 tgbox850
安装 nut
nut 的配置挺多注释的 可以使用 sudo cat /etc/nut/nut.conf | grep -v '^#'
查看除去注释后的内容
向 /etc/nut/nut.conf
写入以下内容,配置为单机模式
向 /etc/nut/upsd.conf
写入以下内容配置监听
向 /etc/nut/upsd.users
添加下列内容增加用户
1 2 3 4 5 [admin] password = foobar159874 upsmon master actions = set actions = fsd
向 /etc/nut/ups.conf
增加 ups 信息
1 2 3 4 5 6 7 maxretry = 3 [tgbox850] driver = "usbhid-ups" port = "auto" vendorid = "0463" product = "SANTAK TG-BOX"
向 /etc/nut/upsmon.conf
写入以下内容 配置 ups 断电后的行为
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 RUN_AS_USER root MINSUPPLIES 1 SHUTDOWNCMD "/sbin/shutdown -h +0" POLLFREQ 5 POLLFREQALERT 5 HOSTSYNC 15 DEADTIME 15 POWERDOWNFLAG /etc/killpower RBWARNTIME 43200 NOCOMMWARNTIME 300 FINALDELAY 5 MONITOR tgbox850@localhost 1 admin foobar159874 master NOTIFYCMD /sbin/upssched NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC NOTIFYFLAG REPLBATT SYSLOG+WALL+EXEC
/etc/nut/upssched.conf
配置 ups 事件触发
1 2 3 4 5 6 7 8 9 10 11 12 13 CMDSCRIPT /bin/upssched-cmd PIPEFN /run/nut/upssched.pipe LOCKFN /run/nut/upssched.lock # Send alerts immediately on change in line power AT ONBATT * EXECUTE onbatt AT ONLINE * EXECUTE onpower # Shutdown after 1 minutes on battery AT ONBATT * START-TIMER onbatt_shutdown 60 # Cancel timer if power's restored AT ONLINE * CANCEL-TIMER onbatt_shutdown
向 /bin/upssched-cmd 写入以下内容,将 ups 事件 记录为日志
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 #! /bin/sh case $1 in onbatt) message="Power outage, on battery" logger -t upssched-cmd "$message " ;; onpower) message="Power restored" logger -t upssched-cmd "$message " ;; onbatt_shutdown) message="Triggering shutdown after 1 minutes on battery" logger -t upssched-cmd "$message " /sbin/upsmon -c fsd ;; *) logger -t upssched-cmd "Unrecognized command: $1 " ;; esac
全部配置好后 ups 就可以用了
你可以使用 upsc tgbox850@localhost
查看 ups 状态。 或者直接拔除 ups 的电源,这时不出意外的话所有打开终端都会打印 ups 的事件