树莓派UPS自定义关机脚本(NUT)
NUT 树莓派自定义关机逻辑,上一篇文章太长了,拉出来一些:
默认关机逻辑貌似是:nut服务会在UPS发送LOWBATT
时通知机器关机,触发时机默认为ups电量剩余20%
。
如果要自定义关机设置需要进行如下设置(因为群辉提供的ups服务器在ups断电之前就关闭了,不清楚服务器在关机之前是不是会发送lowbatt消息)
1.编辑upsmon.conf,添加以下内容:
vim /etc/nut/upsmon.conf
NOTIFYCMD /sbin/upssched
NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
通知类型定义:
NOTIFYMSG type message
upsmon comes with a set of stock messages for various events. You can change them if you like.
NOTIFYMSG ONLINE "UPS %s is getting line power"
NOTIFYMSG ONBATT "Someone pulled the plug on %s"
Note that %s is replaced with the identifier of the UPS in question.
The message must be one element in the configuration file, so if it contains spaces, you must wrap it in quotes.
NOTIFYMSG NOCOMM "Someone stole UPS %s"
Possible values for type:
ONLINE
UPS is back online
ONBATT
UPS is on battery
LOWBATT
UPS is on battery and has a low battery (is critical)
FSD
UPS is being shutdown by the primary (FSD = "Forced Shutdown")
COMMOK
Communications established with the UPS
COMMBAD
Communications lost to the UPS
SHUTDOWN
The system is being shutdown
REPLBATT
The UPS battery is bad and needs to be replaced
NOCOMM
A UPS is unavailable (can’t be contacted for monitoring)
NOTIFYFLAG type flag[+flag]…
By default, upsmon sends walls global messages to all logged in users) via /bin/wall and writes to the syslog when things happen. Except for Windows where upsmon only writes to the syslog by default. You can change this.
Examples:
NOTIFYFLAG ONLINE SYSLOG
NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
Possible values for the flags:
SYSLOG
Write the message to the syslog
WALL
Write the message to all users with /bin/wall
EXEC
Execute NOTIFYCMD (see above) with the message
IGNORE
Don’t do anything
If you use IGNORE, don’t use any other flags on the same line.
2.修改upssched.conf添加以下内容
vim /etc/nut/upssched.conf
CMDSCRIPT /etc/nut/upssched-cmd #编写此脚本设置
# NOTIFYCMD /sbin/upssched
# NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
PIPEFN /etc/nut/upssched.pipe
LOCKFN /etc/nut/upssched.lock
AT ONBATT * START-TIMER power-off 60
AT ONLINE * CANCEL-TIMER power-off
AT ONLINE * EXECUTE power-on
3.编辑upssched-cmd脚本
vim /etc/nut/upssched-cmd
文件内容:
#!/bin/sh
case $1 in
onbatt)
logger -t upssched-cmd "UPS running on battery"
# do somethings ,e.g.send email \ wechat
/usr/sbin/upsmon -c fsd
;;
power-off)
logger -t upssched-cmd "UPS running on battery power off"
/usr/sbin/upsmon -c fsd
;;
shutdowncritical)
logger -t upssched-cmd "UPS on battery critical, forced shutdown"
/usr/sbin/upsmon -c fsd
;;
upsgone)
logger -t upssched-cmd "UPS has been gone too long, can't reach"
;;
*)
logger -t upssched-cmd "Unrecognized command: $1"
;;
esac
修改完成之后重启服务。
相关文章
- 5年程序员问我:什么是断言?
- crudapi零代码开发平台应用场景和成功案例
- “上云”路上的银行业,现在过的怎么样了?
- 人工智能项目可能面临失败的6个原因
- 什么是文档归档?——apipost
- 首席信息安全官的角色将会有哪些变化?
- 在云中进行灾难恢复的5种有效方式
- Web服务器的底层原理与实现
- 如何通过云安全态势管理保障云端数据安全和抵御网络威胁
- selenium常用操作
- 股票代码域名的魅力,电子烟龙头悦刻注册rlx.top
- Zookeeper详细使用解析!分布式架构中的协调服务框架最佳选型实践
- RESTful风格接口开發
- 遍布全球的汽车保养Ltd
- 入门Linux
- SQLALchemy框架
- 深圳专项资金扶持独立站,域名或将迎来新一轮爆发
- 某工程师透露,网站收录慢的真正原因
- 阿里云ECS服务器的使用感受
- 容器场景下云原生可观测性最佳实践