uninstall!

This commit is contained in:
Your Name
2025-04-25 12:08:37 +12:00
parent 61fabac1f0
commit ed8bc0dca6
6 changed files with 100 additions and 9 deletions

View File

@ -175,6 +175,52 @@ bool service_runner::install() {
return true;
}
bool service_runner::uninstall() {
maketitle("Uninstalling " + m_service_info.service_name + " (" + m_service_info.template_name + ") on " + m_server_name);
if (!m_server_env) {
std::cerr << "Error: Server service not initialized" << std::endl;
return false;
}
// 1. Check if template exists
template_info tinfo;
if (!get_template_info(m_service_info.template_name, tinfo)) {
std::cerr << "Error: Template '" << m_service_info.template_name << "' not found" << std::endl;
return false;
}
// 2. Check if service directory exists on server
if (!check_remote_dir_exists(mRemote_service_path)) {
std::cerr << "Service is not installed: " << m_service_info.service_name << std::endl;
return true; // Nothing to uninstall
}
// 3. Run uninstall script if it exists
std::string uninstall_script = mRemote_service_template_path + "/_uninstall.sh";
bool script_exists = check_remote_file_exists(uninstall_script);
if (script_exists) {
std::string uninstall_cmd = "'cd " + mRemote_service_template_path +
" && /bin/bash _uninstall.sh " + mRemote_service_env_file + "'";
if (!execute_ssh_command(uninstall_cmd, "Failed to run uninstall script")) {
std::cerr << "Warning: Uninstall script failed, but continuing with directory removal" << std::endl;
}
} else {
std::cerr << "Warning: No uninstall script found. Unable to uninstall service." << std::endl;
return false;
}
// 4. Remove the service directory from the server
std::string rm_cmd = "'rm -rf " + mRemote_service_path + "'";
if (!execute_ssh_command(rm_cmd, "Failed to remove service directory")) {
return false;
}
std::cout << "Service " << m_service_info.service_name << " successfully uninstalled from " << m_server_name << std::endl;
return true;
}
bool service_runner::run_command(const std::string& command) {
if (!m_server_env) {
std::cerr << "Error: Server service not initialized" << std::endl;