This commit is contained in:
@@ -69,7 +69,7 @@ namespace dropshell
|
||||
if (!SIvalid(service_info))
|
||||
return false;
|
||||
|
||||
server_env_manager server_env(server);
|
||||
server_config server_env(server);
|
||||
if (!server_env.is_valid())
|
||||
return false;
|
||||
|
||||
@@ -90,9 +90,10 @@ namespace dropshell
|
||||
}
|
||||
|
||||
// Create service directory
|
||||
std::string remote_service_path = remotepath::service(server, service);
|
||||
std::string user = server_env.get_user_for_service(server, service);
|
||||
std::string remote_service_path = remotepath(server,user).service(service);
|
||||
std::string mkdir_cmd = "mkdir -p " + quote(remote_service_path);
|
||||
if (!execute_ssh_command(server_env.get_SSH_INFO(), sCommand("", mkdir_cmd, {}), cMode::Silent))
|
||||
if (!execute_ssh_command(server_env.get_SSH_INFO(user), sCommand("", mkdir_cmd, {}), cMode::Silent))
|
||||
{
|
||||
std::cerr << "Failed to create service directory " << remote_service_path << std::endl;
|
||||
return false;
|
||||
@@ -100,7 +101,7 @@ namespace dropshell
|
||||
|
||||
// Check if rsync is installed on remote host
|
||||
std::string check_rsync_cmd = "which rsync";
|
||||
if (!execute_ssh_command(server_env.get_SSH_INFO(), sCommand("", check_rsync_cmd, {}), cMode::Silent))
|
||||
if (!execute_ssh_command(server_env.get_SSH_INFO(user), sCommand("", check_rsync_cmd, {}), cMode::Silent))
|
||||
{
|
||||
std::cerr << "rsync is not installed on the remote host" << std::endl;
|
||||
return false;
|
||||
@@ -108,8 +109,8 @@ namespace dropshell
|
||||
|
||||
// Copy template files
|
||||
debug << "Copying: [LOCAL] " << tinfo.local_template_path() << std::endl
|
||||
<< std::string(8, ' ') << "[REMOTE] " << remotepath::service_template(server, service) << "/" << std::endl;
|
||||
if (!shared_commands::rsync_tree_to_remote(tinfo.local_template_path().string(), remotepath::service_template(server, service),
|
||||
<< std::string(8, ' ') << "[REMOTE] " << remotepath(server,user).service_template(service) << "/" << std::endl;
|
||||
if (!shared_commands::rsync_tree_to_remote(tinfo.local_template_path().string(), remotepath(server,user).service_template(service),
|
||||
server_env, false))
|
||||
{
|
||||
std::cerr << "Failed to copy template files using rsync" << std::endl;
|
||||
@@ -118,8 +119,8 @@ namespace dropshell
|
||||
|
||||
// Copy service files
|
||||
debug << "Copying: [LOCAL] " << localpath::service(server, service) << std::endl
|
||||
<< std::string(8, ' ') << "[REMOTE] " << remotepath::service_config(server, service) << std::endl;
|
||||
if (!shared_commands::rsync_tree_to_remote(localpath::service(server, service), remotepath::service_config(server, service),
|
||||
<< std::string(8, ' ') << "[REMOTE] " << remotepath(server,user).service_config(service) << std::endl;
|
||||
if (!shared_commands::rsync_tree_to_remote(localpath::service(server, service), remotepath(server,user).service_config(service),
|
||||
server_env, false))
|
||||
{
|
||||
std::cerr << "Failed to copy service files using rsync" << std::endl;
|
||||
@@ -263,36 +264,38 @@ namespace dropshell
|
||||
// install the dropshell agent on the given server.
|
||||
maketitle("Installing dropshell agent on " + server, sColour::INFO);
|
||||
|
||||
std::string agent_path = remotepath::agent(server);
|
||||
if (agent_path.empty())
|
||||
{
|
||||
error << "Failed to get agent path for " << server << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
server_env_manager server_env(server);
|
||||
server_config server_env(server);
|
||||
if (!server_env.is_valid())
|
||||
{
|
||||
error << "Invalid server environment for " << server << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 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);
|
||||
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(), sCommand(agent_path, "agent-install.sh",{}), cMode::Defaults | cMode::NoBB64, nullptr);
|
||||
if (!okay)
|
||||
for (const auto &user : server_env.get_users())
|
||||
{
|
||||
error << "ERROR: Failed to install remote agent on " << server << std::endl;
|
||||
return 1;
|
||||
}
|
||||
info << "Installing agent for user " << user.user << " on " << server << std::endl;
|
||||
|
||||
info << "Installation on " << server << " complete." << 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);
|
||||
|
||||
// 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);
|
||||
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);
|
||||
if (!okay)
|
||||
{
|
||||
error << "ERROR: Failed to install remote agent on " << server << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
info << "Installation on " << server << " complete." << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -313,10 +316,10 @@ namespace dropshell
|
||||
return rval;
|
||||
|
||||
// install the dropshell agent on all servers.
|
||||
std::vector<ServerInfo> servers = get_configured_servers();
|
||||
std::vector<server_config> servers = get_configured_servers();
|
||||
for (const auto &server : servers)
|
||||
{
|
||||
rval = install_server(server.name);
|
||||
rval = install_server(server.get_server_name());
|
||||
if (rval != 0)
|
||||
return rval;
|
||||
}
|
||||
|
Reference in New Issue
Block a user