-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathservice.cpp
88 lines (65 loc) · 2.44 KB
/
service.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "service.h"
#include <QProcess>
#include <QDebug>
const char* Service::OPTION_INFO = "i";
const char* Service::OPTION_START = "s";
const char* Service::OPTION_START1 = "1";
const char* Service::OPTION_STOP = "st";
const char* Service::OPTION_STOP1 = "0";
const char* Service::OPTION_RESTART = "r";
const char* Service::OPTION_RESTART1 = "-1";
Service::Service(){
}
QString Service::start(){
QString output=this->info();
if(output.indexOf("active (running)")>0){
return "\033[1;42m● "+this->getServiceName()+" is active (running)\033[0m\n";
}
QProcess pingProcess;
pingProcess.execute(SERVICE_EXE+this->getServiceName()+" start");
output=this->info();
if(output.indexOf("active (running)")>0){
return "\033[1;42m● "+this->getServiceName()+" is active (running)\033[0m\n";
}
return "\033[1;41m● "+this->getServiceName()+" is inactive (dead)\033[0m\n";
}
QString Service::info(){
QProcess pingProcess;
pingProcess.start(SERVICE_EXE+this->getServiceName()+" status");
pingProcess.waitForFinished();
QString output(pingProcess.readAllStandardOutput());
//Pintar de verde si esta activo el servicio o de rojo si no lo esta
if(output.indexOf("active (running)")>0){
output.replace("active (running)","\033[1;42m active (running) \033[0m");
output.replace("●","\033[1;32m●\033[0m");
}
else{
output.replace("inactive (dead)","\033[1;41m inactive (dead) \033[0m");
output.replace("●","\033[1;31m●\033[0m");
}
return output;
}
QString Service::stop(){
QString output=this->info();
if(output.indexOf("active (running)")<0){
return "\033[1;41m● "+this->getServiceName()+" is inactive (dead)\033[0m\n";
}
QProcess pingProcess;
pingProcess.execute(SERVICE_EXE+this->getServiceName()+" stop");
output=this->info();
if(output.indexOf("active (running)")>0){
return "\033[1;42m● "+this->getServiceName()+" is active (running)\033[0m\n";
}
return "\033[1;41m● "+this->getServiceName()+" is inactive (dead)\033[0m\n";
}
QString Service::restart(){
QProcess pingProcess;
pingProcess.execute(SERVICE_EXE+this->getServiceName()+" restart");
return "\033[1;43m● "+this->getServiceName()+" is restarting \033[0m\n";
}
void Service::setServiceName(QString serviceName){
this->serviceName=serviceName;
}
QString Service::getServiceName(){
return this->serviceName;
}