mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 02:20:17 +00:00
API CHANGE
Add 3 new API calls (all almost the same - just different "actions" and the return message will be slightly different)
"action":"start" OR "stop" OR "restart"
This will [start/stop/restart] services on the system.
REQUIRED ARGUMENTS:
"services" : <string with a single service, or array of services>
EXAMPLE "start" command (change "services_started" in responce to "services_[started/stopped/restarted]" as needed to match the action:
REST Request (example):
-------------------------------
PUT /sysadm/services
{
"action" : "start",
"services" : [
"cupsd"
]
}
WebSocket Request:
-------------------------------
{
"args" : {
"action" : "start",
"services" : [
"cupsd"
]
},
"name" : "services",
"id" : "fooid",
"namespace" : "sysadm"
}
Response:
-------------------------------
{
"args": {
"services_started": [
"cupsd"
]
},
"id": "fooid",
"name": "response",
"namespace": "sysadm"
}
This commit is contained in:
@@ -1019,7 +1019,50 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmServiceRequest(const QJsonVa
|
||||
}
|
||||
ok = true;
|
||||
out->insert("services",services);
|
||||
|
||||
}else if(action=="start" && in_args.toObject().contains("services") ){
|
||||
QJsonValue sval = in_args.toObject().value("services");
|
||||
QStringList services;
|
||||
if(sval.isString()){ services << sval.toString(); }
|
||||
else if(sval.isArray()){ services = JsonArrayToStringList(sval.toArray()); }
|
||||
if(!services.isEmpty()){
|
||||
QStringList success;
|
||||
ok = true;
|
||||
for(int i=0; i<services.length(); i++){
|
||||
if( SMGR.Start( SMGR.GetService(services[i]) ) ){ success << services[i]; }
|
||||
}
|
||||
out->insert("services_started", QJsonArray::fromStringList(success));
|
||||
}
|
||||
|
||||
}else if(action=="stop" && in_args.toObject().contains("services") ){
|
||||
QJsonValue sval = in_args.toObject().value("services");
|
||||
QStringList services;
|
||||
if(sval.isString()){ services << sval.toString(); }
|
||||
else if(sval.isArray()){ services = JsonArrayToStringList(sval.toArray()); }
|
||||
if(!services.isEmpty()){
|
||||
QStringList success;
|
||||
ok = true;
|
||||
for(int i=0; i<services.length(); i++){
|
||||
if( SMGR.Stop( SMGR.GetService(services[i]) ) ){ success << services[i]; }
|
||||
}
|
||||
out->insert("services_stopped", QJsonArray::fromStringList(success));
|
||||
}
|
||||
}else if(action=="restart" && in_args.toObject().contains("services") ){
|
||||
QJsonValue sval = in_args.toObject().value("services");
|
||||
QStringList services;
|
||||
if(sval.isString()){ services << sval.toString(); }
|
||||
else if(sval.isArray()){ services = JsonArrayToStringList(sval.toArray()); }
|
||||
if(!services.isEmpty()){
|
||||
QStringList success;
|
||||
ok = true;
|
||||
for(int i=0; i<services.length(); i++){
|
||||
if( SMGR.Restart( SMGR.GetService(services[i]) ) ){ success << services[i]; }
|
||||
}
|
||||
out->insert("services_restarted", QJsonArray::fromStringList(success));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(out->keys().isEmpty()){
|
||||
if(ok){ out->insert("result","success"); }
|
||||
else{ out->insert("error","error"); }
|
||||
|
||||
@@ -67,6 +67,7 @@ bool ServiceManager::isEnabled(Service service){ //single-item overload
|
||||
|
||||
bool ServiceManager::Start(Service service)
|
||||
{
|
||||
if(service.Directory.isEmpty()){ return false; }
|
||||
// Start the process
|
||||
QString prog;
|
||||
QStringList args;
|
||||
@@ -84,6 +85,7 @@ bool ServiceManager::Start(Service service)
|
||||
|
||||
bool ServiceManager::Stop(Service service)
|
||||
{
|
||||
if(service.Directory.isEmpty()){ return false; }
|
||||
// Start the process
|
||||
QString prog;
|
||||
QStringList args;
|
||||
@@ -101,6 +103,7 @@ bool ServiceManager::Stop(Service service)
|
||||
|
||||
bool ServiceManager::Restart(Service service)
|
||||
{
|
||||
if(service.Directory.isEmpty()){ return false; }
|
||||
QString prog;
|
||||
QStringList args;
|
||||
bool once = !isEnabled(service);
|
||||
@@ -117,11 +120,13 @@ bool ServiceManager::Restart(Service service)
|
||||
|
||||
void ServiceManager::Enable(Service service)
|
||||
{
|
||||
if(service.Tag.isEmpty()){ return; }
|
||||
General::setConfFileValue( chroot + "/etc/rc.conf", service.Tag, service.Tag + "=\"YES\"", -1);
|
||||
}
|
||||
|
||||
void ServiceManager::Disable(Service service)
|
||||
{
|
||||
if(service.Tag.isEmpty()){ return; }
|
||||
General::setConfFileValue( chroot + "/etc/rc.conf", service.Tag, service.Tag + "=\"NO\"", -1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user