OPNsense Forum

English Forums => General Discussion => Topic started by: bartjsmit on May 08, 2016, 11:15:01 pm

Title: [SOLVED] Remote shutdown
Post by: bartjsmit on May 08, 2016, 11:15:01 pm
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...
Title: Re: Remote shutdown
Post by: fabian on May 09, 2016, 05:55:25 pm
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
Title: Re: Remote shutdown
Post by: franco on May 10, 2016, 08:21:37 am
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.
Title: Re: Remote shutdown [SOLVED]
Post by: bartjsmit on May 10, 2016, 06:27:22 pm
Thanks both, I will use the SSH script for now at least.

Bart...
Title: Re: [SOLVED] Remote shutdown
Post by: franco on May 18, 2016, 09:27:41 am
I'll add the necessary firmware API bits for 16.1.15:

https://github.com/opnsense/core/issues/948
Title: Re: [SOLVED] Remote shutdown
Post by: franco on May 19, 2016, 08:11:02 am
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. :)
Title: Re: [SOLVED] Remote shutdown
Post by: bartjsmit on May 19, 2016, 08:27:26 am
Thanks Franco,

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

Bart...