mirror of
https://github.com/yawaflua/SpCloudCore.git
synced 2025-12-09 20:19:35 +02:00
Fix
This commit is contained in:
@@ -67,11 +67,11 @@ public:
|
||||
|
||||
file_processing->delete_file(filename);
|
||||
|
||||
/*app->set_url("https://" + app->get_name() + ".almavid.ru/");
|
||||
app->set_url("https://" + app->get_name() + ".almavid.ru/");
|
||||
|
||||
app->set_url_on_local_machine("http://localhost:" + std::to_string(last_available_port));*/
|
||||
app->set_url_on_local_machine("http://localhost:" + std::to_string(last_available_port));
|
||||
|
||||
//app->set_service_name(app_final_file_path);
|
||||
app->set_service_name(app_final_file_path);
|
||||
|
||||
return "Publish successfully: " + filename;
|
||||
}
|
||||
|
||||
@@ -8,25 +8,25 @@ private:
|
||||
std::string url;
|
||||
std::string url_on_local_machine;
|
||||
std::string target;
|
||||
//std::string service_name;
|
||||
std::string service_name;
|
||||
|
||||
public:
|
||||
App(const std::string& name, const std::string& user_id, const std::string& url,
|
||||
const std::string& url_on_local_machine, const std::string& target/*, const std::string& service_name*/)
|
||||
: name(name), user_id(user_id), url(url), url_on_local_machine(url_on_local_machine), target(target)/*, service_name(service_name)*/ {}
|
||||
const std::string& url_on_local_machine, const std::string& target, const std::string& service_name)
|
||||
: name(name), user_id(user_id), url(url), url_on_local_machine(url_on_local_machine), target(target), service_name(service_name) {}
|
||||
|
||||
std::string get_name() const { return name; }
|
||||
std::string get_user_id() const { return user_id; }
|
||||
std::string get_url() const { return url; }
|
||||
std::string get_url_on_local_machine() const { return url_on_local_machine; }
|
||||
std::string get_target() const { return target; }
|
||||
//std::string get_service_name() const { return service_name; }
|
||||
std::string get_service_name() const { return service_name; }
|
||||
|
||||
void set_name(const std::string& name) { this->name = name; }
|
||||
void set_user_id(const std::string& user_id) { this->user_id = user_id; }
|
||||
void set_url(const std::string& url) { this->url = url; }
|
||||
void set_url_on_local_machine(const std::string& url_on_local_machine) { this->url_on_local_machine = url_on_local_machine; }
|
||||
void set_target(const std::string& target) { this->target = target; }
|
||||
//void set_service_name(const std::string& service_name) { this->service_name = service_name; }
|
||||
void set_service_name(const std::string& service_name) { this->service_name = service_name; }
|
||||
};
|
||||
#endif // APP_H
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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"("
|
||||
}
|
||||
|
||||
@@ -72,12 +72,12 @@ int main()
|
||||
return;
|
||||
}
|
||||
|
||||
App* app = new App(name, user_id, "url", "local_url", target/*,"service_name"*/);
|
||||
App* app = new App(name, user_id, "url", "local_url", target,"service_name");
|
||||
|
||||
publish_controller.process_publish(req, app);
|
||||
|
||||
//mongo_service.add_app(app->get_name(), app->get_user_id(), app->get_url(),
|
||||
// app->get_url_on_local_machine(), app->get_target()/*, app->get_service_name()*/);//TODO UNCOMMENT AND FIX
|
||||
mongo_service.add_app(app->get_name(), app->get_user_id(), app->get_url(),
|
||||
app->get_url_on_local_machine(), app->get_target(), app->get_service_name());//TODO UNCOMMENT AND FIX
|
||||
|
||||
delete app;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user