[SOLVED] Remote shutdown

Started by bartjsmit, May 08, 2016, 11:15:01 PM

Previous topic - Next topic
May 08, 2016, 11:15:01 PM Last Edit: May 10, 2016, 06:28:11 PM by bartjsmit
I have OPNsense and a number of internal hosts powered from a UPS. One of the host has a USB connection to the UPS and runs a script on loss of mains power for a graceful shutdown. This script shuts down the other hosts powered by the UPS.

Is there a way to include a remote shutdown of OPNsense in this script? Either through SSH, an API call, SNMP or some other means?

Bart...

power off by the API is afaik not possible at the moment but if you look at this page, it should not be too hard to implement:
https://github.com/opnsense/core/blob/master/src/www/diag_halt.php

SSH works:
ssh root@opnsense /sbin/poweroff

Do not use poweroff... use the script /usr/local/etc/rc.halt as you'll otherwise end up with no backups and/or improper shutdowns.

API for this is going to happen, likely not for 16.7, but should be a viable target for 17.1.

Thanks both, I will use the SSH script for now at least.

Bart...


All done, using the API you can now do e.g.:

# curl -XPOST -d '{}' -H "Content-Type: application/json" -k -u "APIKEY":"APISECRET" https://10.0.0.1/api/core/firmware/poweroff

# curl -XPOST -d '{}' -H "Content-Type: application/json" -k -u "APIKEY":"APISECRET" https://10.0.0.1/api/core/firmware/reboot

Note that this requires the user to have firmware page privileges.

Have fun. :)

Thanks Franco,

I'll test that out once the school exams are finished.

Bart...

September 19, 2025, 08:45:03 AM #7 Last Edit: September 19, 2025, 08:47:00 AM by RichardPo12
Quote from: franco on May 10, 2016, 08:21:37 AMDo not use poweroff... use the script /usr/local/etc/rc.halt as you'll otherwise end up with no backups and/or improper shutdowns.

API for this is going to happen, likely not for 16.7, but should be a viable target for 17.1.

I tried to shutdown the router via:  ssh root@opnsense /.... Any command
But it does not accept ssh commands from the PC (the one connected to the ups), neither using the root user nor any other user.
From the same PC, I can access the OpnSense router's GUI with a browser //<ip>/

Did you enable SSH access (and for root, also)? You need SSH access (preferably with an SSH key to automate) and root privileges to do that.
Intel N100, 4* I226-V, 2* 82559, 16 GByte, 500 GByte NVME, ZTE F6005

1100 down / 800 up, Bufferbloat A+