diff --git a/.cspell/words.txt b/.cspell/words.txt index 6b8950d2..8b743f2b 100644 --- a/.cspell/words.txt +++ b/.cspell/words.txt @@ -157,6 +157,7 @@ ncrypt nlohmann nlohmann_json nmakeprg +nohup nominmax ntstatus nullptr diff --git a/repertory/repertory/include/cli/ui.hpp b/repertory/repertory/include/cli/ui.hpp index f7929d65..ea8a4873 100644 --- a/repertory/repertory/include/cli/ui.hpp +++ b/repertory/repertory/include/cli/ui.hpp @@ -53,8 +53,9 @@ ui(std::vector args, const std::string & /*data_directory*/, } ui::mgmt_app_config config{}; - ui::handlers handlers(&config, &server); + config.set_api_port(ui_port); + ui::handlers handlers(&config, &server); return exit_code::success; } } // namespace repertory::cli::actions diff --git a/repertory/repertory/include/ui/handlers.hpp b/repertory/repertory/include/ui/handlers.hpp index 437db1f0..36be0272 100644 --- a/repertory/repertory/include/ui/handlers.hpp +++ b/repertory/repertory/include/ui/handlers.hpp @@ -61,8 +61,9 @@ private: void handle_put_set_value_by_name(auto &&req, auto &&res); - auto read_process(provider_type prov, std::string_view name, - std::string_view command) const -> std::vector; + auto launch_process(provider_type prov, std::string_view name, + std::string_view command, bool background = false) const + -> std::vector; }; } // namespace repertory::ui diff --git a/repertory/repertory/include/ui/mgmt_app_config.hpp b/repertory/repertory/include/ui/mgmt_app_config.hpp index 5bf2df86..92978254 100644 --- a/repertory/repertory/include/ui/mgmt_app_config.hpp +++ b/repertory/repertory/include/ui/mgmt_app_config.hpp @@ -27,9 +27,9 @@ namespace repertory::ui { class mgmt_app_config final { private: - std::string api_auth_{"test"}; - std::uint16_t api_port_{default_ui_mgmt_port}; - std::string api_user_{"test"}; + atomic api_auth_{"test"}; + std::atomic api_port_{default_ui_mgmt_port}; + atomic api_user_{"test"}; std::unordered_map> locations_; @@ -46,6 +46,8 @@ public: std::string_view name) const -> std::string; + void set_api_port(std::uint16_t api_port); + void set_mount_location(provider_type prov, std::string_view name, std::string_view location); }; diff --git a/repertory/repertory/src/ui/handlers.cpp b/repertory/repertory/src/ui/handlers.cpp index 416ad514..5cfb1b88 100644 --- a/repertory/repertory/src/ui/handlers.cpp +++ b/repertory/repertory/src/ui/handlers.cpp @@ -31,6 +31,8 @@ #include "utils/path.hpp" #include "utils/string.hpp" +#include "boost/process.hpp" + namespace repertory::ui { handlers::handlers(mgmt_app_config *config, httplib::Server *server) : config_(config), @@ -320,7 +322,14 @@ auto handlers::launch_process(provider_type prov, std::string_view name, fmt::format(R"({} {} {})", repertory_binary_, str_type, command); if (background) { - return ""; +#if defined(_WIN32) + system(fmt::format(R"(start "" /b {})", cmd_line).c_str()); +#elif defined(__linux__) // defined(__linux__) + system(fmt::format("nohup {} 1>/dev/null 2>&1", cmd_line).c_str()); +#else // !defined(__linux__) && !defined(_WIN32) + build fails here +#endif // defined(_WIN32) + return {}; } auto *pipe = popen(cmd_line.c_str(), "r"); diff --git a/repertory/repertory/src/ui/mgmt_app_config.cpp b/repertory/repertory/src/ui/mgmt_app_config.cpp index 668cf688..e880c786 100644 --- a/repertory/repertory/src/ui/mgmt_app_config.cpp +++ b/repertory/repertory/src/ui/mgmt_app_config.cpp @@ -34,6 +34,10 @@ auto mgmt_app_config::get_mount_location(provider_type prov, return ""; } +void mgmt_app_config::set_api_port(std::uint16_t api_port) { + api_port_ = api_port; +} + void mgmt_app_config::set_mount_location(provider_type prov, std::string_view name, std::string_view location) {