Shutdown Windows computer and Synology NAS using CyberPower UPS
After a recent thunderstorm that took out the power for several hours, I realized that my four year old 825VA UPS was a little long in the tooth and probably under powered for my computer, NAS and twin 26″ monitors. I also realized that I needed to plug my router and network hub into the UPS, if I wanted Internet to continue during a blackout. (The cable modem is in another room and will get it’s own UPS :-) After doing a bit of research, I decided on the CyberPower CP1500PCFLCD UPS. (I’m not really sure about the pure vs simulated sine wave discussion, but I feared it might matter someday, so I ponied up for the pure sine wave version.)
Another thing dawned on me: although the UPS application would shutdown my computer when the battery got low, nothing instructed my Synology NAS DS212j to do the same. I’ve got twin 4TB drives in there, so corrupting those drives would not be good. I messed around with NUT (Network UPS Tools), but just couldn’t get it to work on my Windows 10 machine. Eventually, I learned that CyberPower had posted actual instructions on how to do it with a Synology NAS! Unfortunately, it doesn’t tell you everything, but after several hours of searching and trial and error I was able to piece it all together and get my Windows computer and Synology NAS to shutdown when my UPS was running out of battery power. I’ve compiled everything here:
First, you need to set the root user’s password on the NAS to be the same as the Admin user.
- Go to the PuTTY Download page and download putty.exe and plink.exe. You can just put them in C:\.
- Open DiskStation on the Synology NAS and then open the Control Panel.
- Select Terminal & SNMP and select the Enable SSH service option. Click Apply.
- Close the DiskStation window.
- On your computer, run Putty (there is no install). In the Host Name field, enter the IP address of your Synology NAS and click Open.
- In the window that appears, log in as admin. Enter your password when prompted.
- Once logged in, enter following command: sudo su
You’ll be prompted for your admin password again. Type it in and press enter.
- Next, enter the following command: synouser -setpw root XXXXXXX
This command changes the root user password to be the same as the admin password. Obviously, replace XXXXXXX with your admin password.
- You can now close down Putty.
Next, set up the CyberPower PowerPanel software:
- Download and install the Business Edition of the CyberPower PowerPanel software. If you’ve already installed the personal edition, uninstall it.
- Find the default.cmd file that gets installed. On Windows 10, it’s here: C:\Program Files (x86)\CyberPower PowerPanel Business Edition\extcmd\default.cmd
- Open default.cmd in a text editor, like Notepad.
- Look for the :doEventOccurCommand label and add the line in bold below that starts with echo.
rem Write commands here.
rem The commands will be ran when an event occurred.
echo n | C:\plink.exe -ssh -pw YOURPASSWORD email@example.com poweroff
Note that the username above must be root (not admin) and replace YOURPASSWORD with…drumroll…your password! HAHA
- Save the file.
- Run PowerPanel Business Edition (it opens in your browser) and click Events.
- Click on the Shutdown initiated row to select it. The fields will become editable.
- Under the Command heading, set Initiated to Instant, Duration to 1 min and File to default. Click Apply.
When a shutdown is initiated, the default.cmd file you edited will be run. The program will wait for 1 minute before shutting down your computer.
- That’s it!
To test your set up:
- Open a DOS CMD window and run the command you added to the default.cmd file (i.e., C:\plink.exe -ssh -pw YOURPASSWORD firstname.lastname@example.org poweroff)
HINT: I suggest you copy the command right out of your default.cmd file, so you know exactly what will be executed.
- Make sure this turns off your NAS. Note that this may take a minute or two.
- If that works, turn your NAS back on and wait until it’s fully booted.
- Go back to PowerPanel Events.
- Select the Utility power failure row.
- Under Shutdown, set the Initiated setting to Instant and click Apply.
- Unplug your UPS.
- It takes a while for the Synology NAS to power down, so your computer may shutdown first, even though you have a one minute delay. Hopefully, the NAS will shut down eventually.
- If that works, change the Utility power failure Shutdown setting back to inactive and apply. If it doesn’t work, go back and recheck everything.
You should be able to get this all done in about ten minutes. Your welcome.