Broken
This commit is contained in:
@@ -61,7 +61,7 @@ namespace dropshell
|
||||
|
||||
std::string rsync_cmd = "rsync --delete --mkpath -zrpc -e 'ssh -p " + server_env.get_SSH_PORT() + "' " +
|
||||
quote(local_path + "/") + " " +
|
||||
quote(server_env.get_SSH_USER() + "@" + server_env.get_SSH_HOST() + ":" +
|
||||
quote(server_env.get_SSH_UNPRIVILEGED_USER() + "@" + server_env.get_SSH_HOST() + ":" +
|
||||
remote_path + "/");
|
||||
return execute_local_command("", rsync_cmd, {}, nullptr, (silent ? cMode::Silent : cMode::Defaults));
|
||||
}
|
||||
@@ -84,11 +84,12 @@ namespace dropshell
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// cRemoteTempFolder : SHARED CLASS
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
cRemoteTempFolder::cRemoteTempFolder(const server_env_manager &server_env) : mServerEnv(server_env)
|
||||
cRemoteTempFolder::cRemoteTempFolder(const server_env_manager &server_env, std::string user) :
|
||||
mServerEnv(server_env), mUser(user)
|
||||
{
|
||||
std::string p = remotepath::temp_files(server_env.get_server_name()) + "/" + random_alphanumeric_string(10);
|
||||
std::string p = remotepath(server_env.get_server_name(),user).temp_files() + "/" + random_alphanumeric_string(10);
|
||||
std::string mkdir_cmd = "mkdir -p " + quote(p);
|
||||
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))
|
||||
error << "Failed to create temp directory on server" << std::endl;
|
||||
else
|
||||
mPath = p;
|
||||
@@ -97,7 +98,7 @@ namespace dropshell
|
||||
cRemoteTempFolder::~cRemoteTempFolder()
|
||||
{
|
||||
std::string rm_cmd = "rm -rf " + quote(mPath);
|
||||
execute_ssh_command(mServerEnv.get_SSH_INFO(), sCommand("", rm_cmd, {}), cMode::Silent);
|
||||
execute_ssh_command(mServerEnv.get_SSH_INFO(mUser), sCommand("", rm_cmd, {}), cMode::Silent);
|
||||
}
|
||||
|
||||
std::string cRemoteTempFolder::path() const
|
||||
@@ -119,49 +120,54 @@ namespace dropshell
|
||||
return status;
|
||||
}
|
||||
|
||||
std::string output;
|
||||
if (!execute_ssh_command(env.get_SSH_INFO(), sCommand(remotepath::agent(server_name), "./_allservicesstatus.sh", {{"HOST_NAME", server_name}, {"SERVER", server_name}, {"AGENT_PATH", remotepath::agent(server_name)}}),
|
||||
cMode::Silent,
|
||||
&output))
|
||||
return status;
|
||||
for (const auto& user : env.get_users()) {
|
||||
std::string output;
|
||||
std::string agentpath = remotepath(server_name,user.user).agent();
|
||||
if (!execute_ssh_command(env.get_SSH_INFO(user.user),
|
||||
sCommand(agentpath, "./_allservicesstatus.sh", {{"HOST_NAME", server_name}, {"SERVER", server_name}, {"AGENT_PATH", agentpath}}),
|
||||
cMode::Silent,
|
||||
&output))
|
||||
return status;
|
||||
|
||||
std::stringstream ss(output);
|
||||
std::string line;
|
||||
while (std::getline(ss, line))
|
||||
{
|
||||
std::string key, value;
|
||||
std::size_t pos = line.find("=");
|
||||
if (pos != std::string::npos)
|
||||
std::stringstream ss(output);
|
||||
std::string line;
|
||||
while (std::getline(ss, line))
|
||||
{
|
||||
key = dequote(trim(line.substr(0, pos)));
|
||||
value = dequote(trim(line.substr(pos + 1)));
|
||||
std::string key, value;
|
||||
std::size_t pos = line.find("=");
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
key = dequote(trim(line.substr(0, pos)));
|
||||
value = dequote(trim(line.substr(pos + 1)));
|
||||
|
||||
// decode key, it's of format SERVICENAME_[HEALTH|PORTS]
|
||||
std::string service_name = key.substr(0, key.find_last_of("_"));
|
||||
std::string status_type = key.substr(key.find_last_of("_") + 1);
|
||||
// decode key, it's of format SERVICENAME_[HEALTH|PORTS]
|
||||
std::string service_name = key.substr(0, key.find_last_of("_"));
|
||||
std::string status_type = key.substr(key.find_last_of("_") + 1);
|
||||
|
||||
if (status_type == "HEALTH")
|
||||
{ // healthy|unhealthy|unknown
|
||||
if (value == "healthy")
|
||||
status[service_name].health = HealthStatus::HEALTHY;
|
||||
else if (value == "unhealthy")
|
||||
status[service_name].health = HealthStatus::UNHEALTHY;
|
||||
else if (value == "unknown")
|
||||
status[service_name].health = HealthStatus::UNKNOWN;
|
||||
else
|
||||
status[service_name].health = HealthStatus::ERROR;
|
||||
}
|
||||
else if (status_type == "PORTS")
|
||||
{ // port1,port2,port3
|
||||
std::vector<std::string> ports = string2multi(value);
|
||||
for (const auto &port : ports)
|
||||
{
|
||||
if (port != "unknown")
|
||||
status[service_name].ports.push_back(str2int(port));
|
||||
if (status_type == "HEALTH")
|
||||
{ // healthy|unhealthy|unknown
|
||||
if (value == "healthy")
|
||||
status[service_name].health = HealthStatus::HEALTHY;
|
||||
else if (value == "unhealthy")
|
||||
status[service_name].health = HealthStatus::UNHEALTHY;
|
||||
else if (value == "unknown")
|
||||
status[service_name].health = HealthStatus::UNKNOWN;
|
||||
else
|
||||
status[service_name].health = HealthStatus::ERROR;
|
||||
}
|
||||
else if (status_type == "PORTS")
|
||||
{ // port1,port2,port3
|
||||
std::vector<std::string> ports = string2multi(value);
|
||||
for (const auto &port : ports)
|
||||
{
|
||||
if (port != "unknown")
|
||||
status[service_name].ports.push_back(str2int(port));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -215,13 +221,15 @@ namespace dropshell
|
||||
return HealthStatus::ERROR;
|
||||
}
|
||||
|
||||
if (!env.check_remote_dir_exists(remotepath::service(server, service)))
|
||||
std::string user = env.get_user_for_service(server, service);
|
||||
|
||||
if (!env.check_remote_dir_exists(remotepath(server,user).service(service), user))
|
||||
{
|
||||
return HealthStatus::NOTINSTALLED;
|
||||
}
|
||||
|
||||
std::string script_path = remotepath::service_template(server, service) + "/status.sh";
|
||||
if (!env.check_remote_file_exists(script_path))
|
||||
std::string script_path = remotepath(server,user).service_template(service) + "/status.sh";
|
||||
if (!env.check_remote_file_exists(script_path, user))
|
||||
{
|
||||
return HealthStatus::UNKNOWN;
|
||||
}
|
||||
@@ -307,7 +315,7 @@ namespace dropshell
|
||||
return false;
|
||||
}
|
||||
ASSERT(!remote_path.empty() && !local_path.empty(), "Remote or local path not specified. Can't scp.");
|
||||
std::string scp_cmd = "scp -P " + server_env.get_SSH_PORT() + " " + quote(local_path) + " " + server_env.get_SSH_USER() + "@" + server_env.get_SSH_HOST() + ":" + quote(remote_path) + (silent ? " > /dev/null 2>&1" : "");
|
||||
std::string scp_cmd = "scp -P " + server_env.get_SSH_PORT() + " " + quote(local_path) + " " + server_env.get_SSH_UNPRIVILEGED_USER() + "@" + server_env.get_SSH_HOST() + ":" + quote(remote_path) + (silent ? " > /dev/null 2>&1" : "");
|
||||
return execute_local_command("", scp_cmd, {}, nullptr, (silent ? cMode::Silent : cMode::Defaults));
|
||||
}
|
||||
|
||||
@@ -322,7 +330,7 @@ namespace dropshell
|
||||
return false;
|
||||
}
|
||||
ASSERT(!remote_path.empty() && !local_path.empty(), "Remote or local path not specified. Can't scp.");
|
||||
std::string scp_cmd = "scp -P " + server_env.get_SSH_PORT() + " " + server_env.get_SSH_USER() + "@" + server_env.get_SSH_HOST() + ":" + quote(remote_path) + " " + quote(local_path) + (silent ? " > /dev/null 2>&1" : "");
|
||||
std::string scp_cmd = "scp -P " + server_env.get_SSH_PORT() + " " + server_env.get_SSH_UNPRIVILEGED_USER() + "@" + server_env.get_SSH_HOST() + ":" + quote(remote_path) + " " + quote(local_path) + (silent ? " > /dev/null 2>&1" : "");
|
||||
return execute_local_command("", scp_cmd, {}, nullptr, (silent ? cMode::Silent : cMode::Defaults));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user