![当 UPS 切换到电池电源时,NUT 关闭脚本不运行(“返回 1”)](https://linux22.com/image/228143/%E5%BD%93%20UPS%20%E5%88%87%E6%8D%A2%E5%88%B0%E7%94%B5%E6%B1%A0%E7%94%B5%E6%BA%90%E6%97%B6%EF%BC%8CNUT%20%E5%85%B3%E9%97%AD%E8%84%9A%E6%9C%AC%E4%B8%8D%E8%BF%90%E8%A1%8C%EF%BC%88%E2%80%9C%E8%BF%94%E5%9B%9E%201%E2%80%9D%EF%BC%89.png)
我第一次在 ubuntu 上设置 UPS。我完全按照这里的说明进行操作:https://www.sobyte.net/post/2023-03/ups-nut-configuration-tutorial/
我的 UPS 是 PowerShield Defender 650。
正确的驱动程序是“blazer_usb”。
我已命名该设备屏蔽和命令如
upsc pshield
工作正常。
系统日志还显示系统确实可以识别电池电源何时被激活。例如:
01/12/2024 9:43:20 PM
Jan 12 21:43:19 barbelith upsmon[2624]: UPS pshield@localhost on battery
01/12/2024 9:43:20 PM
Jan 12 21:43:19 barbelith upssched[154701]: Timer daemon started
01/12/2024 9:43:20 PM
Jan 12 21:43:19 barbelith upssched[154701]: New timer: onbattwarn (10 seconds)
01/12/2024 9:43:20 PM
Jan 12 21:43:19 barbelith upssched[154700]: Executing command: onbattnoti
01/12/2024 9:43:20 PM
Jan 12 21:43:19 barbelith upssched[154700]: exec_cmd(/opt/scripts/upssched-cmd.sh onbattnoti) returned 1
01/12/2024 9:43:30 PM
Jan 12 21:43:29 barbelith upssched[154701]: Event: onbattwarn
01/12/2024 9:43:30 PM
Jan 12 21:43:29 barbelith upssched[154701]: exec_cmd(/opt/scripts/upssched-cmd.sh onbattwarn) returned 1
01/12/2024 9:43:45 PM
Jan 12 21:43:44 barbelith upssched[154701]: Timer queue empty, exiting
但实际的脚本(/opt/scripts/upssched-cmd.sh)似乎没有运行。即,系统没有关闭。 我怎样才能解决这个问题?
相关文件:
/opt/scripts/upssched-cmd.sh
#!/usr/bin/env bash
# from https://www.sobyte.net/post/2023-03/ups-nut-configuration-tutorial/
set -ex
exec >> /var/log/upssched-cmd.log 2>&1
# Functions mainly responsible for shutting down the system
function xpoweroff(){
logger -t upssched-cmd 'Preparing to shut down barbelith...'
logger -t upssched-cmd 'All necessary systems have been successfully shut down....'
}
# Determine the event triggered by upssched
case $1 in
onbattwarn)
logger -t upssched-cmd 'The UPS has switched to battery power, ready to safely shut down the system...'
xpoweroff
;;
ups-back-on-line)
logger -t upssched-cmd 'Municipal power has been restored...'
;;
lowbatt)
logger -t upssched-cmd 'UPS power is low, shut down the system immediately...'
xpoweroff
;;
*)
logger -t upssched-cmd "Unrecognized command: $1"
;;
esac
/etc/nut/ups.conf
[pshield]
driver = "blazer_usb"
port = "auto"
vendorid = "0665"
productid = "5161"
bus = "001"
/etc/nut/upsd.conf
LISTEN 0.0.0.0 3493
/etc/nut/upsmon.conf
SHUTDOWNCMD "/usr/sbin/poweroff"
MONITOR pshield@localhost 1 monuser PASSWORD master
NOTIFYCMD /usr/sbin/upssched
NOTIFYFLAG ONLINE SYSLOG+EXEC+WALL
NOTIFYFLAG ONBATT SYSLOG+EXEC+WALL
NOTIFYFLAG LOWBATT SYSLOG+EXEC
/etc/nut/upssched.conf
CMDSCRIPT /opt/scripts/upssched-cmd.sh
PIPEFN /run/nut/upssched.pipe
LOCKFN /run/nut/upssched.lock
AT ONBATT * START-TIMER onbattwarn 30
AT ONLINE * CANCEL-TIMER onbattwarn
AT ONBATT * EXECUTE onbattnoti