OPNsense
  • Home
  • Help
  • Search
  • Login
  • Register

  • OPNsense Forum »
  • English Forums »
  • General Discussion »
  • [SOLVED] Remote shutdown
« previous next »
  • Print
Pages: [1]

Author Topic: [SOLVED] Remote shutdown  (Read 5738 times)

bartjsmit

  • Hero Member
  • *****
  • Posts: 1594
  • Karma: 167
    • View Profile
[SOLVED] Remote shutdown
« 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...
« Last Edit: May 10, 2016, 06:28:11 pm by bartjsmit »
Logged

fabian

  • Hero Member
  • *****
  • Posts: 2768
  • Karma: 199
  • OPNsense Contributor (Language, VPN, Proxy, etc.)
    • View Profile
    • Personal Homepage
Re: Remote shutdown
« Reply #1 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
Logged

franco

  • Administrator
  • Hero Member
  • *****
  • Posts: 13903
  • Karma: 1206
    • View Profile
Re: Remote shutdown
« Reply #2 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.
Logged

bartjsmit

  • Hero Member
  • *****
  • Posts: 1594
  • Karma: 167
    • View Profile
Re: Remote shutdown [SOLVED]
« Reply #3 on: May 10, 2016, 06:27:22 pm »
Thanks both, I will use the SSH script for now at least.

Bart...
Logged

franco

  • Administrator
  • Hero Member
  • *****
  • Posts: 13903
  • Karma: 1206
    • View Profile
Re: [SOLVED] Remote shutdown
« Reply #4 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
Logged

franco

  • Administrator
  • Hero Member
  • *****
  • Posts: 13903
  • Karma: 1206
    • View Profile
Re: [SOLVED] Remote shutdown
« Reply #5 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. :)
Logged

bartjsmit

  • Hero Member
  • *****
  • Posts: 1594
  • Karma: 167
    • View Profile
Re: [SOLVED] Remote shutdown
« Reply #6 on: May 19, 2016, 08:27:26 am »
Thanks Franco,

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

Bart...
Logged

  • Print
Pages: [1]
« previous next »
  • OPNsense Forum »
  • English Forums »
  • General Discussion »
  • [SOLVED] Remote shutdown
 

OPNsense is an OSS project © Deciso B.V. 2015 - 2023 All rights reserved
  • SMF 2.0.19 | SMF © 2021, Simple Machines
    Privacy Policy
    | XHTML | RSS | WAP2