Shutdown Windows computer and Synology NAS using CyberPower UPS

NOTE: As of DSM 6+, it is no longer possible to log in as a root user using the command line option, so the solution in this post no longer works. However, see my newer post, Shutdown Windows computer and Synology NAS using WinNut, for another way to accomplish the same thing!

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.

  1. Go to the PuTTY Download page and download putty.exe and plink.exe. You can just put them in C:\.
  2. Open DiskStation on the Synology NAS and then open the Control Panel.
  3. Select Terminal & SNMP and select the Enable SSH service option. Click Apply.
    ssh service
  4. Close the DiskStation window.
  5. 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.
  6. In the window that appears, log in as admin. Enter your password when prompted.
  7. Once logged in, enter following command: sudo su
    You’ll be prompted for your admin password again. Type it in and press enter.
  8. 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.
    sudo su
  9. You can now close down Putty.

Next, set up the CyberPower PowerPanel software:

  1. Download and install the Business Edition of the CyberPower PowerPanel software. If you’ve already installed the personal edition, uninstall it.
  2. 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
  3. Open default.cmd in a text editor, like Notepad.
  4. 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 root@ poweroff
    Note that the username above must be root (not admin) and replace YOURPASSWORD with…drumroll…your password! HAHA
  5. Save the file.
  6. Run PowerPanel Business Edition (it opens in your browser) and click Events.
  7. Click on the Shutdown initiated row to select it. The fields will become editable.
  8. 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.
  9. That’s it!

To test your set up:

  1. Open a DOS CMD window and run the command you added to the default.cmd file (i.e., C:\plink.exe -ssh -pw YOURPASSWORD root@ poweroff)
    HINT: I suggest you copy the command right out of your default.cmd file, so you know exactly what will be executed.
  2. Make sure this turns off your NAS. Note that this may take a minute or two.
  3. If that works, turn your NAS back on and wait until it’s fully booted.
  4. Go back to PowerPanel Events.
  5. Select the Utility power failure row.
  6. Under Shutdown, set the Initiated setting to Instant and click Apply.
  7. Unplug your UPS.
  8. 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.
  9. 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.

Comments 4

  • @Lesh, Could you elaborate on the steps you took in the following section of your post?

    “When it asked me if I trusted the host, I copied the key to add it to my command in default.cmd.

    “C:\Program files (x86)\puTTY\plink.exe” -hostkey -batch -ssh -pw @ sudo shutdown -h now

    Also, I added the admin user to the sudoers file so that it would not request a password a second time.”

  • So the command works when I past it in the cmd prompt but when it is called from the default file it doesnt seem to work. Any ideas? I have the DS3617xs and Windows 10 for my PC

    • Hmmmm not sure Greg. Are you sure the command gets executed? If not, try putting a .exe path and file in the command line to see if it even gets called. If you are saying that it does get called but it just doesn’t turn the NAS off, I don’t know what to suggest. I wonder if its a permission issue. Sorry I’m not of more help.

      • This helped me out and I might be able to answer the question above for future reference. There are two issues. It seems that plink now gives a message to the console waiting for a return press unless you include the -batch option. Also, if you haven’t connected before, the host key is not cached, and even if you connect by running the command in command prompt, it will only cache the keys for the current user. I suspect PowerPanel runs it as SYSTEM or something, so the keys are not cached for that user.

        For this I deleted the cached registry keys (HKEY_CURRENT_USER/Software/SimonTatham/PuTTY/SshHostKeys) and then ran the command again from command prompt. When it asked me if I trusted the host, I copied the key to add it to my command in default.cmd.

        “C:\Program files (x86)\puTTY\plink.exe” -hostkey -batch -ssh -pw @ sudo shutdown -h now

        Also, I added the admin user to the sudoers file so that it would not request a password a second time.

Leave a Reply