diff --git a/source/agent-remote/ds_run.sh b/source/agent-remote/ds_run.sh new file mode 100644 index 0000000..514a38a --- /dev/null +++ b/source/agent-remote/ds_run.sh @@ -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} diff --git a/source/src/commands/install.cpp b/source/src/commands/install.cpp index 93662fd..326891d 100644 --- a/source/src/commands/install.cpp +++ b/source/src/commands/install.cpp @@ -532,11 +532,22 @@ complete -F _dropshell_completions ds // 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, false, user.user); + shared_commands::rsync_tree_to_remote( + localpath::agent_remote(), + agent_path, + 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. - + // copy server.json across. + info << "Copying server.json to remote server... " < get_all_services_status(const ServerConfig & server_env); diff --git a/source/src/utils/directories.cpp b/source/src/utils/directories.cpp index c09093c..59f8f7d 100644 --- a/source/src/utils/directories.cpp +++ b/source/src/utils/directories.cpp @@ -32,12 +32,6 @@ namespace dropshell 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() { return localpath::agent_local() + "/template_example"; @@ -146,6 +140,7 @@ namespace dropshell //------------------------------------------------------------------------------------------------ // remote paths // DROPSHELL_DIR + // |-- server.json // |-- backups // |-- temp_files // |-- agent @@ -157,9 +152,10 @@ namespace dropshell // |-- service.env (actual service config) // |-- template // |-- (script files) + // |-- template_info.env // |-- 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) {} @@ -168,6 +164,11 @@ namespace dropshell 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) {} std::string remotepath::DROPSHELL_DIR() const diff --git a/source/src/utils/directories.hpp b/source/src/utils/directories.hpp index a8e6e78..e3d5be1 100644 --- a/source/src/utils/directories.hpp +++ b/source/src/utils/directories.hpp @@ -24,9 +24,9 @@ namespace dropshell { // | |-- .json // | |-- // | |-- (...script files...) + // | |-- template_info.env // | |-- config // | |-- service.env - // | |-- .template_info.env // | |-- (...other service config files...) // backups_path @@ -39,11 +39,10 @@ namespace dropshell { // |-- services // |-- // |-- service.env - // |-- .template_info.env // |-- (...other config files for specific server&service...) 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 readme = "README.txt"; static const std::string server_json = "server.json"; @@ -54,7 +53,6 @@ namespace dropshell { std::string dropshell_json(); 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 template_info_env(const std::string &server_name, const std::string &service_name); std::string template_example(); std::string bb64(); } // namespace localfile @@ -81,6 +79,7 @@ namespace dropshell { //------------------------------------------------------------------------------------------------ // remote paths // DROPSHELL_DIR + // |-- server.json // |-- backups // |-- temp_files // |-- agent @@ -90,18 +89,18 @@ namespace dropshell { // |-- service name // |-- config // |-- service.env (actual service config) - // |-- .template_info.env // |-- template // |-- (script files) + // |-- template_info.env // |-- config // |-- service.env (default service config) - // |-- .template_info.env - // |-- (other config files for specific server&service) + // |-- (other template/example config files) class remotefile { public: remotefile(const std::string &server_name, const std::string &user); std::string service_env(const std::string &service_name) const; + std::string server_json(); private: std::string mServer_name; std::string mUser;