diff --git a/src/server_env.cpp b/src/server_env.cpp index ebea347..50738b2 100644 --- a/src/server_env.cpp +++ b/src/server_env.cpp @@ -78,7 +78,7 @@ server_env::server_env(const std::string& path) : mValid(false) { } // Verify required variables exist - for (const auto& var : {"SSH_HOST", "SSH_USER", "SSH_PORT"}) { + for (const auto& var : {"SSH_HOST", "SSH_USER", "SSH_PORT", "DROPSHELL_DIR"}) { if (variables.find(var) == variables.end()) { // print the contents of the _server.env file to screen: print_file(env_path.string()); @@ -130,4 +130,8 @@ std::string server_env::get_SSH_PORT() { return get_variable("SSH_PORT"); } +std::string server_env::get_DROPSHELL_DIR() { + return get_variable("DROPSHELL_DIR"); +} + } // namespace dropshell \ No newline at end of file diff --git a/src/server_env.hpp b/src/server_env.hpp index 7cf5183..46e1448 100644 --- a/src/server_env.hpp +++ b/src/server_env.hpp @@ -24,6 +24,8 @@ class server_env { std::string get_SSH_USER(); std::string get_SSH_PORT(); + std::string get_DROPSHELL_DIR(); + bool is_valid(); private: diff --git a/src/server_service.hpp b/src/server_service.hpp index c16a51d..c1be720 100644 --- a/src/server_service.hpp +++ b/src/server_service.hpp @@ -9,9 +9,25 @@ class server_service { public: server_service(); bool init(const std::string& server_name, const std::string& service_name); - bool install(); - bool is_installed(); + + // install the service over ssh, using the credentials from _server.env (via server_env.hpp), by: + // 1. check if the server_name exists, and the service_name refers to a valid template + // 2. check if service_name is valid for the server_name + // 3. create the service directory on the server at {DROPSHELL_DIR}/{service_name} + // 3. copy the template files into that service directory/template (from the templates directory for the specified server, using templates.hpp to identify the path) + // 4. copying the {service_name}.env file to the service directory (from the server directory for the specified server) + // 5. running the install.sh script on the server, passing the {service_name}.env file as an argument + bool install(); + // run a command over ssh, using the credentials from _server.env (via server_env.hpp) + // first check that the command corresponds to a valid .sh file in the service directory + // then run the command, passing the {service_name}.env file as an argument + // do a lot of checks, such as: + // checking that we can ssh to the server. + // checking whether the service directory exists on the server. + // checking that the command exists in the service directory. + // checking that the command is a valid .sh file. + // checking that the {service_name}.env file exists in the service directory. bool run_command(const std::string& command); }; diff --git a/templates/squashkiwi/status.sh b/templates/squashkiwi/status.sh new file mode 100644 index 0000000..b3f5bd9 --- /dev/null +++ b/templates/squashkiwi/status.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Source common functions +source "$(dirname "$0")/_common.sh" + +# Load environment variables +load_env "$1" || exit 1 + +# check if the service is running +if ! docker ps | grep -q "$CONTAINER_NAME"; then + echo "Service is not running" + exit 1 +fi + +echo "Service is running" + +# curl -s -X GET http://localhost:8080/health | grep -q "OK" +if ! curl -s -X GET http://localhost:${HOST_PORT}/health | grep -q "OK"; then + echo "Service is not healthy" + exit 1 +fi + +echo "Service is healthy" +return 0