우분투에서 처음으로 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