-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuperviser.cpp
71 lines (63 loc) · 1.64 KB
/
superviser.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
#include "superviser.h"
#include <QDir>
#include<QProcess>
#include<QDebug>
superviser::superviser()
{
services_directory = QDir::homePath() + "/" + "services";
}
void superviser::slot_start_microservice(const QString &name)
{
already_run = false;
qint64 pid;
for(int i = 0; i < services_map.size(); ++i)
{
if(services_map.at(i).first == name)
{
qDebug() << "This microservice is already run";
already_run = true;
break;
}
}
if(!already_run)
{
if(!QProcess::startDetached(services_directory + QDir::separator() + name,
arguments, services_directory, &pid))
{
qDebug() << "Cant start the service " << name;
}
else
{
qDebug() << "Stasrted service " << name;
this->services_map.push_back(QPair<QString ,int>(name, pid));
}
}
}
void superviser::slot_kill_microservice(const QString &name)
{
#ifdef __linux__
QProcess kill_process;
kill_process.start("pkill -f " + name);
kill_process.kill();
#elif __WIN32__
QProcess::execute("taskkill /F /IM " + name);
#endif
//delete elem from services map after killing
for(int i = 0; i < services_map.size(); ++i)
{
if(services_map.at(i).first == name)
{
services_map.erase(services_map.begin() + i);
}
}
}
void superviser::look_all_services()
{
for(auto elem :services_map)
{
qDebug() << elem.first << " With pid " << elem.second;
}
}
superviser::~superviser()
{
}