117 lines
4.0 KiB
C++
117 lines
4.0 KiB
C++
|
|
// #include <iostream>
|
|
// #include <fstream>
|
|
// #include <sstream>
|
|
// #include <cstdlib>
|
|
// #include <chrono>
|
|
// #include <iomanip>
|
|
// #include <filesystem>
|
|
// #include <unistd.h>
|
|
// #include <libassert/assert.hpp>
|
|
|
|
// #include "config.hpp"
|
|
// #include "servers.hpp"
|
|
// #include "templates.hpp"
|
|
// #include "services.hpp"
|
|
// #include "utils/directories.hpp"
|
|
// #include "utils/utils.hpp"
|
|
// #include "command_registry.hpp"
|
|
// #include "shared_commands.hpp"
|
|
|
|
|
|
// namespace fs = std::filesystem;
|
|
|
|
// namespace dropshell {
|
|
|
|
|
|
// service_runner::service_runner(const std::string& server_name, const std::string& service_name) :
|
|
// mServerEnv(server_name), mServer(server_name), mService(service_name), mValid(false)
|
|
// {
|
|
// if (server_name.empty() || service_name.empty())
|
|
// return;
|
|
|
|
// // Initialize server environment
|
|
// if (!mServerEnv.is_valid())
|
|
// return;
|
|
|
|
// mServiceInfo = get_service_info(server_name, service_name);
|
|
// if (mServiceInfo.service_name.empty())
|
|
// return;
|
|
|
|
// mService = mServiceInfo.service_name;
|
|
|
|
// mValid = !mServiceInfo.local_template_path.empty();
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // ------------------------------------------------------------------------------------------------
|
|
// // Run a command on the service.
|
|
// // ------------------------------------------------------------------------------------------------
|
|
// bool service_runner::run_command(const std::string& command, std::vector<std::string> additional_args, std::map<std::string, std::string> env_vars) {
|
|
// if (!mServerEnv.is_valid()) {
|
|
// std::cerr << "Error: Server service not initialized" << std::endl;
|
|
// return false;
|
|
// }
|
|
// template_info tinfo = gTemplateManager().get_template_info(mServiceInfo.template_name);
|
|
// if (!tinfo.is_set()) {
|
|
// std::cerr << "Error: Template '" << mServiceInfo.template_name << "' not found" << std::endl;
|
|
// return false;
|
|
// }
|
|
|
|
// if (!gTemplateManager().template_command_exists(mServiceInfo.template_name, command)) {
|
|
// std::cout << "No command script for " << mServiceInfo.template_name << " : " << command << std::endl;
|
|
// return true; // nothing to run.
|
|
// }
|
|
|
|
// // install doesn't require anything on the server yet.
|
|
// // if (command == "install")
|
|
// // return install_service(mServer, mService, false);
|
|
|
|
// std::string script_path = remotepath::service_template(mServer, mService) + "/" + command + ".sh";
|
|
|
|
// // Check if service directory exists
|
|
// if (!mServerEnv.check_remote_dir_exists(remotepath::service(mServer, mService))) {
|
|
// std::cerr << "Error: Service is not installed: " << mService << std::endl;
|
|
// return false;
|
|
// }
|
|
|
|
// // Check if command script exists
|
|
// if (!mServerEnv.check_remote_file_exists(script_path)) {
|
|
// std::cerr << "Error: Remote command script not found: " << script_path << std::endl;
|
|
// return false;
|
|
// }
|
|
|
|
// // Check if env file exists
|
|
// if (!mServerEnv.check_remote_file_exists(remotefile::service_env(mServer, mService))) {
|
|
// std::cerr << "Error: Service config file not found: " << remotefile::service_env(mServer, mService) << std::endl;
|
|
// return false;
|
|
// }
|
|
|
|
// // if (command == "uninstall")
|
|
// // return uninstall();
|
|
|
|
// if (command == "ssh") {
|
|
// interactive_ssh_service();
|
|
// return true;
|
|
// }
|
|
// if (command == "restore") {
|
|
// if (additional_args.size() < 1) {
|
|
// std::cerr << "Error: restore requires a backup file:" << std::endl;
|
|
// std::cerr << "dropshell restore <server> <service> <backup-file>" << std::endl;
|
|
// return false;
|
|
// }
|
|
// return restore(additional_args[0], false);
|
|
// }
|
|
// if (command == "backup") {
|
|
// return backup(false);
|
|
// }
|
|
|
|
// // Run the generic command
|
|
// std::vector<std::string> args; // not passed through yet.
|
|
// return mServerEnv.run_remote_template_command(mService, command, args, false, env_vars);
|
|
// }
|
|
|
|
|
|
// } // namespace dropshell
|