[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...