Install is broken - putting the wrong template on.
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
This commit is contained in:
parent
ddc57173cb
commit
a5243a7e79
@ -57,65 +57,85 @@ namespace dropshell
|
|||||||
// step 1 - destroy on remote server.
|
// step 1 - destroy on remote server.
|
||||||
if (server_env.is_valid())
|
if (server_env.is_valid())
|
||||||
{
|
{
|
||||||
LocalServiceInfo service_info;
|
std::string user = server_env.get_user_for_service(service); // returns empty string if no user found.
|
||||||
|
if (user.empty())
|
||||||
service_info = get_service_info(server, service);
|
|
||||||
bool service_valid = SIvalid(service_info);
|
|
||||||
if (!service_valid)
|
|
||||||
warning << "Invalid service: " << service << std::endl;
|
|
||||||
|
|
||||||
std::string user = server_env.get_user_for_service(service);
|
|
||||||
bool remote_dir_exists = server_env.check_remote_dir_exists(remotepath(server, user).service(service), user);
|
|
||||||
if (remote_dir_exists)
|
|
||||||
{
|
{
|
||||||
// run the destroy script on the remote server if it exists.
|
warning << "No user found for service " << service << " on " << server << std::endl;
|
||||||
// otherwise just uninstall.
|
for (auto sshuser : server_env.get_users())
|
||||||
if (service_valid)
|
|
||||||
{
|
{
|
||||||
if (gTemplateManager().template_command_exists(service_info.template_name, "destroy"))
|
if (server_env.check_remote_dir_exists(remotepath(server, sshuser.user).service(service), sshuser.user))
|
||||||
{
|
{
|
||||||
info << "Running destroy script for " << service << " on " << server << std::endl;
|
info << "Found a remote service directory here: " << remotepath(server, sshuser.user).service(service) << std::endl;
|
||||||
if (!server_env.run_remote_template_command(service, "destroy", {}, false, {}))
|
info << "Deleting it as user " << sshuser.user << std::endl;
|
||||||
warning << "Failed to run destroy script: " << service << std::endl;
|
user = sshuser.user;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.empty())
|
||||||
|
warning << "No remote service directory found for " << service << " on " << server << std::endl;
|
||||||
|
else
|
||||||
|
{ // user is not empty.
|
||||||
|
LocalServiceInfo service_info;
|
||||||
|
service_info = get_service_info(server, service);
|
||||||
|
bool service_valid = SIvalid(service_info);
|
||||||
|
if (!service_valid)
|
||||||
|
warning << "No valid service definition found for " << service << std::endl;
|
||||||
|
|
||||||
|
if (server_env.check_remote_dir_exists(remotepath(server, user).service(service), user))
|
||||||
|
{
|
||||||
|
// run the destroy script on the remote server if it exists.
|
||||||
|
// otherwise just uninstall.
|
||||||
|
if (service_valid)
|
||||||
|
{
|
||||||
|
if (gTemplateManager().template_command_exists(service_info.template_name, "destroy"))
|
||||||
|
{
|
||||||
|
info << "Running destroy script for " << service << " on " << server << std::endl;
|
||||||
|
if (!server_env.run_remote_template_command(service, "destroy", {}, false, {}))
|
||||||
|
warning << "Failed to run destroy script: " << service << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
info << "No destroy script found for " << service << " on " << server << std::endl;
|
||||||
|
info << "Running uninstall script instead and will clean directories." << std::endl;
|
||||||
|
if (!server_env.run_remote_template_command(service, "uninstall", {}, false, {}))
|
||||||
|
warning << "Failed to uninstall service: " << service << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the service directory from the server, running in a docker container as root.
|
||||||
|
if (server_env.remove_remote_dir(remotepath(server, user).service(service), true, user))
|
||||||
|
{
|
||||||
|
ASSERT(!server_env.check_remote_dir_exists(remotepath(server, user).service(service), user), "Service directory still found on server after uninstall");
|
||||||
|
info << "Remote service directory removed: " << remotepath(server, user).service(service) << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
warning << "Failed to remove remote service directory" << std::endl;
|
||||||
info << "No destroy script found for " << service << " on " << server << std::endl;
|
|
||||||
info << "Running uninstall script instead and will clean directories." << std::endl;
|
|
||||||
if (!server_env.run_remote_template_command(service, "uninstall", {}, false, {}))
|
|
||||||
warning << "Failed to uninstall service: " << service << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove the service directory from the server, running in a docker container as root.
|
|
||||||
if (server_env.remove_remote_dir(remotepath(server, user).service(service), true, user))
|
|
||||||
{
|
|
||||||
ASSERT(!server_env.check_remote_dir_exists(remotepath(server, user).service(service), user), "Service directory still found on server after uninstall");
|
|
||||||
info << "Remote service directory removed: " << remotepath(server, user).service(service) << std::endl;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
warning << "Failed to remove remote service directory" << std::endl;
|
warning << "No remote service directory found for " << service << " on "<< server << std::endl;
|
||||||
}
|
} // user is not empty.
|
||||||
else
|
} // server_env is valid.
|
||||||
warning << "Service not found on remote server: " << remotepath(server, user).service(service) << std::endl;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
warning << "Can't destroy the remote service as the server is invalid: " << server << std::endl;
|
error << "No valid local server information for server " << server << std::endl;
|
||||||
|
|
||||||
// step 2 - destroy the local service directory.
|
// step 2 - destroy the local service directory, if it exists.
|
||||||
std::string local_service_path = localpath::service(server, service);
|
std::string local_service_path = localpath::service(server, service);
|
||||||
if (local_service_path.empty() || !std::filesystem::exists(local_service_path))
|
if (local_service_path.empty() || !std::filesystem::exists(local_service_path))
|
||||||
{
|
{
|
||||||
warning << "Local service directory not found: " << local_service_path << std::endl;
|
warning << "No local service directory found for " << service << " on " << server << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto itemsdeleted = std::filesystem::remove_all(local_service_path);
|
auto itemsdeleted = std::filesystem::remove_all(local_service_path);
|
||||||
if (itemsdeleted == 0)
|
if (itemsdeleted == 0)
|
||||||
error << "Failed to remove local service directory" << std::endl;
|
error << "Failed to remove local service directory" << std::endl;
|
||||||
|
else
|
||||||
|
info << "Local service directory removed: " << local_service_path << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
info << "Destroyed service " << service << " on server " << server << std::endl;
|
info << "Finished destroying service " << service << " on server " << server << std::endl;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -196,18 +196,36 @@ namespace dropshell
|
|||||||
|
|
||||||
bool ServerConfig::check_remote_dir_exists(const std::string &dir_path, std::string user) const
|
bool ServerConfig::check_remote_dir_exists(const std::string &dir_path, std::string user) const
|
||||||
{
|
{
|
||||||
|
if (user.empty())
|
||||||
|
{
|
||||||
|
debug << "Can't check remote directory exists for " << dir_path << " as user is empty" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
sCommand scommand("", "test -d " + quote(dir_path), {});
|
sCommand scommand("", "test -d " + quote(dir_path), {});
|
||||||
return execute_ssh_command(get_SSH_INFO(user), scommand, cMode::Silent);
|
return execute_ssh_command(get_SSH_INFO(user), scommand, cMode::Silent);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerConfig::check_remote_file_exists(const std::string &file_path, std::string user) const
|
bool ServerConfig::check_remote_file_exists(const std::string &file_path, std::string user) const
|
||||||
{
|
{
|
||||||
|
if (user.empty())
|
||||||
|
{
|
||||||
|
debug << "Can't check remote file exists for " << file_path << " as user is empty" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
sCommand scommand("", "test -f " + quote(file_path), {});
|
sCommand scommand("", "test -f " + quote(file_path), {});
|
||||||
return execute_ssh_command(get_SSH_INFO(user), scommand, cMode::Silent);
|
return execute_ssh_command(get_SSH_INFO(user), scommand, cMode::Silent);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerConfig::check_remote_items_exist(const std::vector<std::string> &file_paths, std::string user) const
|
bool ServerConfig::check_remote_items_exist(const std::vector<std::string> &file_paths, std::string user) const
|
||||||
{
|
{
|
||||||
|
if (user.empty())
|
||||||
|
{
|
||||||
|
debug << "Can't check remote items exist as user is empty" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// convert file_paths to a single string, separated by spaces
|
// convert file_paths to a single string, separated by spaces
|
||||||
std::string file_paths_str;
|
std::string file_paths_str;
|
||||||
std::string file_names_str;
|
std::string file_names_str;
|
||||||
|
@ -89,7 +89,7 @@ namespace dropshell
|
|||||||
// check the service directory exists.
|
// check the service directory exists.
|
||||||
if (!fs::exists(service.local_service_path))
|
if (!fs::exists(service.local_service_path))
|
||||||
{
|
{
|
||||||
std::cerr << "Error: Service directory not found: " << service.local_service_path << std::endl;
|
warning << "Service directory not found: " << service.local_service_path << std::endl;
|
||||||
return LocalServiceInfo();
|
return LocalServiceInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user