Add two new API calls, to shutdown/halt the system, and to

reboot the system.

Shutdown API call

REST Request:
-------------------------------
PUT /sysadm/systemmanager
{
   "action" : "halt"
}

WebSocket Request:
-------------------------------
{
   "id" : "fooid",
   "args" : {
      "action" : "halt"
   },
   "name" : "systemmanager",
   "namespace" : "sysadm"
}

Response:
-------------------------------
{
  "args": {
    "halt": {
      "response": "true"
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
}

Reboot API call

REST Request:
-------------------------------
PUT /sysadm/systemmanager
{
   "action" : "reboot"
}

WebSocket Request:
-------------------------------
{
   "id" : "fooid",
   "args" : {
      "action" : "reboot"
   },
   "name" : "systemmanager",
   "namespace" : "sysadm"
}

Response:
-------------------------------
{
  "args": {
    "reboot": {
      "response": "true"
    }
  },
  "id": "fooid",
  "name": "response",
  "namespace": "sysadm"
}
This commit is contained in:
Kris Moore
2016-02-17 13:08:12 -05:00
parent cd72cb1308
commit 80bcd67733
3 changed files with 30 additions and 0 deletions

View File

@@ -405,6 +405,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmSystemMgmtRequest(const QJso
ok = true;
out->insert("externalmounts", sysadm::SysMgmt::externalDevicePaths());
}
if(act=="halt"){
ok = true;
out->insert("halt", sysadm::SysMgmt::systemHalt());
}
if(act=="killproc"){
ok = true;
out->insert("killproc", sysadm::SysMgmt::killProc(in_args.toObject()));
@@ -417,6 +421,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmSystemMgmtRequest(const QJso
ok = true;
out->insert("procinfo", sysadm::SysMgmt::procInfo());
}
if(act=="reboot"){
ok = true;
out->insert("reboot", sysadm::SysMgmt::systemReboot());
}
if(act=="setsysctl"){
ok = true;
out->insert("setsysctl", sysadm::SysMgmt::setSysctl(in_args.toObject()));

View File

@@ -371,3 +371,23 @@ QJsonObject SysMgmt::systemInfo() {
return retObject;
}
// Halt the box
QJsonObject SysMgmt::systemHalt() {
QJsonObject retObject;
QString output = General::RunCommand("shutdown -p now");
retObject.insert("response", "true");
return retObject;
}
// Reboot the box
QJsonObject SysMgmt::systemReboot() {
QJsonObject retObject;
QString output = General::RunCommand("shutdown -r now");
retObject.insert("response", "true");
return retObject;
}

View File

@@ -24,6 +24,8 @@ public:
static QJsonObject setSysctl(QJsonObject);
static QJsonObject sysctlList();
static QJsonObject systemInfo();
static QJsonObject systemReboot();
static QJsonObject systemHalt();
};
} //end of pcbsd namespace