biiig wrench

This commit is contained in:
Your Name
2025-05-03 22:58:39 +12:00
parent 107034cf7b
commit 340170b248
51 changed files with 347 additions and 395 deletions

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
source "$AGENT_PATH/_common.sh" source "${AGENT_PATH}/_common.sh"
check_required_env_vars "CONTAINER_NAME" "DATA_VOLUME" "CONFIG_VOLUME" "CONFIG_PATH" check_required_env_vars "CONTAINER_NAME" "DATA_VOLUME" "CONFIG_VOLUME" "CONFIG_PATH"
_stop_container "$CONTAINER_NAME" _stop_container "$CONTAINER_NAME"

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
source "$AGENT_PATH/_common.sh" source "${AGENT_PATH}/_common.sh"
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "DATA_VOLUME" "CONFIG_VOLUME" check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "DATA_VOLUME" "CONFIG_VOLUME"
if ! autocreate volume=$DATA_VOLUME volume=$CONFIG_VOLUME; then if ! autocreate volume=$DATA_VOLUME volume=$CONFIG_VOLUME; then

View File

@ -1,6 +1,5 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
source "$AGENT_PATH/_common.sh"
check_required_env_vars "CONTAINER_NAME" check_required_env_vars "CONTAINER_NAME"
# Main script. # Main script.

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
source "$AGENT_PATH/_common.sh" source "${AGENT_PATH}/_common.sh"
# NUKE SCRIPT # NUKE SCRIPT
# This is run after the uninstall.sh script to delete all data. # This is run after the uninstall.sh script to delete all data.

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
source "$AGENT_PATH/_common.sh" source "${AGENT_PATH}/_common.sh"
echo 80 echo 80

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
source "$AGENT_PATH/_common.sh" source "${AGENT_PATH}/_common.sh"
# RESTORE SCRIPT # RESTORE SCRIPT

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
source "$AGENT_PATH/_common.sh" source "${AGENT_PATH}/_common.sh"
# START SCRIPT # START SCRIPT
# The start script is required for all templates. # The start script is required for all templates.

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
source "$AGENT_PATH/_common.sh" source "${AGENT_PATH}/_common.sh"
# STATUS SCRIPT # STATUS SCRIPT
# The status script is OPTIONAL. # The status script is OPTIONAL.

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
source "$AGENT_PATH/_common.sh" source "${AGENT_PATH}/_common.sh"
# STOP SCRIPT # STOP SCRIPT
# The stop script is required for all templates. # The stop script is required for all templates.

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
source "$AGENT_PATH/_common.sh" source "${AGENT_PATH}/_common.sh"
# UNINSTALL SCRIPT # UNINSTALL SCRIPT
# The uninstall script is required for all templates. # The uninstall script is required for all templates.

View File

@ -6,12 +6,7 @@
# It is called with the path to the server specific env file as an argument. # It is called with the path to the server specific env file as an argument.
install_prerequisites() { check_prerequisites() {
# this script works on debian, ubuntu and Raspberry Pi OS
# it checks the following prerequisites, and installs them if missing.
# if the user is root it proceeds, otherwise it checks for sudo privileges.
# if neither exists, and a prerequisite is missing, the script exits with failure.
# prerequisites: # prerequisites:
# - bash # - bash
# - curl # - curl
@ -29,6 +24,6 @@ install_prerequisites() {
done done
} }
install_prerequisites check_prerequisites
exit 0 exit 0

View File

@ -1,6 +1 @@
#!/bin/bash #!/bin/bash
# NUKE SCRIPT
# run after uninstall.sh to delete all data.

View File

@ -7,11 +7,11 @@
# ---------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------
# summary of functions: # summary of functions:
# die "message" : Prints an error message in red and exits with status code 1. # _die "message" : Prints an error message in red and exits with status code 1.
# grey_start : Switches terminal output color to grey. # _grey_start : Switches terminal output color to grey.
# grey_end : Resets terminal output color from grey. # _grey_end : Resets terminal output color from grey.
# create_and_start_container "<run_cmd>" <container_name> : Creates/starts a container, verifying it runs. # _create_and_start_container "<run_cmd>" <container_name> : Creates/starts a container, verifying it runs.
# create_folder <folder_path> : Creates a directory if it doesn't exist (chmod 777). # _create_folder <folder_path> : Creates a directory if it doesn't exist (chmod 777).
# _check_docker_installed : Checks if Docker is installed, running, and user has permission. Returns 1 on failure. # _check_docker_installed : Checks if Docker is installed, running, and user has permission. Returns 1 on failure.
# _is_container_exists <container_name> : Checks if a container (any state) exists. Returns 1 if not found. # _is_container_exists <container_name> : Checks if a container (any state) exists. Returns 1 if not found.
# _is_container_running <container_name>: Checks if a container is currently running. Returns 1 if not running. # _is_container_running <container_name>: Checks if a container is currently running. Returns 1 if not running.
@ -21,29 +21,31 @@
# _stop_container <container_name> : Stops a running container. # _stop_container <container_name> : Stops a running container.
# _remove_container <container_name> : Stops (if needed) and removes a container. # _remove_container <container_name> : Stops (if needed) and removes a container.
# _get_container_logs <container_name> : Prints the logs for a container. # _get_container_logs <container_name> : Prints the logs for a container.
# check_required_env_vars "VAR1" ... : Checks if listed environment variables are set; calls die() if any are missing. # _check_required_env_vars "VAR1" ... : Checks if listed environment variables are set; calls _die() if any are missing.
# _root_remove_tree <path> : Removes a path using a root Docker container (for permissions). # _root_remove_tree <path> : Removes a path using a root Docker container (for permissions).
# ---------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------
# Print error message and exit with code 1 # Prints an error message in red and exits with status code 1.
# Usage: die "error message" _die() {
die() {
echo -e "\033[91mError: $1\033[0m" echo -e "\033[91mError: $1\033[0m"
exit 1 exit 1
} }
grey_start() { # Switches terminal output color to grey.
_grey_start() {
echo -e -n "\033[90m" echo -e -n "\033[90m"
} }
grey_end() { # Resets terminal output color from grey.
_grey_end() {
echo -e -n "\033[0m" echo -e -n "\033[0m"
} }
create_and_start_container() { # Creates/starts a container, verifying it runs.
_create_and_start_container() {
if [ -z "$1" ] || [ -z "$2" ]; then if [ -z "$1" ] || [ -z "$2" ]; then
die "Template error: create_and_start_container <run_cmd> <container_name>" _die "Template error: create_and_start_container <run_cmd> <container_name>"
fi fi
local run_cmd="$1" local run_cmd="$1"
@ -53,32 +55,33 @@ create_and_start_container() {
_is_container_running $container_name && return 0 _is_container_running $container_name && return 0
_start_container $container_name _start_container $container_name
else else
grey_start _grey_start
$run_cmd $run_cmd
grey_end _grey_end
fi fi
if ! _is_container_running $container_name; then if ! _is_container_running $container_name; then
die "Container ${container_name} failed to start" _die "Container ${container_name} failed to start"
fi fi
ID=$(_get_container_id $container_name) ID=$(_get_container_id $container_name)
echo "Container ${container_name} is running with ID ${ID}" echo "Container ${container_name} is running with ID ${ID}"
} }
function create_folder() { # Creates a directory if it doesn't exist (chmod 777).
_create_folder() {
local folder="$1" local folder="$1"
if [ -d "$folder" ]; then if [ -d "$folder" ]; then
return 0 return 0
fi fi
if ! mkdir -p "$folder"; then if ! mkdir -p "$folder"; then
die "Failed to create folder: $folder" _die "Failed to create folder: $folder"
fi fi
chmod 777 "$folder" chmod 777 "$folder"
echo "Folder created: $folder" echo "Folder created: $folder"
} }
# Check if docker is installed # Checks if Docker is installed, running, and user has permission. Returns 1 on failure.
_check_docker_installed() { _check_docker_installed() {
if ! command -v docker &> /dev/null; then if ! command -v docker &> /dev/null; then
echo "Docker is not installed" echo "Docker is not installed"
@ -100,7 +103,7 @@ _check_docker_installed() {
return 0 return 0
} }
# Check if a container exists # Checks if a container (any state) exists. Returns 1 if not found.
_is_container_exists() { _is_container_exists() {
if ! docker ps -a --format "{{.Names}}" | grep -q "^$1$"; then if ! docker ps -a --format "{{.Names}}" | grep -q "^$1$"; then
return 1 return 1
@ -108,7 +111,7 @@ _is_container_exists() {
return 0 return 0
} }
# Check if a container is running # Checks if a container is currently running. Returns 1 if not running.
_is_container_running() { _is_container_running() {
if ! docker ps --format "{{.Names}}" | grep -q "^$1$"; then if ! docker ps --format "{{.Names}}" | grep -q "^$1$"; then
return 1 return 1
@ -116,37 +119,37 @@ _is_container_running() {
return 0 return 0
} }
# get contianer ID # Prints the ID of the named container.
_get_container_id() { _get_container_id() {
docker ps --format "{{.ID}}" --filter "name=$1" docker ps --format "{{.ID}}" --filter "name=$1"
} }
# get container status # Prints the status string of the named container.
_get_container_status() { _get_container_status() {
docker ps --format "{{.Status}}" --filter "name=$1" docker ps --format "{{.Status}}" --filter "name=$1"
} }
# start container that exists # Starts an existing, stopped container.
_start_container() { _start_container() {
_is_container_exists $1 || return 1 _is_container_exists $1 || return 1
_is_container_running $1 && return 0 _is_container_running $1 && return 0
docker start $1 docker start $1
} }
# stop container that exists # Stops a running container.
_stop_container() { _stop_container() {
_is_container_running $1 || return 0; _is_container_running $1 || return 0;
docker stop $1 docker stop $1
} }
# remove container that exists # Stops (if needed) and removes a container.
_remove_container() { _remove_container() {
_stop_container $1 _stop_container $1
_is_container_exists $1 || return 0; _is_container_exists $1 || return 0;
docker rm $1 docker rm $1
} }
# get container logs # Prints the logs for a container.
_get_container_logs() { _get_container_logs() {
if ! _is_container_exists $1; then if ! _is_container_exists $1; then
echo "Container $1 does not exist" echo "Container $1 does not exist"
@ -156,16 +159,18 @@ _get_container_logs() {
docker logs $1 docker logs $1
} }
check_required_env_vars() { # Checks if listed environment variables are set; calls _die() if any are missing.
_check_required_env_vars() {
local required_vars=("$@") local required_vars=("$@")
for var in "${required_vars[@]}"; do for var in "${required_vars[@]}"; do
if [ -z "${!var}" ]; then if [ -z "${!var}" ]; then
die "Required environment variable $var is not set in your service.env file" _die "Required environment variable $var is not set in your service.env file"
fi fi
done done
} }
function _root_remove_tree() { # Removes a path using a root Docker container (for permissions).
_root_remove_tree() {
local to_remove="$1" local to_remove="$1"
parent=$(dirname "$to_remove") parent=$(dirname "$to_remove")
abs_parent=$(realpath "$parent") abs_parent=$(realpath "$parent")

View File

@ -1,7 +1 @@
#!/bin/bash #!/bin/bash
# UNINSTALL SCRIPT
# The uninstall script is required for all templates.
# It is used to uninstall the service from the server.
# It is called with the path to the server specific env file as an argument.

View File

@ -1,36 +1,42 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
# BACKUP SCRIPT # Nginx Example Backup Script
# The backup script is OPTIONAL.
# It is used to backup the service on the server.
# It is called with one argument: the path to the destination backup file.
# If the backup file already exists, the script should exit with a message.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
# Get backup file path from first argument # Load service environment variables
source ./service.env
_check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
BACKUP_FILE="$1" BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then if [ -z "$BACKUP_FILE" ]; then
die "Backup file path not provided" _die "Backup file path not provided"
fi fi
# Check if backup file already exists if [ -e "$BACKUP_FILE" ]; then
if [ -f "$BACKUP_FILE" ]; then _die "Backup file $BACKUP_FILE already exists"
die "Backup file $BACKUP_FILE already exists"
fi fi
# Stop container before backup echo "Backing up data for ${CONTAINER_NAME} from ${LOCAL_DATA_FOLDER} to ${BACKUP_FILE}..."
_stop_container "$CONTAINER_NAME"
Create backup of data folder # Stop container before backup?
echo "Creating backup of $LOCAL_DATA_FOLDER..." # echo "Stopping container ${CONTAINER_NAME} for backup..."
if ! tar zcvf "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER" .; then # _stop_container "$CONTAINER_NAME"
_start_container "$CONTAINER_NAME"
die "Failed to create backup" # Create backup of data folder
tar -czf "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER" .
# Check if backup command was successful
if [ $? -ne 0 ]; then
# Start container again if it was stopped
# echo "Restarting container ${CONTAINER_NAME}..."
# _start_container "$CONTAINER_NAME"
_die "Failed to create backup"
fi fi
# Start container after backup # Start container again if it was stopped
_start_container "$CONTAINER_NAME" # echo "Restarting container ${CONTAINER_NAME}..."
# _start_container "$CONTAINER_NAME"
echo "Backup created successfully: $BACKUP_FILE" echo "Backup complete: ${BACKUP_FILE}"

50
templates/example-nginx/install.sh Executable file → Normal file
View File

@ -1,41 +1,33 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
# INSTALL SCRIPT # Nginx Example Install Script
# The install script is required for all templates.
# It is used to install the service on the server.
# It is called with the path to the server specific env file as an argument.
source "$(dirname "$0")/_common.sh"
# Required environment variables # Load service environment variables
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "LOCAL_DATA_FOLDER" source ./service.env
_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "LOCAL_DATA_FOLDER"
# Create local data folder if it doesn't exist # Ensure local data folder exists
if [ -d "${LOCAL_DATA_FOLDER}" ]; then if [ ! -d "${LOCAL_DATA_FOLDER}" ]; then
echo "Local data folder ${LOCAL_DATA_FOLDER} exists, using existing data." echo "Creating local data folder ${LOCAL_DATA_FOLDER}..."
else
echo "Local data folder ${LOCAL_DATA_FOLDER} does not exist, creating..."
mkdir -p "${LOCAL_DATA_FOLDER}" mkdir -p "${LOCAL_DATA_FOLDER}"
cat <<EOF > "${LOCAL_DATA_FOLDER}/index.html" chmod 777 "${LOCAL_DATA_FOLDER}"
<html> # Optionally, copy default content if needed
<body> # cp -r ./example/* "${LOCAL_DATA_FOLDER}/"
<h1>Hello, World!</h1>
</body>
</html>
EOF
fi fi
# Test Docker echo "Checking Docker installation..."
_check_docker_installed || die "Docker test failed, aborting installation..." _check_docker_installed || _die "Docker test failed, aborting installation..."
echo "Pulling image ${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG}..."
docker pull "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || _die "Failed to pull image $IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG"
# check can pull image on remote host and exit if fails echo "Stopping and removing any existing container..."
docker pull "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || die "Failed to pull image $IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" bash ./stop.sh || _die "Failed to stop container ${CONTAINER_NAME}"
_remove_container $CONTAINER_NAME || _die "Failed to remove container ${CONTAINER_NAME}"
# remove and restart, as the env may have changed. echo "Starting container..."
bash ./stop.sh || die "Failed to stop container ${CONTAINER_NAME}" bash ./start.sh || _die "Failed to start container ${CONTAINER_NAME}"
_remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER_NAME}"
bash ./start.sh || die "Failed to start container ${CONTAINER_NAME}"
echo "Installation of ${CONTAINER_NAME} complete" echo "Installation complete for service ${CONTAINER_NAME}."
echo "You can access the service at http://${SERVER}:${HOST_PORT}"

View File

@ -1,16 +1,14 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
# LOGS SCRIPT # Nginx Example Logs Script
# The logs script is OPTIONAL.
# It is used to return the logs of the service.
# It is called with the path to the server specific env file as an argument.
source "$(dirname "$0")/_common.sh"
# Required environment variables # Load service environment variables
check_required_env_vars "CONTAINER_NAME" source ./service.env
_check_required_env_vars "CONTAINER_NAME"
echo "Container ${CONTAINER_NAME} logs:" echo "Showing logs for ${CONTAINER_NAME}... (Press Ctrl+C to stop)"
grey_start _grey_start
docker logs "${CONTAINER_NAME}" _get_container_logs $CONTAINER_NAME
grey_end _grey_end

View File

@ -1,14 +1,18 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
# NUKE SCRIPT # Nginx Example Nuke Script
# This is run after the uninstall.sh script to delete all data. # Removes container and local data folder.
# dropshell handles the configuration files, so we just need to remove
# any docker volumes and any custom local data folders.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "LOCAL_DATA_FOLDER" "CONTAINER_NAME"
# remove the local data folder # Load service environment variables
rm -rf $LOCAL_DATA_FOLDER || die "Failed to remove local data folder ${LOCAL_DATA_FOLDER}" source ./service.env
_check_required_env_vars "LOCAL_DATA_FOLDER" "CONTAINER_NAME"
echo "Nuking of ${CONTAINER_NAME} complete." # Call uninstall script first
./uninstall.sh
echo "Removing local data folder ${LOCAL_DATA_FOLDER}..."
rm -rf $LOCAL_DATA_FOLDER || _die "Failed to remove local data folder ${LOCAL_DATA_FOLDER}"
echo "Nuke complete for service ${CONTAINER_NAME}."

View File

@ -1,13 +1,18 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
# PORT SCRIPT # Nginx Example Ports Script
# The port script is OPTIONAL.
# It is used to return the ports used by the service.
# It is called with the path to the server specific env file as an argument.
source "$(dirname "$0")/_common.sh"
# Required environment variables # Load service environment variables
# check_required_env_vars "HOST_PORT" source ./service.env
echo $HOST_PORT # This template uses HOST_PORT directly if set
# check_required_env_vars "HOST_PORT"
if [ -n "$HOST_PORT" ]; then
echo $HOST_PORT
else
# Default or logic to determine port if not in env
echo 80 # Default Nginx port
fi

View File

@ -1,41 +1,42 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
# RESTORE SCRIPT # Nginx Example Restore Script
# The restore script is OPTIONAL.
# It is used to restore the service on the server from a backup file.
# It is called with one argument: the path to the backup file.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
# Get backup file path from first argument # Load service environment variables
source ./service.env
_check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
BACKUP_FILE="$1" BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then if [ -z "$BACKUP_FILE" ]; then
die "Backup file path not provided" _die "Backup file path not provided"
fi fi
# Check if backup file already exists
if [ ! -f "$BACKUP_FILE" ]; then if [ ! -f "$BACKUP_FILE" ]; then
die "Backup file $BACKUP_FILE does not exist" _die "Backup file $BACKUP_FILE does not exist"
fi fi
# # Stop container before backup echo "Uninstalling service before restore..."
bash ./uninstall.sh || die "Failed to uninstall service before restore" bash ./uninstall.sh || _die "Failed to uninstall service before restore"
# Remove existing data folder echo "Removing existing data folder ${LOCAL_DATA_FOLDER}..."
echo "Deleting ALL data in $LOCAL_DATA_FOLDER." # Use root remove in case of permission issues
_root_remove_tree "$LOCAL_DATA_FOLDER" _root_remove_tree "$LOCAL_DATA_FOLDER"
[ ! -d "$LOCAL_DATA_FOLDER" ] || die "Failed to delete $LOCAL_DATA_FOLDER" [ ! -d "$LOCAL_DATA_FOLDER" ] || _die "Failed to delete $LOCAL_DATA_FOLDER"
mkdir -p "$LOCAL_DATA_FOLDER" mkdir -p "$LOCAL_DATA_FOLDER"
[ -d "$LOCAL_DATA_FOLDER" ] || die "Failed to create $LOCAL_DATA_FOLDER" [ -d "$LOCAL_DATA_FOLDER" ] || _die "Failed to create $LOCAL_DATA_FOLDER"
chmod 777 "$LOCAL_DATA_FOLDER" # Ensure permissions
# Restore data folder from backup echo "Restoring data from ${BACKUP_FILE} to ${LOCAL_DATA_FOLDER}..."
# --strip-components=1 removes the parent folder in the tgz from the restore paths. # Assuming backup is a simple tarball of the folder contents
if ! tar xzvf "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER" --strip-components=1; then tar -xzf "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER" --strip-components=1
die "Failed to restore data folder from backup" if [ $? -ne 0 ]; then
_die "Failed to restore data folder from backup"
fi fi
# reinstall service echo "Restore complete. Reinstalling service..."
bash ./install.sh || die "Failed to reinstall service after restore" bash ./install.sh || _die "Failed to reinstall service after restore"
echo "Restore complete! Service is running again on port $HOST_PORT with restored website." echo "Service ${CONTAINER_NAME} restored and reinstalled."

2
templates/example-nginx/start.sh Executable file → Normal file
View File

@ -1,11 +1,11 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
# START SCRIPT # START SCRIPT
# The start script is required for all templates. # The start script is required for all templates.
# It is used to start the service on the server. # It is used to start the service on the server.
# It is called with the path to the server specific env file as an argument. # It is called with the path to the server specific env file as an argument.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" "HOST_PORT" "LOCAL_DATA_FOLDER" check_required_env_vars "CONTAINER_NAME" "HOST_PORT" "LOCAL_DATA_FOLDER"
[ -d "${LOCAL_DATA_FOLDER}" ] || die "Local data folder ${LOCAL_DATA_FOLDER} does not exist." [ -d "${LOCAL_DATA_FOLDER}" ] || die "Local data folder ${LOCAL_DATA_FOLDER} does not exist."

View File

@ -1,4 +1,5 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
# STATUS SCRIPT # STATUS SCRIPT
# The status script is OPTIONAL. # The status script is OPTIONAL.
@ -7,7 +8,6 @@
# This is an example of a status script that checks if the service is running. # This is an example of a status script that checks if the service is running.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" check_required_env_vars "CONTAINER_NAME"
# check if the service is running # check if the service is running

2
templates/example-nginx/stop.sh Executable file → Normal file
View File

@ -1,11 +1,11 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
# STOP SCRIPT # STOP SCRIPT
# The stop script is required for all templates. # The stop script is required for all templates.
# It is used to stop the service on the server. # It is used to stop the service on the server.
# It is called with the path to the server specific env file as an argument. # It is called with the path to the server specific env file as an argument.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" check_required_env_vars "CONTAINER_NAME"
_stop_container $CONTAINER_NAME || die "Failed to stop container ${CONTAINER_NAME}" _stop_container $CONTAINER_NAME || die "Failed to stop container ${CONTAINER_NAME}"

View File

@ -1,19 +1,21 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
# UNINSTALL SCRIPT # Nginx Example Uninstall Script
# The uninstall script is required for all templates.
# It is used to uninstall the service from the server.
# It is called with the path to the server specific env file as an argument.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "LOCAL_DATA_FOLDER"
_remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER_NAME}" # Load service environment variables
_is_container_running && die "Couldn't stop existing container" source ./service.env
_is_container_exists && die "Couldn't remove existing container" _check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "LOCAL_DATA_FOLDER"
# remove the image echo "Uninstalling service ${CONTAINER_NAME}..."
docker rmi "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || echo "Failed to remove image $IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" _remove_container $CONTAINER_NAME || _die "Failed to remove container ${CONTAINER_NAME}"
if _is_container_running $CONTAINER_NAME; then _die "Couldn't stop existing container"; fi
if _is_container_exists $CONTAINER_NAME; then _die "Couldn't remove existing container"; fi
echo "Uninstallation of ${CONTAINER_NAME} complete." # Optional: Remove image?
echo "Local data folder ${LOCAL_DATA_FOLDER} still in place." # echo "Removing image ${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG}..."
# docker rmi "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || echo "Warning: Failed to remove image (might be in use)"
echo "Service ${CONTAINER_NAME} uninstalled."
# Note: This does NOT remove the local data folder. Use nuke.sh for that.

View File

@ -1,40 +1,13 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
# BACKUP SCRIPT # Simple Object Storage Backup Script
# The backup script is OPTIONAL. # Creates a backup tarball of the volume contents.
# It is used to backup the service on the server.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME"
_check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME"
# HOT backup is fine for simple-object-storage # HOT backup is fine for simple-object-storage
autobackup "volume=${VOLUME_NAME}" $1 $2 || _die "Failed to create backup"
echo "Backup complete: ${BACKUP_FILE}"
# Get backup file path from first argument
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
die "Backup file path not provided"
fi
TEMP_DIR=$2
if [ -z "$TEMP_DIR" ]; then
die "Temporary directory not provided"
fi
# Check if backup file already exists
if [ -f "$BACKUP_FILE" ]; then
die "Backup file $BACKUP_FILE already exists"
fi
# Create backup of data folder
echo "Creating backup of $VOLUME_NAME..."
docker run --rm -v ${VOLUME_NAME}:/data -v ${TEMP_DIR}:/tempdir alpine sh -c "\
tar zcvf /tempdir/backup.tar.gz -C /data ."
cp ${TEMP_DIR}/backup.tar.gz $BACKUP_FILE
# dropshell cleans up temp dir after script finishes
echo "Backup created successfully: $BACKUP_FILE"

View File

@ -1,42 +1,27 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
# INSTALL SCRIPT # Simple Object Storage Install Script
# The install script is required for all templates. # Pulls image, creates volume/config, starts container.
# It is used to install the service on the server.
source "$(dirname "$0")/_common.sh"
# Required environment variables _check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "VOLUME_NAME" "HOST_NAME"
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "VOLUME_NAME" "HOST_NAME"
# Create volume if it doesn't exist
if ! docker volume inspect "${VOLUME_NAME}" &>/dev/null; then
echo "Volume ${VOLUME_NAME} does not exist, creating..."
docker volume create "${VOLUME_NAME}"
fi
if ! docker volume inspect "${VOLUME_NAME}" &>/dev/null; then
die "Failed to create volume ${VOLUME_NAME}"
fi
# Test Docker
_check_docker_installed || die "Docker test failed, aborting installation..."
autocreate "volume=${VOLUME_NAME}"
# check can pull image on remote host and exit if fails # check can pull image on remote host and exit if fails
docker pull "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || die "Failed to pull image $IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" echo "Pulling image ${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG}..."
docker pull "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || _die "Failed to pull image $IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG"
# remove and restart, as the env may have changed.
bash ./stop.sh || die "Failed to stop container ${CONTAINER_NAME}"
_remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER_NAME}"
bash ./start.sh || die "Failed to start container ${CONTAINER_NAME}"
echo "Installation of ${CONTAINER_NAME} complete"
echo "Stopping and removing any existing container..."
bash ./stop.sh || _die "Failed to stop container ${CONTAINER_NAME}"
_remove_container $CONTAINER_NAME || _die "Failed to remove container ${CONTAINER_NAME}"
bash ./start.sh || _die "Failed to start container ${CONTAINER_NAME}"
echo "Installation complete for service ${CONTAINER_NAME}."
# determine port. # determine port.
command -v jq &> /dev/null || die "jq could not be found, please install it" command -v jq &> /dev/null || die "jq could not be found, please install it"
[ -f "${CONFIG_PATH}/sos_config.json" ] || die "sos_config.json does not exist" [ -f "${CONFIG_PATH}/sos_config.json" ] || die "sos_config.json does not exist"
PORT=$(jq -r '.port' "${CONFIG_PATH}/sos_config.json") PORT=$(jq -r '.port' "${CONFIG_PATH}/sos_config.json")
echo "You can access the service at http://${HOST_NAME}:${PORT}" echo "You can access the service at http://${HOST_NAME}:${PORT}"

View File

@ -1,16 +1,13 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
# LOGS SCRIPT # Simple Object Storage Logs Script
# The logs script is OPTIONAL. # Shows the logs for the running container.
# It is used to return the logs of the service.
# It is called with the path to the server specific env file as an argument.
source "$(dirname "$0")/_common.sh"
# Required environment variables _check_required_env_vars "CONTAINER_NAME"
check_required_env_vars "CONTAINER_NAME"
echo "Container ${CONTAINER_NAME} logs:" echo "Showing logs for ${CONTAINER_NAME}... (Press Ctrl+C to stop)"
grey_start _grey_start
docker logs "${CONTAINER_NAME}" _get_container_logs $CONTAINER_NAME
grey_end _grey_end

View File

@ -1,12 +1,9 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
# NUKE SCRIPT # Simple Object Storage Nuke Script
# Gets run after uninstall.sh # Removes container AND volume.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME"
docker volume rm $VOLUME_NAME || die "Failed to remove volume ${VOLUME_NAME}"
echo "Nuking of ${CONTAINER_NAME} complete."
_check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME"
autonuke "volume=${VOLUME_NAME}"

View File

@ -1,11 +1,11 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
# PORT SCRIPT # PORT SCRIPT
# The port script is OPTIONAL. # The port script is OPTIONAL.
# It is used to return the ports used by the service. # It is used to return the ports used by the service.
# It is called with the path to the server specific env file as an argument. # It is called with the path to the server specific env file as an argument.
source "$(dirname "$0")/_common.sh"
# Required environment variables # Required environment variables
check_required_env_vars "CONFIG_PATH" check_required_env_vars "CONFIG_PATH"

View File

@ -1,46 +1,23 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh" || _die "Failed to source _common.sh"
# RESTORE SCRIPT # Simple Object Storage Restore Script
# The restore script is OPTIONAL. # Restores data from a backup file.
# It is used to restore the service on the server from a backup file.
# It is called with one argument: the path to the backup file.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME"
# Get backup file path from first argument _check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then echo "Uninstalling service before restore..."
die "Backup file path not provided" bash ./uninstall.sh || _die "Failed to uninstall service before restore"
echo "Restoring data for ${CONTAINER_NAME} from ${BACKUP_FILE}..."
if ! autorestore "volume=${VOLUME_NAME}" "$1" "$2"; then
_die "Failed to restore data from backup file"
fi fi
TEMP_DIR=$2 echo "Restore complete. Reinstalling service..."
if [ -z "$TEMP_DIR" ]; then
die "Temporary directory not provided"
fi
# Check if backup file already exists bash ./install.sh || _die "Failed to reinstall service after restore"
if [ ! -f "$BACKUP_FILE" ]; then
die "Backup file $BACKUP_FILE does not exist"
fi
# # Stop container before backup echo "Service ${CONTAINER_NAME} restored and reinstalled."
bash ./uninstall.sh || die "Failed to uninstall service before restore"
# Remove existing data folder
echo "Deleting ALL data in $VOLUME_NAME."
docker run --rm -v ${VOLUME_NAME}:/data alpine sh -c "\
rm -rf /data/*"
echo "Restoring data from $BACKUP_FILE to $VOLUME_NAME."
docker run --rm \
-v ${VOLUME_NAME}:/data \
-v ${BACKUP_FILE}:/backup.tar.gz \
alpine sh -c "\
tar xzvf /backup.tar.gz -C /data --strip-components=1"
# reinstall service - ensure everything is latest.
bash ./install.sh || die "Failed to reinstall service after restore"
echo "Restore complete! Service is running again."

View File

@ -1,14 +1,18 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/_common.sh" source "${AGENT_PATH}/_common.sh"
check_required_env_vars "CONTAINER_NAME" # Simple Object Storage SSH Script
# Opens a shell in the running container.
if ! _is_container_running "$CONTAINER_NAME"; then
die "Container ${CONTAINER_NAME} is not running. Can't connect to it."
_check_required_env_vars "CONTAINER_NAME"
if ! _is_container_running $CONTAINER_NAME; then
_die "Container ${CONTAINER_NAME} is not running. Can't connect to it."
fi fi
echo "Connecting to ${CONTAINER_NAME}..." echo "Connecting to container ${CONTAINER_NAME}..."
docker exec -it "${CONTAINER_NAME}" /bin/bash
docker exec -it ${CONTAINER_NAME} bash
echo "Disconnected from ${CONTAINER_NAME}" echo "Disconnected from ${CONTAINER_NAME}"

View File

@ -1,21 +1,19 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
# START SCRIPT # Simple Object Storage Start Script
# The start script is required for all templates. # Creates and starts the container using environment variables.
# It is used to start the service on the server.
# It is called with the path to the server specific env file as an argument.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME" "CONFIG_PATH" check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME" "CONFIG_PATH"
# check volume exists. # check volume exists.
if ! docker volume inspect "${VOLUME_NAME}" &>/dev/null; then if ! docker volume inspect "${VOLUME_NAME}" &>/dev/null; then
die "Docker volume ${VOLUME_NAME} does not exist" _die "Docker volume ${VOLUME_NAME} does not exist"
fi fi
# determine port. # determine port.
command -v jq &> /dev/null || die "jq could not be found, please install it" command -v jq &> /dev/null || _die "jq could not be found, please install it"
[ -f "${CONFIG_PATH}/sos_config.json" ] || die "sos_config.json does not exist" [ -f "${CONFIG_PATH}/sos_config.json" ] || _die "sos_config.json does not exist"
PORT=$(jq -r '.port' "${CONFIG_PATH}/sos_config.json") PORT=$(jq -r '.port' "${CONFIG_PATH}/sos_config.json")
@ -29,12 +27,12 @@ DOCKER_RUN_CMD="docker run -d \
if ! create_and_start_container "$DOCKER_RUN_CMD" "$CONTAINER_NAME"; then if ! create_and_start_container "$DOCKER_RUN_CMD" "$CONTAINER_NAME"; then
die "Failed to start container ${CONTAINER_NAME}" _die "Failed to start container ${CONTAINER_NAME}"
fi fi
# Check if the container is running # Check if the container is running
if ! _is_container_running "$CONTAINER_NAME"; then if ! _is_container_running "$CONTAINER_NAME"; then
die "Container ${CONTAINER_NAME} is not running" _die "Container ${CONTAINER_NAME} is not running"
fi fi
echo "Container ${CONTAINER_NAME} started" echo "Container ${CONTAINER_NAME} started"

View File

@ -1,13 +1,9 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
# STATUS SCRIPT # STATUS SCRIPT
# The status script is OPTIONAL.
# It is used to return the status of the service (0 is healthy, 1 is unhealthy).
# It is called with the path to the server specific env file as an argument.
# This is an example of a status script that checks if the service is running. # This is an example of a status script that checks if the service is running.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" check_required_env_vars "CONTAINER_NAME"
# check if the service is running # check if the service is running

View File

@ -1,13 +1,12 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
# STOP SCRIPT # Simple Object Storage Stop Script
# The stop script is required for all templates. # Stops the running container.
# It is used to stop the service on the server.
# It is called with the path to the server specific env file as an argument.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME"
_stop_container $CONTAINER_NAME || die "Failed to stop container ${CONTAINER_NAME}" _check_required_env_vars "CONTAINER_NAME"
echo "Container ${CONTAINER_NAME} stopped" echo "Stopping service ${CONTAINER_NAME}..."
_stop_container $CONTAINER_NAME || _die "Failed to stop container ${CONTAINER_NAME}"
echo "Service ${CONTAINER_NAME} stopped."

View File

@ -1,11 +1,11 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
# UNINSTALL SCRIPT # UNINSTALL SCRIPT
# The uninstall script is required for all templates. # The uninstall script is required for all templates.
# It is used to uninstall the service from the server. # It is used to uninstall the service from the server.
# It is called with the path to the server specific env file as an argument. # It is called with the path to the server specific env file as an argument.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "VOLUME_NAME" check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "VOLUME_NAME"
_remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER_NAME}" _remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER_NAME}"

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/_common.sh" source "${AGENT_PATH}/_common.sh"
# Get backup file path from argument # Get backup file path from argument
BACKUP_FILE="$1" BACKUP_FILE="$1"

2
templates/squashkiwi/install.sh Executable file → Normal file
View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/_common.sh" source "${AGENT_PATH}/_common.sh"
check_required_env_vars \ check_required_env_vars \
"IMAGE_REGISTRY" \ "IMAGE_REGISTRY" \

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/_common.sh" source "${AGENT_PATH}/_common.sh"
# check required env vars # check required env vars
check_required_env_vars \ check_required_env_vars \

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/_common.sh" source "${AGENT_PATH}/_common.sh"
check_required_env_vars "HOST_PORT" check_required_env_vars "HOST_PORT"

View File

@ -1,11 +1,11 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
# RESTORE SCRIPT # RESTORE SCRIPT
# The restore script is OPTIONAL. # The restore script is OPTIONAL.
# It is used to restore the service on the server from a backup file. # It is used to restore the service on the server from a backup file.
# It is called with one argument: the path to the backup file. # It is called with one argument: the path to the backup file.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER" check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
# Get backup file path from first argument # Get backup file path from first argument

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/_common.sh" source "${AGENT_PATH}/_common.sh"
if ! _is_container_running "$CONTAINER_NAME"; then if ! _is_container_running "$CONTAINER_NAME"; then

2
templates/squashkiwi/start.sh Executable file → Normal file
View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/_common.sh" source "${AGENT_PATH}/_common.sh"
check_required_env_vars \ check_required_env_vars \
"CONTAINER_NAME" \ "CONTAINER_NAME" \

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/_common.sh" source "${AGENT_PATH}/_common.sh"
check_required_env_vars \ check_required_env_vars \
"CONTAINER_NAME" \ "CONTAINER_NAME" \

2
templates/squashkiwi/stop.sh Executable file → Normal file
View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/_common.sh" source "${AGENT_PATH}/_common.sh"
check_required_env_vars \ check_required_env_vars \
"CONTAINER_NAME" "CONTAINER_NAME"

View File

@ -1,11 +1,11 @@
#!/bin/bash #!/bin/bash
source "${AGENT_PATH}/_common.sh"
# UNINSTALL SCRIPT # UNINSTALL SCRIPT
# The uninstall script is required for all templates. # The uninstall script is required for all templates.
# It is used to uninstall the service from the server. # It is used to uninstall the service from the server.
# It is called with the path to the server specific env file as an argument. # It is called with the path to the server specific env file as an argument.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG"
_remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER_NAME}" _remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER_NAME}"

33
templates/watchtower/install.sh Executable file → Normal file
View File

@ -1,20 +1,25 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/_common.sh" source "${AGENT_PATH}/_common.sh"
# Required environment variables # Watchtower Install Script
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG"
# Test Docker
_check_docker_installed || die "Docker test failed, aborting installation..."
# check can pull image on remote host and exit if fails # Load service environment variables
echo "Pulling image ${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG}" source ./service.env
docker pull "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || die "Failed to pull image $IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" _check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG"
# remove and restart, as the env may have changed. echo "Checking Docker installation..."
echo "Removing old container ${CONTAINER_NAME}" _check_docker_installed || _die "Docker test failed, aborting installation..."
_remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER_NAME}"
echo "Starting container ${CONTAINER_NAME}"
bash ./start.sh $1 || die "Failed to start container ${CONTAINER_NAME}"
echo "Installation of ${CONTAINER_NAME} complete" echo "Pulling image ${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG}..."
docker pull "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || _die "Failed to pull image $IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG"
echo "Stopping and removing any existing container..."
# No need to check failure, might not exist
_stop_container $CONTAINER_NAME
_remove_container $CONTAINER_NAME || _die "Failed to remove container ${CONTAINER_NAME}"
echo "Starting container..."
bash ./start.sh $1 || _die "Failed to start container ${CONTAINER_NAME}"
echo "Installation complete for service ${CONTAINER_NAME}."

View File

@ -1,10 +1,14 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/_common.sh" source "${AGENT_PATH}/_common.sh"
# Required environment variables # Watchtower Logs Script
check_required_env_vars "CONTAINER_NAME"
echo "Container ${CONTAINER_NAME} logs:"
grey_start # Load service environment variables
docker logs "${CONTAINER_NAME}" source ./service.env
grey_end _check_required_env_vars "CONTAINER_NAME"
echo "Showing logs for ${CONTAINER_NAME}... (Press Ctrl+C to stop)"
_grey_start
_get_container_logs $CONTAINER_NAME
_grey_end

44
templates/watchtower/start.sh Executable file → Normal file
View File

@ -1,28 +1,38 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/_common.sh" source "${AGENT_PATH}/_common.sh"
SERVICE_CONFIG_DIR="$1" # Watchtower Start Script
# Required environment variables
check_required_env_vars "CONTAINER_NAME" "INTERVAL" # Load service environment variables
source ./service.env
_check_required_env_vars "CONTAINER_NAME" "INTERVAL"
# Optional arguments (e.g., --cleanup, --monitor-only)
EXTRA_ARGS=$1
DOCKER_RUN_CMD="docker run -d \ DOCKER_RUN_CMD="docker run -d \
--restart unless-stopped \ --name ${CONTAINER_NAME} \
--name ${CONTAINER_NAME} \ --restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \ -v /var/run/docker.sock:/var/run/docker.sock \
-v ${SERVICE_CONFIG_DIR}/config.json:/config.json ${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG} \
${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG} \ --interval ${INTERVAL} ${EXTRA_ARGS}"
--interval ${INTERVAL}"
if ! create_and_start_container "$DOCKER_RUN_CMD" "$CONTAINER_NAME"; then echo "Starting container ${CONTAINER_NAME}..."
echo "RUN_CMD failed:"
echo "$DOCKER_RUN_CMD" if ! _create_and_start_container "$DOCKER_RUN_CMD" "$CONTAINER_NAME"; then
die "Failed to start container ${CONTAINER_NAME}" # If creation/start failed, attempt to display logs if container exists
if _is_container_exists $CONTAINER_NAME; then
echo "Attempting to get logs from failed container..."
_get_container_logs $CONTAINER_NAME
fi
_die "Failed to start container ${CONTAINER_NAME}"
fi fi
# Check if the container is running # Check if the container is running after successful start command
if ! _is_container_running "$CONTAINER_NAME"; then if ! _is_container_running "$CONTAINER_NAME"; then
die "Container ${CONTAINER_NAME} is not running" _get_container_logs $CONTAINER_NAME # Show logs if it immediately exited
_die "Container ${CONTAINER_NAME} is not running after start attempt"
fi fi
echo "Container ${CONTAINER_NAME} started" echo "Service ${CONTAINER_NAME} started successfully."

View File

@ -1,14 +1,17 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/_common.sh" source "${AGENT_PATH}/_common.sh"
# Required environment variables # Watchtower Status Script
check_required_env_vars "CONTAINER_NAME"
# check if the service is running
_is_container_running $CONTAINER_NAME || die "Service is not running - did not find container $CONTAINER_NAME."
# check if the service is healthy # Load service environment variables
# curl -s -X GET http://localhost:${HOST_PORT}/health | grep -q "OK" \ source ./service.env
# || die "Service is not healthy - did not get OK response from /health endpoint." _check_required_env_vars "CONTAINER_NAME"
echo "Service is healthy" _is_container_running $CONTAINER_NAME || _die "Service is not running - did not find container $CONTAINER_NAME."
# Optional: Add specific health checks for Watchtower if needed.
# For example, check logs for recent activity or errors.
echo "Service ${CONTAINER_NAME} is running."
exit 0

14
templates/watchtower/stop.sh Executable file → Normal file
View File

@ -1,9 +1,13 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/_common.sh" source "${AGENT_PATH}/_common.sh"
# Required environment variables # Watchtower Stop Script
check_required_env_vars "CONTAINER_NAME"
_stop_container $CONTAINER_NAME || die "Failed to stop container ${CONTAINER_NAME}"
echo "Container ${CONTAINER_NAME} stopped" # Load service environment variables
source ./service.env
_check_required_env_vars "CONTAINER_NAME"
echo "Stopping service ${CONTAINER_NAME}..."
_stop_container $CONTAINER_NAME || _die "Failed to stop container ${CONTAINER_NAME}"
echo "Service ${CONTAINER_NAME} stopped."

View File

@ -1,13 +1,17 @@
#!/bin/bash #!/bin/bash
source "$(dirname "$0")/_common.sh" source "${AGENT_PATH}/_common.sh"
# Required environment variables # Watchtower Uninstall Script
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG"
_remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER_NAME}"
# remove the image # Load service environment variables
docker rmi "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || echo "Failed to remove image $IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" source ./service.env
_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG"
echo "Uninstallation of ${CONTAINER_NAME} complete." echo "Uninstalling service ${CONTAINER_NAME}..."
_remove_container $CONTAINER_NAME || _die "Failed to remove container ${CONTAINER_NAME}"
echo "Service ${CONTAINER_NAME} uninstalled."
# Note: Watchtower doesn't typically have volumes to nuke.