MAJRO CHANGES!@!!@#
This commit is contained in:
64
source/agent-remote/ds_run.sh
Normal file
64
source/agent-remote/ds_run.sh
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Dropshell Run
|
||||||
|
|
||||||
|
# Usage:
|
||||||
|
|
||||||
|
# ds_run.sh SERVER SERVICE COMMAND [param1] [param2] ...
|
||||||
|
|
||||||
|
# //------------------------------------------------------------------------------------------------
|
||||||
|
# // remote paths
|
||||||
|
# // DROPSHELL_DIR
|
||||||
|
# // |-- server.json
|
||||||
|
# // |-- backups
|
||||||
|
# // |-- temp_files
|
||||||
|
# // |-- agent
|
||||||
|
# // | |-- bb64
|
||||||
|
# // | |-- (other agent files)
|
||||||
|
# // |-- services
|
||||||
|
# // |-- service name
|
||||||
|
# // |-- config
|
||||||
|
# // |-- service.env (actual service config)
|
||||||
|
# // |-- template
|
||||||
|
# // |-- (script files)
|
||||||
|
# // |-- template_info.env
|
||||||
|
# // |-- config
|
||||||
|
# // |-- service.env (default service config)
|
||||||
|
# // |-- (other template/example config files)
|
||||||
|
|
||||||
|
# read SERVER, SERVICE from the command line args
|
||||||
|
export SERVER=TODO
|
||||||
|
export SERVICE=TODO
|
||||||
|
export DSCOMMAND=TODO
|
||||||
|
export DOCKER_CLI_HINTS=false
|
||||||
|
|
||||||
|
# we are in the agent directory.
|
||||||
|
export AGENT_PATH="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)"
|
||||||
|
export DROPSHELL_DIR=TODO
|
||||||
|
export CONFIG_PATH="${DROPSHELL_DIR}/services/${SERVICE}/config"
|
||||||
|
|
||||||
|
source "${AGENT_PATH}/commmon.sh"
|
||||||
|
|
||||||
|
[ -d ${CONFIG_PATH} ] || _die "Service ${SERVICE} does not exist on the server."
|
||||||
|
|
||||||
|
export TEMPLATE_INFO_ENV="${DROPSHELL_DIR}/services/${SERVICE}/template/template_info.env"
|
||||||
|
[ -f ${TEMPLATE_INFO_ENV} ] || _die "Couldn't find template_info.env at ${TEMPLATE_INFO_ENV}"
|
||||||
|
|
||||||
|
#read in the TEMPLATE_INFO_ENV, exporting all variables
|
||||||
|
source "${TEMPLATE_INFO_ENV}"
|
||||||
|
|
||||||
|
export SERVICE_ENV="${DROPSHELL_DIR}/services/${SERVICE}/config/service.env"
|
||||||
|
[ -f ${SERVICE_ENV} ] || _die "Couldn't find service.env at ${SERVICE_ENV}"
|
||||||
|
|
||||||
|
# read in the SERVICE_ENV, exporting all varialbes
|
||||||
|
source "${SERVICE_ENV}"
|
||||||
|
|
||||||
|
|
||||||
|
## Run the command
|
||||||
|
|
||||||
|
export COMMAND_TO_RUN="${DROPSHELL_DIR}/services/${SERVICE}/template/${DSCOMMAND}"
|
||||||
|
[ -f "${COMMAND_TO_RUN}" ] || COMMAND_TO_RUN="${COMMAND_TO_RUN}.sh"
|
||||||
|
[ -f "${COMMAND_TO_RUN}" ] || _die "Couldn't find the command to run: ${COMMAND_TO_RUN}"
|
||||||
|
|
||||||
|
# ensure all variables are in the environment of the command being run!!
|
||||||
|
${COMMAND_TO_RUN}
|
||||||
@@ -532,11 +532,22 @@ complete -F _dropshell_completions ds
|
|||||||
// now create the agent.
|
// now create the agent.
|
||||||
// copy across from the local agent files.
|
// copy across from the local agent files.
|
||||||
info << "Copying local agent files to remote server... " << std::flush;
|
info << "Copying local agent files to remote server... " << std::flush;
|
||||||
shared_commands::rsync_tree_to_remote(localpath::agent_remote(), agent_path, server, false, user.user);
|
shared_commands::rsync_tree_to_remote(
|
||||||
|
localpath::agent_remote(),
|
||||||
|
agent_path,
|
||||||
|
server, false, user.user);
|
||||||
info << "done." << std::endl;
|
info << "done." << std::endl;
|
||||||
|
|
||||||
// run the agent installer. Can't use BB64 yet, as we're installing it on the remote server.
|
// copy server.json across.
|
||||||
|
info << "Copying server.json to remote server... " <<std::flush;
|
||||||
|
shared_commands::rsync_file_to_remote(
|
||||||
|
localfile::server_json(server)),
|
||||||
|
remotepath(server.get_server_name(),user.user).server_json(),
|
||||||
|
server, false, user.user);
|
||||||
|
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.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)
|
if (!okay)
|
||||||
{
|
{
|
||||||
@@ -544,6 +555,7 @@ complete -F _dropshell_completions ds
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
info << "Installation on " << server.get_server_name() << " complete." << std::endl;
|
info << "Installation on " << server.get_server_name() << " complete." << std::endl;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -71,6 +71,27 @@ namespace dropshell
|
|||||||
return execute_local_command("", rsync_cmd, {}, nullptr, (silent ? cMode::Silent : cMode::Defaults));
|
return execute_local_command("", rsync_cmd, {}, nullptr, (silent ? cMode::Silent : cMode::Defaults));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
// rsync_file_to_remote : SHARED COMMAND
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
bool rsync_file_to_remote(
|
||||||
|
const std::string &local_path,
|
||||||
|
const std::string &remote_path,
|
||||||
|
const ServerConfig &server_env,
|
||||||
|
bool silent,
|
||||||
|
std::string user)
|
||||||
|
{
|
||||||
|
ASSERT(!local_path.empty() && !remote_path.empty(), "Local or remote path not specified. Can't rsync.");
|
||||||
|
ASSERT(std::filesystem::is_block_file(local_path), "Local path is not a file. Can't rsync.");
|
||||||
|
|
||||||
|
std::string rsync_cmd = "rsync --mkpath -zpc -e 'ssh -p " + server_env.get_SSH_PORT() + "' " +
|
||||||
|
quote(local_path) + " " +
|
||||||
|
quote(user + "@" + server_env.get_SSH_HOST() + ":" +
|
||||||
|
remote_path);
|
||||||
|
return execute_local_command("", rsync_cmd, {}, nullptr, (silent ? cMode::Silent : cMode::Defaults));
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// get_arch : SHARED COMMAND
|
// get_arch : SHARED COMMAND
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -59,6 +59,13 @@ namespace dropshell
|
|||||||
bool silent,
|
bool silent,
|
||||||
std::string user);
|
std::string user);
|
||||||
|
|
||||||
|
bool rsync_file_to_remote(
|
||||||
|
const std::string &local_path,
|
||||||
|
const std::string &remote_path,
|
||||||
|
const ServerConfig &server_env,
|
||||||
|
bool silent,
|
||||||
|
std::string user);
|
||||||
|
|
||||||
std::string get_arch();
|
std::string get_arch();
|
||||||
|
|
||||||
std::map<std::string, ServiceStatus> get_all_services_status(const ServerConfig & server_env);
|
std::map<std::string, ServiceStatus> get_all_services_status(const ServerConfig & server_env);
|
||||||
|
|||||||
@@ -32,12 +32,6 @@ namespace dropshell
|
|||||||
return (servicepath.empty() ? "" : (fs::path(servicepath) / filenames::service_env).string());
|
return (servicepath.empty() ? "" : (fs::path(servicepath) / filenames::service_env).string());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string template_info_env(const std::string &server_name, const std::string &service_name)
|
|
||||||
{
|
|
||||||
std::string servicepath = localpath::service(server_name, service_name);
|
|
||||||
return (servicepath.empty() ? "" : (fs::path(servicepath) / filenames::template_info_env).string());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string template_example()
|
std::string template_example()
|
||||||
{
|
{
|
||||||
return localpath::agent_local() + "/template_example";
|
return localpath::agent_local() + "/template_example";
|
||||||
@@ -146,6 +140,7 @@ namespace dropshell
|
|||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
// remote paths
|
// remote paths
|
||||||
// DROPSHELL_DIR
|
// DROPSHELL_DIR
|
||||||
|
// |-- server.json
|
||||||
// |-- backups
|
// |-- backups
|
||||||
// |-- temp_files
|
// |-- temp_files
|
||||||
// |-- agent
|
// |-- agent
|
||||||
@@ -157,9 +152,10 @@ namespace dropshell
|
|||||||
// |-- service.env (actual service config)
|
// |-- service.env (actual service config)
|
||||||
// |-- template
|
// |-- template
|
||||||
// |-- (script files)
|
// |-- (script files)
|
||||||
|
// |-- template_info.env
|
||||||
// |-- config
|
// |-- config
|
||||||
// |-- service.env (default service config)
|
// |-- service.env (default service config)
|
||||||
// |-- (other config files for specific server&service)
|
// |-- (other template/example config files)
|
||||||
|
|
||||||
remotefile::remotefile(const std::string &server_name, const std::string &user) : mServer_name(server_name), mUser(user) {}
|
remotefile::remotefile(const std::string &server_name, const std::string &user) : mServer_name(server_name), mUser(user) {}
|
||||||
|
|
||||||
@@ -168,6 +164,11 @@ namespace dropshell
|
|||||||
return remotepath(mServer_name, mUser).service_config(service_name) + "/" + filenames::service_env;
|
return remotepath(mServer_name, mUser).service_config(service_name) + "/" + filenames::service_env;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string remotefile::server_json()
|
||||||
|
{
|
||||||
|
return remotepath(mServer_name, mUser).DROPSHELL_DIR() + "/" + filenames::server_json;
|
||||||
|
}
|
||||||
|
|
||||||
remotepath::remotepath(const std::string &server_name, const std::string &user) : mServer_name(server_name), mUser(user) {}
|
remotepath::remotepath(const std::string &server_name, const std::string &user) : mServer_name(server_name), mUser(user) {}
|
||||||
|
|
||||||
std::string remotepath::DROPSHELL_DIR() const
|
std::string remotepath::DROPSHELL_DIR() const
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ namespace dropshell {
|
|||||||
// | |-- <template_name>.json
|
// | |-- <template_name>.json
|
||||||
// | |-- <template_name>
|
// | |-- <template_name>
|
||||||
// | |-- (...script files...)
|
// | |-- (...script files...)
|
||||||
|
// | |-- template_info.env
|
||||||
// | |-- config
|
// | |-- config
|
||||||
// | |-- service.env
|
// | |-- service.env
|
||||||
// | |-- .template_info.env
|
|
||||||
// | |-- (...other service config files...)
|
// | |-- (...other service config files...)
|
||||||
|
|
||||||
// backups_path
|
// backups_path
|
||||||
@@ -39,11 +39,10 @@ namespace dropshell {
|
|||||||
// |-- services
|
// |-- services
|
||||||
// |-- <service_name>
|
// |-- <service_name>
|
||||||
// |-- service.env
|
// |-- service.env
|
||||||
// |-- .template_info.env
|
|
||||||
// |-- (...other config files for specific server&service...)
|
// |-- (...other config files for specific server&service...)
|
||||||
|
|
||||||
namespace filenames {
|
namespace filenames {
|
||||||
static const std::string template_info_env = ".template_info.env";
|
static const std::string template_info_env = "template_info.env";
|
||||||
static const std::string service_env = "service.env";
|
static const std::string service_env = "service.env";
|
||||||
static const std::string readme = "README.txt";
|
static const std::string readme = "README.txt";
|
||||||
static const std::string server_json = "server.json";
|
static const std::string server_json = "server.json";
|
||||||
@@ -54,7 +53,6 @@ namespace dropshell {
|
|||||||
std::string dropshell_json();
|
std::string dropshell_json();
|
||||||
std::string server_json(const std::string &server_name);
|
std::string server_json(const std::string &server_name);
|
||||||
std::string service_env(const std::string &server_name, const std::string &service_name);
|
std::string service_env(const std::string &server_name, const std::string &service_name);
|
||||||
std::string template_info_env(const std::string &server_name, const std::string &service_name);
|
|
||||||
std::string template_example();
|
std::string template_example();
|
||||||
std::string bb64();
|
std::string bb64();
|
||||||
} // namespace localfile
|
} // namespace localfile
|
||||||
@@ -81,6 +79,7 @@ namespace dropshell {
|
|||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
// remote paths
|
// remote paths
|
||||||
// DROPSHELL_DIR
|
// DROPSHELL_DIR
|
||||||
|
// |-- server.json
|
||||||
// |-- backups
|
// |-- backups
|
||||||
// |-- temp_files
|
// |-- temp_files
|
||||||
// |-- agent
|
// |-- agent
|
||||||
@@ -90,18 +89,18 @@ namespace dropshell {
|
|||||||
// |-- service name
|
// |-- service name
|
||||||
// |-- config
|
// |-- config
|
||||||
// |-- service.env (actual service config)
|
// |-- service.env (actual service config)
|
||||||
// |-- .template_info.env
|
|
||||||
// |-- template
|
// |-- template
|
||||||
// |-- (script files)
|
// |-- (script files)
|
||||||
|
// |-- template_info.env
|
||||||
// |-- config
|
// |-- config
|
||||||
// |-- service.env (default service config)
|
// |-- service.env (default service config)
|
||||||
// |-- .template_info.env
|
// |-- (other template/example config files)
|
||||||
// |-- (other config files for specific server&service)
|
|
||||||
|
|
||||||
class remotefile {
|
class remotefile {
|
||||||
public:
|
public:
|
||||||
remotefile(const std::string &server_name, const std::string &user);
|
remotefile(const std::string &server_name, const std::string &user);
|
||||||
std::string service_env(const std::string &service_name) const;
|
std::string service_env(const std::string &service_name) const;
|
||||||
|
std::string server_json();
|
||||||
private:
|
private:
|
||||||
std::string mServer_name;
|
std::string mServer_name;
|
||||||
std::string mUser;
|
std::string mUser;
|
||||||
|
|||||||
Reference in New Issue
Block a user