Compare commits
4 Commits
2025.0524.
...
2025.0524.
Author | SHA1 | Date | |
---|---|---|---|
9a141685de | |||
9c94510213 | |||
bcc78859fc | |||
a5243a7e79 |
@ -14,10 +14,10 @@ jobs:
|
|||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
cd ${{ gitea.workspace }}/docker
|
cd ${{ gitea.workspace }}/source
|
||||||
./compile.sh
|
./multibuild.sh
|
||||||
- name: Test
|
- name: Test
|
||||||
run: |
|
run: |
|
||||||
cd ${{ gitea.workspace }}/docker/output
|
cd ${{ gitea.workspace }}/source/output
|
||||||
./dropshell_x86_64 list
|
./dropshell_x86_64 list
|
||||||
./dropshell_x86_64 help
|
./dropshell_x86_64 help
|
||||||
|
@ -20,6 +20,15 @@ void CommandRegistry::register_command(const CommandInfo& info) {
|
|||||||
const CommandInfo* CommandRegistry::find_command(const std::string& name) const {
|
const CommandInfo* CommandRegistry::find_command(const std::string& name) const {
|
||||||
auto it = command_map_.find(name);
|
auto it = command_map_.find(name);
|
||||||
if (it != command_map_.end()) return it->second.get();
|
if (it != command_map_.end()) return it->second.get();
|
||||||
|
|
||||||
|
// go deep now.
|
||||||
|
for (const auto& cmd : all_commands_) {
|
||||||
|
if (cmd->names.size() > 0) {
|
||||||
|
for (const auto& altname : cmd->names) {
|
||||||
|
if (name == altname) return cmd.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,10 +194,10 @@ namespace dropshell
|
|||||||
|
|
||||||
info << "Setting SSH_USER to " << sshuser << " in the " << filenames::service_env << " file" << std::endl;
|
info << "Setting SSH_USER to " << sshuser << " in the " << filenames::service_env << " file" << std::endl;
|
||||||
{ // edit the service.env file to set the SSH_USER.
|
{ // edit the service.env file to set the SSH_USER.
|
||||||
std::string template_service_env_file = tinfo.local_template_path() / "config" / filenames::service_env;
|
std::string source_service_env = tinfo.local_template_path() / "config" / filenames::service_env;
|
||||||
ASSERT(std::filesystem::exists(template_service_env_file), "Template service env file not found: " + template_service_env_file);
|
ASSERT(std::filesystem::exists(source_service_env), "Template service env file not found: " + source_service_env);
|
||||||
std::ifstream template_service_env_file_in(template_service_env_file);
|
std::ifstream template_service_env_file_in(source_service_env);
|
||||||
std::ofstream service_env_file_out(localfile::template_info_env(server_name, service_name));
|
std::ofstream service_env_file_out(localfile::service_env(server_name, service_name));
|
||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline(template_service_env_file_in, line))
|
while (std::getline(template_service_env_file_in, line))
|
||||||
{
|
{
|
||||||
|
@ -14,7 +14,7 @@ namespace dropshell
|
|||||||
{
|
{
|
||||||
|
|
||||||
int destroy_handler(const CommandContext &ctx);
|
int destroy_handler(const CommandContext &ctx);
|
||||||
static std::vector<std::string> destroy_name_list = {"destroy"};
|
static std::vector<std::string> destroy_name_list = {"destroy", "nuke", "nuke-service","erase","destroy-service"};
|
||||||
|
|
||||||
// Static registration
|
// Static registration
|
||||||
struct DestroyCommandRegister
|
struct DestroyCommandRegister
|
||||||
@ -57,16 +57,33 @@ 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())
|
||||||
|
{
|
||||||
|
warning << "No user found for service " << service << " on " << server << std::endl;
|
||||||
|
for (auto sshuser : server_env.get_users())
|
||||||
|
{
|
||||||
|
if (server_env.check_remote_dir_exists(remotepath(server, sshuser.user).service(service), sshuser.user))
|
||||||
|
{
|
||||||
|
info << "Found a remote service directory here: " << remotepath(server, sshuser.user).service(service) << std::endl;
|
||||||
|
info << "Deleting it as user " << sshuser.user << 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);
|
service_info = get_service_info(server, service);
|
||||||
bool service_valid = SIvalid(service_info);
|
bool service_valid = SIvalid(service_info);
|
||||||
if (!service_valid)
|
if (!service_valid)
|
||||||
warning << "Invalid service: " << service << std::endl;
|
warning << "No valid service definition found for " << service << std::endl;
|
||||||
|
|
||||||
std::string user = server_env.get_user_for_service(service);
|
if (server_env.check_remote_dir_exists(remotepath(server, user).service(service), user))
|
||||||
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.
|
// run the destroy script on the remote server if it exists.
|
||||||
// otherwise just uninstall.
|
// otherwise just uninstall.
|
||||||
@ -97,25 +114,28 @@ namespace dropshell
|
|||||||
warning << "Failed to remove remote service directory" << std::endl;
|
warning << "Failed to remove remote service directory" << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
warning << "Service not found on remote server: " << remotepath(server, user).service(service) << std::endl;
|
warning << "No remote service directory found for " << service << " on "<< server << std::endl;
|
||||||
}
|
} // user is not empty.
|
||||||
|
} // server_env is valid.
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -105,6 +105,16 @@ namespace dropshell
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!gTemplateManager().template_command_exists(service_info.template_name, "backup") ||
|
||||||
|
!gTemplateManager().template_command_exists(service_info.template_name, "restore"))
|
||||||
|
{
|
||||||
|
info << service << " has no data to restore" << std::endl;
|
||||||
|
debug << "(no backup or restore script for " << service_info.template_name << ")" << std::endl;
|
||||||
|
return 0; // nothing to back up.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::optional<shared_commands::cBackupFileName> backup_details;
|
std::optional<shared_commands::cBackupFileName> backup_details;
|
||||||
if (backup_arg == "latest")
|
if (backup_arg == "latest")
|
||||||
{ // special case.
|
{ // special case.
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user