<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
  
  <title>Lee Chun Yong — Writing</title>
  <subtitle>Notes on security, systems and self-hosting.</subtitle>
  <link href="https://portfolio.chunyong.cc/feed.xml" rel="self" />
  <link href="https://portfolio.chunyong.cc/" />
  <updated>2026-08-30T00:00:00Z</updated>
  <id>https://portfolio.chunyong.cc/</id>
  <author>
    <name>Lee Chun Yong</name>
  </author>
  <entry>
    <title>Setting Up Auto-Shutdown for a Prolink PRO851SFCU UPS on Debian</title>
    <link href="https://portfolio.chunyong.cc/blog/ups-auto-shutdown-debian/" />
    <updated>2026-08-30T00:00:00Z</updated>
    <id>https://portfolio.chunyong.cc/blog/ups-auto-shutdown-debian/</id>
    <content type="html">&lt;p&gt;I recently picked up a Prolink PRO851SFCU UPS to protect my home server setup against unexpected power trips. Getting the hardware plugged in is only half the battle — the real work is configuring Network UPS Tools (NUT) to handle a graceful, automated shutdown before the battery drains completely.&lt;/p&gt;
&lt;p&gt;Here is the complete configuration blueprint for setting up NUT with a 2-minute timed auto-shutdown on Debian.&lt;/p&gt;
&lt;h2&gt;Step 1: Hardware &amp;amp; Package Installation&lt;/h2&gt;
&lt;p&gt;Connect the UPS to the server via the USB-A to USB-B cable, then install the NUT packages:&lt;/p&gt;
&lt;div class=&quot;code-panel&quot;&gt;
  &lt;div class=&quot;code-panel-head&quot;&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;copy-btn&quot; type=&quot;button&quot;&gt;Copy&lt;/button&gt;&lt;/div&gt;
  &lt;pre class=&quot;code-block&quot;&gt;&lt;code&gt;sudo apt update &amp;amp;&amp;amp; sudo apt install nut nut-client nut-server
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2&gt;Step 2: Driver &amp;amp; Monitoring Configuration&lt;/h2&gt;
&lt;p&gt;Because the Prolink PRO851SFCU uses a single 12V 10Ah battery and a Voltronic-QS USB chip, we override the low/high voltage limits in &lt;code&gt;/etc/nut/ups.conf&lt;/code&gt; to get an accurate 0–100% state-of-charge calculation and prevent poll disconnect spam:&lt;/p&gt;
&lt;div class=&quot;code-panel&quot;&gt;
  &lt;div class=&quot;code-panel-head&quot;&gt;&lt;span class=&quot;code-lang&quot;&gt;ini&lt;/span&gt;&lt;button class=&quot;copy-btn&quot; type=&quot;button&quot;&gt;Copy&lt;/button&gt;&lt;/div&gt;
  &lt;pre class=&quot;code-block&quot;&gt;&lt;code&gt;# /etc/nut/ups.conf
[prolink]
    driver = nutdrv_qx
    port = auto
    desc = &amp;quot;Prolink PRO851SFCU&amp;quot;
    override.battery.voltage.low = 9.6
    override.battery.voltage.high = 13.2
    override.battery.packs = 1
    pollinterval = 2
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Set the operation mode to standalone in &lt;code&gt;/etc/nut/nut.conf&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;code-panel&quot;&gt;
  &lt;div class=&quot;code-panel-head&quot;&gt;&lt;span class=&quot;code-lang&quot;&gt;ini&lt;/span&gt;&lt;button class=&quot;copy-btn&quot; type=&quot;button&quot;&gt;Copy&lt;/button&gt;&lt;/div&gt;
  &lt;pre class=&quot;code-block&quot;&gt;&lt;code&gt;# /etc/nut/nut.conf
MODE=standalone
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Define local monitoring credentials in &lt;code&gt;/etc/nut/upsd.users&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;code-panel&quot;&gt;
  &lt;div class=&quot;code-panel-head&quot;&gt;&lt;span class=&quot;code-lang&quot;&gt;ini&lt;/span&gt;&lt;button class=&quot;copy-btn&quot; type=&quot;button&quot;&gt;Copy&lt;/button&gt;&lt;/div&gt;
  &lt;pre class=&quot;code-block&quot;&gt;&lt;code&gt;# /etc/nut/upsd.users
[monuser]
    password = secretpass
    upsmon primary
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Configure &lt;code&gt;upsmon&lt;/code&gt; in &lt;code&gt;/etc/nut/upsmon.conf&lt;/code&gt; to delegate events to &lt;code&gt;upssched&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;code-panel&quot;&gt;
  &lt;div class=&quot;code-panel-head&quot;&gt;&lt;span class=&quot;code-lang&quot;&gt;ini&lt;/span&gt;&lt;button class=&quot;copy-btn&quot; type=&quot;button&quot;&gt;Copy&lt;/button&gt;&lt;/div&gt;
  &lt;pre class=&quot;code-block&quot;&gt;&lt;code&gt;# /etc/nut/upsmon.conf
MONITOR prolink@localhost 1 monuser secretpass primary
SHUTDOWNCMD &amp;quot;/sbin/shutdown -h now&amp;quot;
POWERDOWNFLAG /etc/killpower

NOTIFYCMD /sbin/upssched
NOTIFYFLAG ONLINE   EXEC+WARN+REGARD
NOTIFYFLAG ONBATT   EXEC+WARN+REGARD
NOTIFYFLAG LOWBATT  EXEC+WARN+REGARD
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2&gt;Step 3: Timed Shutdown Script&lt;/h2&gt;
&lt;p&gt;To prevent the server from instantly shutting down during brief brownouts, set up a 120-second timer buffer in &lt;code&gt;/etc/nut/upssched.conf&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;code-panel&quot;&gt;
  &lt;div class=&quot;code-panel-head&quot;&gt;&lt;span class=&quot;code-lang&quot;&gt;ini&lt;/span&gt;&lt;button class=&quot;copy-btn&quot; type=&quot;button&quot;&gt;Copy&lt;/button&gt;&lt;/div&gt;
  &lt;pre class=&quot;code-block&quot;&gt;&lt;code&gt;# /etc/nut/upssched.conf
CMDSCRIPT /etc/nut/upssched-cmd
PIPEFN /var/run/nut/upssched.pipe
LOCKFN /var/run/nut/upssched.lock

AT ONBATT * START-TIMER shutdown_timer 120
AT ONLINE * CANCEL-TIMER shutdown_timer
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Create the execution script at &lt;code&gt;/etc/nut/upssched-cmd&lt;/code&gt; (ensure the double &#39;s&#39; in &lt;code&gt;upssched&lt;/code&gt; to avoid execution errors):&lt;/p&gt;
&lt;div class=&quot;code-panel&quot;&gt;
  &lt;div class=&quot;code-panel-head&quot;&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;copy-btn&quot; type=&quot;button&quot;&gt;Copy&lt;/button&gt;&lt;/div&gt;
  &lt;pre class=&quot;code-block&quot;&gt;&lt;code&gt;#!/bin/sh
case $1 in
    shutdown_timer)
        /sbin/shutdown -h now &amp;quot;UPS on battery for 2 minutes. Shutting down system.&amp;quot;
        ;;
    *)
        logger -t upssched-cmd &amp;quot;Unknown event: $1&amp;quot;
        ;;
esac
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Apply execution permissions and set ownership for the &lt;code&gt;nut&lt;/code&gt; user:&lt;/p&gt;
&lt;div class=&quot;code-panel&quot;&gt;
  &lt;div class=&quot;code-panel-head&quot;&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;copy-btn&quot; type=&quot;button&quot;&gt;Copy&lt;/button&gt;&lt;/div&gt;
  &lt;pre class=&quot;code-block&quot;&gt;&lt;code&gt;sudo chmod +x /etc/nut/upssched-cmd
sudo chown nut:nut /etc/nut/upssched-cmd
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2&gt;Step 4: Verification &amp;amp; Service Startup&lt;/h2&gt;
&lt;p&gt;Clear any stuck PID files, enable the systemd services, and test the connection:&lt;/p&gt;
&lt;div class=&quot;code-panel&quot;&gt;
  &lt;div class=&quot;code-panel-head&quot;&gt;&lt;span class=&quot;code-lang&quot;&gt;bash&lt;/span&gt;&lt;button class=&quot;copy-btn&quot; type=&quot;button&quot;&gt;Copy&lt;/button&gt;&lt;/div&gt;
  &lt;pre class=&quot;code-block&quot;&gt;&lt;code&gt;sudo systemctl stop nut-server nut-client
sudo rm -f /run/nut/*.pid
sudo systemctl restart nut-server nut-client
sudo systemctl enable nut-server nut-client
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Running &lt;code&gt;upsc prolink@localhost&lt;/code&gt; should now report &lt;code&gt;ups.status: OL&lt;/code&gt; and &lt;code&gt;battery.charge: 100&lt;/code&gt;. You can safely test the script logic by manually executing &lt;code&gt;sudo /etc/nut/upssched-cmd shutdown_timer&lt;/code&gt; and cancelling it with &lt;code&gt;sudo shutdown -c&lt;/code&gt;.&lt;/p&gt;
</content>
  </entry>
</feed>