惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
P
Proofpoint News Feed
The Last Watchdog
The Last Watchdog
S
Secure Thoughts
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
N
News | PayPal Newsroom
Application and Cybersecurity Blog
Application and Cybersecurity Blog
O
OpenAI News
S
Security @ Cisco Blogs
宝玉的分享
宝玉的分享
Hacker News: Ask HN
Hacker News: Ask HN
T
Troy Hunt's Blog
Google Online Security Blog
Google Online Security Blog
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
TaoSecurity Blog
TaoSecurity Blog
Help Net Security
Help Net Security
Latest news
Latest news
NISL@THU
NISL@THU
S
Security Affairs
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
博客园 - 聂微东
AI
AI
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Recent Announcements
Recent Announcements
P
Privacy & Cybersecurity Law Blog
小众软件
小众软件
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
AWS News Blog
AWS News Blog
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
I
InfoQ
Schneier on Security
Schneier on Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
The Exploit Database - CXSecurity.com
IT之家
IT之家
T
Threatpost
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
腾讯CDC
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
N
News and Events Feed by Topic
L
LINUX DO - 最新话题
F
Full Disclosure
大猫的无限游戏
大猫的无限游戏
H
Heimdal Security Blog
S
SegmentFault 最新的问题

Zar_SY | 博客

「圣地巡礼」圣诞快乐,有希——凉宫春日(冬) - Zar_SY | 博客 2025年小结 - Zar_SY | 博客 「白金指北」PSVITA 舰队Collection 改 - Zar_SY | 博客 香港:给我一周也逛不完 - Zar_SY | 博客 2024年小结 - Zar_SY | 博客 AKG N5005 主观听感 - Zar_SY | 博客 给X1 II换电池以及一些碎碎念 - Zar_SY | 博客 「圣地巡礼」在这片无垠的苍穹之下——缘之空(足利) - Zar_SY | 博客 2024 东京自由行 - Zar_SY | 博客 浦东机场过夜记 - Zar_SY | 博客 2023年总结 - Zar_SY | 博客 通过AutoBangumi实现全自动追番 - Zar_SY | 博客 「厨房札记」蔬菜烤鸡 feat.气炸锅 - Zar_SY | 博客 并不是很推荐的类纸膜:Elecom肯特纸 - Zar_SY | 博客 关于我把Ultra Mobile PayGO换成了giffgaff这档子事 - Zar_SY | 博客 小型媒体服务器折腾记-初见 - Zar_SY | 博客 Docker-Compose安装Komga——一款好用的个人漫画阅读服务 - Zar_SY | 博客 Hello Halo - Zar_SY | 博客 「樱之刻」:被幸福填满的酒杯 - Zar_SY | 博客
apcupsd配置小记 - Zar_SY | 博客
Zar_SY · 2023-10-19 · via Zar_SY | 博客

大一入学的时候因为寝室电压不稳定导致玩PS4的时候显示器时常黑屏,再加上担心哪天忘了交电费玩游戏玩到一半断电导致存档丢失,所以买了个UPS放寝室。
今年因为去医院见习,没什么时间打机,所以就把UPS丢在家里吃灰。直到国庆前几天,从不停电的家竟然停电了。担心断电对系统和硬盘造成损害,所以国庆的时候就把吃灰了几个月的UPS搬了出来,接到Homelab上。

1. 安装与配置

1.1 apt install

我的UPS是APC家的BK650M2-CH,所以用apcupsd进行管理。

sudo apt install apcupsd

插上RJ45网口到USB-A的线

lsusb

查看USB设备连接情况

Bus 001 Device 009: ID 051d:0002 American Power Conversion Uninterruptible Power Supply

1.2 修改/etc/default/apcupsd

因为不是使用 systemd 启动 apcupsd ,所以需要将ISCONFIGURED修改为yes

vim /etc/default/apcupsd

1.3 apcupsd.conf

先备份

cp /etc/apcupsd/apcupsd.conf{,.backup}
vim /etc/apcupsd/apcupsd.conf

修改为

#
UPSTYPE usb
DEVICE 

DEVICE留空,不然会出现STATUS:COMMLOST的错误

查看运行状况

apcaccess 

按需修改关机触发事件

vim /etc/apcupsd/apcupsd.conf
#
# Note: BATTERYLEVEL, MINUTES, and TIMEOUT work in conjunction, so
# the first that occurs will cause the initation of a shutdown.
#

# If during a power failure, the remaining battery percentage
# (as reported by the UPS) is below or equal to BATTERYLEVEL,
# apcupsd will initiate a system shutdown.
BATTERYLEVEL 40

# If during a power failure, the remaining runtime in minutes
# (as calculated internally by the UPS) is below or equal to MINUTES,
# apcupsd, will initiate a system shutdown.
MINUTES 20

# If during a power failure, the UPS has run on batteries for TIMEOUT
# many seconds or longer, apcupsd will initiate a system shutdown.
# A value of 0 disables this timer.
#
#  Note, if you have a Smart UPS, you will most likely want to disable
#    this timer by setting it to zero. That way, you UPS will continue
#    on batteries until either the % charge remaing drops to or below BATTERYLEVEL,
#    or the remaining battery runtime drops to or below MINUTES.  Of course,
#    if you are testing, setting this to 60 causes a quick system shutdown
#    if you pull the power plug.
#  If you have an older dumb UPS, you will want to set this to less than
#    the time you know you can run on batteries.
TIMEOUT 0

一共三个参数,分别是

名称 注释 单位
BATTERYLEVEL 当UPS电池电量低于 百分比
MINUTES 电池剩余可支持时间 分钟
TIMEOUT 断电时间 分钟

1.4 开机自启

/etc/init.d/apcupsd enable
/etc/init.d/apcupsd start

2. 测试

拔掉电源
status从变成了ONBATT

Broadcast message from root@homelab (somewhere) (Fri Sep 29 12:10:57 2023):

Power failure on UPS homelab. Running on batteries.

---
触发关机事件
---

Broadcast message from root@homelab (somewhere) (Fri Sep 29 12:52:54 2023):

Remaining battery charge below limit on UPS homelab. Doing shutdown.


Broadcast message from root@homelab (somewhere) (Fri Sep 29 12:52:54 2023):

UPS homelab initiated Shutdown Sequence

Connection to 192.168.1.*** closed by remote host.
Connection to 192.168.1.*** closed.

3. 关机但不关闭供电

测试了几次发现一个严重的问题:
触发关机事件后,主机是正常关机了,但同时UPS关机,不再给其他设备供电。
因为Homelab用的是PN41,内置只有一个nvme和一个2.5寸硬盘位,所以同时外接了一个硬盘柜。UPS断电的时候主机关机,但外接的硬盘还在转,所以断电就能听到一声让人毛骨悚然的“吱~”。
希望主机能够自己关机但不停止UPS对其他设备的供电,所以需要修改默认的关机指令。
先创建一个另外的关机脚本

vim powerfailure_shutdown.sh
# 等待30秒后关机
sleep 30
sudo shutdown -h now

然后修改断电关机指令

cp /etc/apcupsd/apccontrol{,.backup}
vim /etc/apcupsd/apccontrol

doshutdown)
    echo "UPS ${2} initiated Shutdown Sequence" | ${WALL}
    #${SHUTDOWN} -h now "apcupsd UPS ${2} initiated shutdown"
    ;;

修改成

doshutdown)
    echo "UPS ${2} initiated Shutdown Sequence" | ${WALL}
    /path/to/powerfailure_shutdown.sh &  # 脚本路径
;;

再次拔掉电源测试,主机关机之后UPS还在持续给硬盘柜断电,让硬盘有足够的停转时间。

参考文章
APCUPSD User Manual
Apcupsd on Debian stretch 9 no connection to UPS?