mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
API CHANGE
Add the "is_running" output field to the sysadm/services "list_services" output. This also cleans up the is_enabled detection routine so it should be more reliable.
This commit is contained in:
@@ -1013,6 +1013,7 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmServiceRequest(const QJsonVa
|
||||
S.insert("path", list[i].Path);
|
||||
S.insert("description", list[i].Description);
|
||||
S.insert("is_enabled", listEnabled[i] ? "true" : "false" );
|
||||
S.insert("is_running",SMGR.isRunning(list[i]) ? "true" : "false" );
|
||||
//S.insert("filename", list[i].Directory);
|
||||
//Need to add status info as well (isRunning, isEnabled);
|
||||
services.insert(list[i].Name, S);
|
||||
|
||||
@@ -35,7 +35,8 @@ QList<bool> ServiceManager::isRunning(QList<Service> services){
|
||||
//return list in the same order as the input list
|
||||
QList<bool> out;
|
||||
for(int i=0; i<services.length(); i++){
|
||||
out << false; //TO-DO - need to figure out a way to detect process status
|
||||
if(services[i].Directory.isEmpty()){ out << false; }
|
||||
else{ out << sysadm::General::RunQuickCommand("service",QStringList() << services[i].Directory << "status"); }
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -53,7 +54,7 @@ QList<bool> ServiceManager::isEnabled(QList<Service> services){
|
||||
//Now go through the list of services and report which ones are enabled
|
||||
for(int i=0; i<services.length(); i++){
|
||||
bool enabled = false;
|
||||
if(rcdata.contains(services[i].Tag)){ enabled = rcdata.value(services[i].Tag)=="\"YES\""; }
|
||||
if(rcdata.contains(services[i].Tag)){ enabled = rcdata.value(services[i].Tag)=="YES"; }
|
||||
out << enabled;
|
||||
}
|
||||
return out;
|
||||
@@ -118,16 +119,16 @@ bool ServiceManager::Restart(Service service)
|
||||
return General::RunQuickCommand(prog,args);
|
||||
}
|
||||
|
||||
void ServiceManager::Enable(Service service)
|
||||
bool ServiceManager::Enable(Service service)
|
||||
{
|
||||
if(service.Tag.isEmpty()){ return; }
|
||||
General::setConfFileValue( chroot + "/etc/rc.conf", service.Tag, service.Tag + "=\"YES\"", -1);
|
||||
if(service.Tag.isEmpty()){ return false; }
|
||||
return General::setConfFileValue( chroot + "/etc/rc.conf", service.Tag, service.Tag + "=\"YES\"", -1);
|
||||
}
|
||||
|
||||
void ServiceManager::Disable(Service service)
|
||||
bool ServiceManager::Disable(Service service)
|
||||
{
|
||||
if(service.Tag.isEmpty()){ return; }
|
||||
General::setConfFileValue( chroot + "/etc/rc.conf", service.Tag, service.Tag + "=\"NO\"", -1);
|
||||
if(service.Tag.isEmpty()){ return false; }
|
||||
return General::setConfFileValue( chroot + "/etc/rc.conf", service.Tag, service.Tag + "=\"NO\"", -1);
|
||||
}
|
||||
|
||||
Service ServiceManager::loadServices(QString name)
|
||||
@@ -227,7 +228,14 @@ Service ServiceManager::loadServices(QString name)
|
||||
void ServiceManager::loadRCdata(){
|
||||
//Read all the rc.conf files in highest-priority order
|
||||
rcdata.clear();
|
||||
QDir dir("/etc");
|
||||
QStringList info = sysadm::General::RunCommand("sysrc -A").split("\n");
|
||||
for(int i=0; i<info.length(); i++){
|
||||
if(info[i].contains(": ")){
|
||||
rcdata.insert( info[i].section(": ",0,0), info[i].section(": ",1,-1) );
|
||||
}
|
||||
}
|
||||
|
||||
/*QDir dir("/etc");
|
||||
QStringList confs = dir.entryList(QStringList() << "rc.conf*", QDir::Files, QDir::Name | QDir::Reversed);
|
||||
//qDebug() << "Conf file order:" << confs;
|
||||
for(int i=0; i<confs.length(); i++){
|
||||
@@ -258,5 +266,5 @@ void ServiceManager::loadRCdata(){
|
||||
}//end loop over lines
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -69,12 +69,12 @@ public:
|
||||
* @brief Enable enable a service
|
||||
* @param service the service to enable
|
||||
*/
|
||||
void Enable(Service service);
|
||||
bool Enable(Service service);
|
||||
/**
|
||||
* @brief Disable disable a service
|
||||
* @param service the service to disable
|
||||
*/
|
||||
void Disable(Service service);
|
||||
bool Disable(Service service);
|
||||
private:
|
||||
QList<Service> services;
|
||||
Service loadServices(QString service = ""); //Return struct is optional - only used for a single service search
|
||||
|
||||
@@ -287,6 +287,7 @@ QJsonObject Update::writeSettings(QJsonObject obj){
|
||||
info << keys[i]+": "+vals[i];
|
||||
}
|
||||
if( General::writeTextFile(UP_CONFFILE, info, true) ){
|
||||
QProcess::startDetached("pc-updatemanager syncconf"); //sync up the config files as needed
|
||||
ret.insert("result","success");
|
||||
}else{
|
||||
ret.insert("result","error");
|
||||
|
||||
Reference in New Issue
Block a user