This commit is contained in:
Hepatica
2024-08-17 03:39:14 +02:00
parent b758657c65
commit 4e10c139f8
5 changed files with 37 additions and 17 deletions

View File

@@ -209,15 +209,23 @@ public:
std::string command_reload = "sudo systemctl daemon-reload";
std::thread commandThreadReload(&CommandService::execute_command, command_reload);
/*std::thread commandThreadReload(&CommandService::execute_command, command_reload);
commandThreadReload.join();
commandThreadReload.join();*/
std::string command_start = "sudo systemctl start " + name + ".service";
std::thread commandThreadStart(&CommandService::execute_command, commandThreadStart);
//std::thread commandThreadStart(&CommandService::execute_command, commandThreadStart);
commandThreadStart.join();
//commandThreadStart.join();
auto request_reload = std::async(std::launch::async, &FileProcessingService::execute_command, this, command_reload);
std::string response_reload = request_reload.get();
auto request_start = std::async(std::launch::async, &FileProcessingService::execute_command, this, command_start);
std::string response_start = request_start.get();
//Todo check service ->sudo systemctl status <service-name>.service
@@ -230,6 +238,18 @@ public:
}
}
std::string execute_command(const std::string& command) {
std::array<char, 128> buffer;
std::string result;
std::shared_ptr<FILE> pipe(popen(command.c_str(), "r"), pclose);
if (!pipe) throw std::runtime_error("popen() failed!");
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
result += buffer.data();
}
return result;
}
void create_directory(const std::string& path) {
std::filesystem::create_directories(path);
}

View File

@@ -114,7 +114,7 @@ public:
return "App name isn't free please select another one";
}
std::string add_app(std::string name, std::string user_id, std::string url, std::string url_on_local_mahcine, std::string target/*, std::string service_name*/)
std::string add_app(std::string name, std::string user_id, std::string url, std::string url_on_local_mahcine, std::string target, std::string service_name)
{
std::string json_data = R"({
"dataSource": "SpCloudCluster",
@@ -124,7 +124,7 @@ public:
"name": ")" + name + R"(",
"user_id": ")" + user_id + R"(",
"url": ")" + url + R"(",
"service_name": ")" + "TEST" + R"(",
"service_name": ")" + service_name + R"(",
"url_on_local_machine": ")" + url_on_local_mahcine + R"(",
"target": ")" + target + R"("
}