Fix list a bit
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled

This commit is contained in:
Your Name
2025-05-23 23:07:26 +12:00
parent b07704612b
commit e1c631dc72
11 changed files with 174 additions and 136 deletions

View File

@@ -63,15 +63,13 @@ namespace dropshell
// ------------------------------------------------------------------------------------------------
// install service over ssh : SHARED COMMAND
// ------------------------------------------------------------------------------------------------
bool install_service(const std::string &server, const std::string &service)
bool install_service(const server_config &server_env, const std::string &service)
{
LocalServiceInfo service_info = get_service_info(server, service);
std::string server = server_env.get_server_name();
LocalServiceInfo service_info = get_service_info(server_env.get_server_name(), service);
if (!SIvalid(service_info))
return false;
server_config server_env(server);
if (!server_env.is_valid())
return false;
maketitle("Installing " + service + " (" + service_info.template_name + ") on " + server);
@@ -259,42 +257,35 @@ namespace dropshell
return 0;
}
int install_server(const std::string &server)
int install_server(const server_config &server)
{
// install the dropshell agent on the given server.
maketitle("Installing dropshell agent on " + server, sColour::INFO);
maketitle("Installing dropshell agent on " + server.get_server_name(), sColour::INFO);
server_config server_env(server);
if (!server_env.is_valid())
for (const auto &user : server.get_users())
{
error << "Invalid server environment for " << server << std::endl;
return 1;
}
info << "Installing agent for user " << user.user << " on " << server.get_server_name() << std::endl;
for (const auto &user : server_env.get_users())
{
info << "Installing agent for user " << user.user << " on " << server << std::endl;
std::string agent_path = remotepath(server,user.user).agent();
ASSERT(agent_path == user.dir, "Agent path does not match user directory for "+user.user+"@" + server + " : " + agent_path + " != " + user.dir);
ASSERT(!agent_path.empty(), "Agent path is empty for " + user.user + "@" + server);
std::string agent_path = remotepath(server.get_server_name(),user.user).agent();
ASSERT(agent_path == user.dir, "Agent path does not match user directory for "+user.user+"@" + server.get_server_name() + " : " + agent_path + " != " + user.dir);
ASSERT(!agent_path.empty(), "Agent path is empty for " + user.user + "@" + server.get_server_name());
// now create the agent.
// copy across from the local agent files.
info << "Copying local agent files to remote server... " << std::flush;
shared_commands::rsync_tree_to_remote(localpath::agent_remote(), agent_path, server_env, false);
shared_commands::rsync_tree_to_remote(localpath::agent_remote(), agent_path, server, false);
info << "done." << std::endl;
// run the agent installer. Can't use BB64 yet, as we're installing it on the remote server.
bool okay = execute_ssh_command(server_env.get_SSH_INFO(user.user), sCommand(agent_path, "agent-install.sh",{}), cMode::Defaults | cMode::NoBB64, nullptr);
bool okay = execute_ssh_command(server.get_SSH_INFO(user.user), sCommand(agent_path, "agent-install.sh",{}), cMode::Defaults | cMode::NoBB64, nullptr);
if (!okay)
{
error << "ERROR: Failed to install remote agent on " << server << std::endl;
error << "ERROR: Failed to install remote agent on " << server.get_server_name() << std::endl;
return 1;
}
info << "Installation on " << server << " complete." << std::endl;
info << "Installation on " << server.get_server_name() << " complete." << std::endl;
}
return 0;
}
@@ -319,7 +310,7 @@ namespace dropshell
std::vector<server_config> servers = get_configured_servers();
for (const auto &server : servers)
{
rval = install_server(server.get_server_name());
rval = install_server(server);
if (rval != 0)
return rval;
}
@@ -352,15 +343,24 @@ namespace dropshell
}
// install service(s)
if (!server_exists(server))
{
error << "Server " << server << " does not exist." << std::endl;
info << "Create it with: dropshell create-server " << server << std::endl;
return 1;
}
server_config server_env(server);
ASSERT(server_env.is_valid(), "Invalid server environment for " + server);
if (safearg(ctx.args, 1) == "all")
{
// install all services on the server
maketitle("Installing all services on " + server);
bool okay = true;
std::vector<LocalServiceInfo> services = get_server_services_info(server);
for (const auto &service : services)
for (const auto &lsi : services)
{
if (!shared_commands::install_service(server, service.service_name))
if (!shared_commands::install_service(server_env, lsi.service_name))
okay = false;
}
return okay ? 0 : 1;
@@ -368,7 +368,7 @@ namespace dropshell
else
{ // install the specific service.
std::string service = safearg(ctx.args, 1);
return shared_commands::install_service(server, service) ? 0 : 1;
return shared_commands::install_service(server_env, service) ? 0 : 1;
}
}