diff --git a/replace_die.sh b/replace_die.sh new file mode 100644 index 0000000..abbf62f --- /dev/null +++ b/replace_die.sh @@ -0,0 +1,2 @@ +#!/bin/bash +echo "Replacing die with _die in all template scripts..." diff --git a/templates/caddy/backup.sh b/templates/caddy/backup.sh index 18ef3cb..e6d6d76 100644 --- a/templates/caddy/backup.sh +++ b/templates/caddy/backup.sh @@ -1,6 +1,6 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" -check_required_env_vars "CONTAINER_NAME" "DATA_VOLUME" "CONFIG_VOLUME" "CONFIG_PATH" +check_required_env_vars _stop_container "$CONTAINER_NAME" diff --git a/templates/caddy/install.sh b/templates/caddy/install.sh index 89d9d2f..dbc90cb 100644 --- a/templates/caddy/install.sh +++ b/templates/caddy/install.sh @@ -1,6 +1,6 @@ #!/bin/bash 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" "CONFIG_PATH" if ! autocreate volume=$DATA_VOLUME volume=$CONFIG_VOLUME; then die "Failed to autocreate volumes and paths" diff --git a/templates/caddy/logs.sh b/templates/caddy/logs.sh index 61d4451..25ee2d3 100644 --- a/templates/caddy/logs.sh +++ b/templates/caddy/logs.sh @@ -1,6 +1,6 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" -check_required_env_vars "CONTAINER_NAME" +check_required_env_vars # Main script. echo "Container ${CONTAINER_NAME} logs:" diff --git a/templates/caddy/nuke.sh b/templates/caddy/nuke.sh index b076810..04652ca 100644 --- a/templates/caddy/nuke.sh +++ b/templates/caddy/nuke.sh @@ -1,12 +1,12 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars # NUKE SCRIPT # This is run after the uninstall.sh script to delete all data. # dropshell handles the configuration files, so we just need to remove # any docker volumes and any custom local data folders. -check_required_env_vars "CONTAINER_NAME" "DATA_VOLUME" "CONFIG_VOLUME" "CONFIG_PATH" if ! autonuke volume=$DATA_VOLUME volume=$CONFIG_VOLUME; then die "Failed to nuke" diff --git a/templates/caddy/restore.sh b/templates/caddy/restore.sh index be65798..3264d14 100644 --- a/templates/caddy/restore.sh +++ b/templates/caddy/restore.sh @@ -1,9 +1,9 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars # RESTORE SCRIPT -check_required_env_vars "DATA_VOLUME" "CONFIG_VOLUME" "CONFIG_PATH" # uninstall container before restore bash ./uninstall.sh || die "Failed to uninstall service before restore" diff --git a/templates/caddy/start.sh b/templates/caddy/start.sh index 751dd22..a58ff2e 100644 --- a/templates/caddy/start.sh +++ b/templates/caddy/start.sh @@ -1,11 +1,11 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars # START SCRIPT # The start script is required for all templates. # It is used to start the service on the server. -check_required_env_vars "CONTAINER_NAME" "DATA_VOLUME" "CONFIG_VOLUME" DOCKER_RUN_CMD="docker run -d \ diff --git a/templates/caddy/status.sh b/templates/caddy/status.sh index 41c0473..a482e35 100644 --- a/templates/caddy/status.sh +++ b/templates/caddy/status.sh @@ -1,12 +1,12 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars # STATUS SCRIPT # The status script is OPTIONAL. # It is used to return the status of the service (0 is healthy, 1 is unhealthy). # This is an example of a status script that checks if the service is running. -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." diff --git a/templates/caddy/stop.sh b/templates/caddy/stop.sh index 86d802f..11e836c 100644 --- a/templates/caddy/stop.sh +++ b/templates/caddy/stop.sh @@ -1,11 +1,11 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars # STOP SCRIPT # The stop script is required for all templates. # It is used to stop the service on the server. -check_required_env_vars "CONTAINER_NAME" _stop_container $CONTAINER_NAME || die "Failed to stop container ${CONTAINER_NAME}" diff --git a/templates/caddy/uninstall.sh b/templates/caddy/uninstall.sh index dab2594..8c5a8e4 100644 --- a/templates/caddy/uninstall.sh +++ b/templates/caddy/uninstall.sh @@ -1,11 +1,11 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars # UNINSTALL SCRIPT # The uninstall script is required for all templates. # It is used to uninstall the service from the server. -check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" _remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER_NAME}" _is_container_running && die "Couldn't stop existing container" diff --git a/templates/dropshell-agent/shared/_common.sh b/templates/dropshell-agent/shared/_common.sh index 4f9b994..d5bcae6 100644 --- a/templates/dropshell-agent/shared/_common.sh +++ b/templates/dropshell-agent/shared/_common.sh @@ -164,7 +164,7 @@ _check_required_env_vars() { local required_vars=("$@") for var in "${required_vars[@]}"; do 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" fi done } diff --git a/templates/example-nginx/backup.sh b/templates/example-nginx/backup.sh index a7885bb..58c19fd 100644 --- a/templates/example-nginx/backup.sh +++ b/templates/example-nginx/backup.sh @@ -1,12 +1,10 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars "LOCAL_DATA_FOLDER" # Nginx Example Backup Script - -_check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER" - # hot backup is fine for nginx website content. autobackup "path=${LOCAL_DATA_FOLDER}" $1 $2 || _die "Failed to create backup" -echo "Backup complete: ${BACKUP_FILE}" +echo "Backup complete" diff --git a/templates/example-nginx/install.sh b/templates/example-nginx/install.sh index de551c8..8969408 100644 --- a/templates/example-nginx/install.sh +++ b/templates/example-nginx/install.sh @@ -1,12 +1,12 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars "LOCAL_DATA_FOLDER" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "CONTAINER_NAME" # Nginx Example Install Script # Load service environment variables source ./service.env -_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "LOCAL_DATA_FOLDER" # Ensure local data folder exists if [ ! -d "${LOCAL_DATA_FOLDER}" ]; then diff --git a/templates/example-nginx/logs.sh b/templates/example-nginx/logs.sh index 514693f..b5dcd99 100644 --- a/templates/example-nginx/logs.sh +++ b/templates/example-nginx/logs.sh @@ -1,13 +1,9 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars "CONTAINER_NAME" # Nginx Example Logs Script - -# Load service environment variables -source ./service.env -_check_required_env_vars "CONTAINER_NAME" - echo "Showing logs for ${CONTAINER_NAME}... (Press Ctrl+C to stop)" _grey_start _get_container_logs $CONTAINER_NAME diff --git a/templates/example-nginx/nuke.sh b/templates/example-nginx/nuke.sh index 83d0dab..5a45b35 100644 --- a/templates/example-nginx/nuke.sh +++ b/templates/example-nginx/nuke.sh @@ -1,14 +1,10 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars "LOCAL_DATA_FOLDER" "CONTAINER_NAME" # Nginx Example Nuke Script # Removes container and local data folder. - -# Load service environment variables -source ./service.env -_check_required_env_vars "LOCAL_DATA_FOLDER" "CONTAINER_NAME" - # Call uninstall script first ./uninstall.sh diff --git a/templates/example-nginx/ports.sh b/templates/example-nginx/ports.sh index c7e0fd6..1ccdc1b 100644 --- a/templates/example-nginx/ports.sh +++ b/templates/example-nginx/ports.sh @@ -1,18 +1,7 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars "HOST_PORT" # Nginx Example Ports Script - -# Load service environment variables -source ./service.env - -# 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 +echo $HOST_PORT diff --git a/templates/example-nginx/restore.sh b/templates/example-nginx/restore.sh index 6acd49c..0174aca 100644 --- a/templates/example-nginx/restore.sh +++ b/templates/example-nginx/restore.sh @@ -1,40 +1,15 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars "LOCAL_DATA_FOLDER" # Nginx Example Restore Script - -# Load service environment variables -source ./service.env -_check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER" - BACKUP_FILE="$1" -if [ -z "$BACKUP_FILE" ]; then - _die "Backup file path not provided" -fi - -if [ ! -f "$BACKUP_FILE" ]; then - _die "Backup file $BACKUP_FILE does not exist" -fi - echo "Uninstalling service before restore..." bash ./uninstall.sh || _die "Failed to uninstall service before restore" -echo "Removing existing data folder ${LOCAL_DATA_FOLDER}..." -# Use root remove in case of permission issues -_root_remove_tree "$LOCAL_DATA_FOLDER" -[ ! -d "$LOCAL_DATA_FOLDER" ] || _die "Failed to delete $LOCAL_DATA_FOLDER" -mkdir -p "$LOCAL_DATA_FOLDER" -[ -d "$LOCAL_DATA_FOLDER" ] || _die "Failed to create $LOCAL_DATA_FOLDER" -chmod 777 "$LOCAL_DATA_FOLDER" # Ensure permissions - -echo "Restoring data from ${BACKUP_FILE} to ${LOCAL_DATA_FOLDER}..." -# Assuming backup is a simple tarball of the folder contents -tar -xzf "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER" --strip-components=1 -if [ $? -ne 0 ]; then - _die "Failed to restore data folder from backup" -fi +autorestore "path=${LOCAL_DATA_FOLDER}" $1 $2 || _die "Failed to restore data folder from backup" echo "Restore complete. Reinstalling service..." bash ./install.sh || _die "Failed to reinstall service after restore" diff --git a/templates/example-nginx/start.sh b/templates/example-nginx/start.sh index 3935e3a..e5bde11 100644 --- a/templates/example-nginx/start.sh +++ b/templates/example-nginx/start.sh @@ -1,12 +1,12 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER" "HOST_PORT" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" # START SCRIPT # The start script is required for all templates. # 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. -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." diff --git a/templates/example-nginx/status.sh b/templates/example-nginx/status.sh index 5424d79..4e9fe90 100644 --- a/templates/example-nginx/status.sh +++ b/templates/example-nginx/status.sh @@ -1,21 +1,13 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars "CONTAINER_NAME" # 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. -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 -# curl -s -X GET http://localhost:${HOST_PORT}/health | grep -q "OK" \ -# || die "Service is not healthy - did not get OK response from /health endpoint." - echo "Service is healthy" exit 0 diff --git a/templates/example-nginx/stop.sh b/templates/example-nginx/stop.sh index 43c8f2e..2983646 100644 --- a/templates/example-nginx/stop.sh +++ b/templates/example-nginx/stop.sh @@ -1,11 +1,5 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" - -# STOP SCRIPT -# The stop script is required for all templates. -# 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. - check_required_env_vars "CONTAINER_NAME" _stop_container $CONTAINER_NAME || die "Failed to stop container ${CONTAINER_NAME}" diff --git a/templates/example-nginx/uninstall.sh b/templates/example-nginx/uninstall.sh index 8cc813d..62e9b15 100644 --- a/templates/example-nginx/uninstall.sh +++ b/templates/example-nginx/uninstall.sh @@ -1,21 +1,13 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars "CONTAINER_NAME" # Nginx Example Uninstall Script - -# Load service environment variables -source ./service.env -_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "LOCAL_DATA_FOLDER" - echo "Uninstalling service ${CONTAINER_NAME}..." _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 -# Optional: Remove image? -# 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. +echo "Note: This does NOT remove the local data folder. Use nuke.sh for that." diff --git a/templates/simple-object-storage/backup.sh b/templates/simple-object-storage/backup.sh index 2c59fdc..35662f8 100644 --- a/templates/simple-object-storage/backup.sh +++ b/templates/simple-object-storage/backup.sh @@ -1,11 +1,11 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars # Simple Object Storage Backup Script # Creates a backup tarball of the volume contents. -_check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME" # HOT backup is fine for simple-object-storage autobackup "volume=${VOLUME_NAME}" $1 $2 || _die "Failed to create backup" diff --git a/templates/simple-object-storage/install.sh b/templates/simple-object-storage/install.sh index 801e5cb..89c41a3 100644 --- a/templates/simple-object-storage/install.sh +++ b/templates/simple-object-storage/install.sh @@ -1,11 +1,11 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars # Simple Object Storage Install Script # Pulls image, creates volume/config, starts container. -_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "VOLUME_NAME" "HOST_NAME" autocreate "volume=${VOLUME_NAME}" diff --git a/templates/simple-object-storage/logs.sh b/templates/simple-object-storage/logs.sh index ebea282..506db2e 100644 --- a/templates/simple-object-storage/logs.sh +++ b/templates/simple-object-storage/logs.sh @@ -1,11 +1,11 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars # Simple Object Storage Logs Script # Shows the logs for the running container. -_check_required_env_vars "CONTAINER_NAME" echo "Showing logs for ${CONTAINER_NAME}... (Press Ctrl+C to stop)" _grey_start diff --git a/templates/simple-object-storage/nuke.sh b/templates/simple-object-storage/nuke.sh index c00853b..01ba91c 100644 --- a/templates/simple-object-storage/nuke.sh +++ b/templates/simple-object-storage/nuke.sh @@ -1,9 +1,9 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars # Simple Object Storage Nuke Script # Removes container AND volume. -_check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME" autonuke "volume=${VOLUME_NAME}" diff --git a/templates/simple-object-storage/ports.sh b/templates/simple-object-storage/ports.sh index 285d36b..5437f21 100644 --- a/templates/simple-object-storage/ports.sh +++ b/templates/simple-object-storage/ports.sh @@ -1,5 +1,6 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars # PORT SCRIPT # The port script is OPTIONAL. @@ -8,7 +9,6 @@ source "${AGENT_PATH}/_common.sh" # Required environment variables -check_required_env_vars "CONFIG_PATH" # determine port. command -v jq &> /dev/null || die "jq could not be found, please install it" diff --git a/templates/simple-object-storage/restore.sh b/templates/simple-object-storage/restore.sh index 7586ed4..f7dcb3c 100644 --- a/templates/simple-object-storage/restore.sh +++ b/templates/simple-object-storage/restore.sh @@ -1,11 +1,11 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" || _die "Failed to source _common.sh" +check_required_env_vars # Simple Object Storage Restore Script # Restores data from a backup file. -_check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME" echo "Uninstalling service before restore..." bash ./uninstall.sh || _die "Failed to uninstall service before restore" diff --git a/templates/simple-object-storage/ssh.sh b/templates/simple-object-storage/ssh.sh index 364e491..15c7c86 100644 --- a/templates/simple-object-storage/ssh.sh +++ b/templates/simple-object-storage/ssh.sh @@ -1,11 +1,11 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars # Simple Object Storage SSH Script # Opens a shell in the running container. -_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." diff --git a/templates/simple-object-storage/start.sh b/templates/simple-object-storage/start.sh index 34228fb..2099d72 100644 --- a/templates/simple-object-storage/start.sh +++ b/templates/simple-object-storage/start.sh @@ -1,10 +1,10 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME" "CONFIG_PATH" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" # Simple Object Storage Start Script # Creates and starts the container using environment variables. -check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME" "CONFIG_PATH" # check volume exists. if ! docker volume inspect "${VOLUME_NAME}" &>/dev/null; then diff --git a/templates/simple-object-storage/status.sh b/templates/simple-object-storage/status.sh index 8721118..c634613 100644 --- a/templates/simple-object-storage/status.sh +++ b/templates/simple-object-storage/status.sh @@ -1,10 +1,10 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars # STATUS SCRIPT # This is an example of a status script that checks if the service is running. -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." diff --git a/templates/simple-object-storage/stop.sh b/templates/simple-object-storage/stop.sh index 751e03a..462b3c9 100644 --- a/templates/simple-object-storage/stop.sh +++ b/templates/simple-object-storage/stop.sh @@ -1,11 +1,11 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars # Simple Object Storage Stop Script # Stops the running container. -_check_required_env_vars "CONTAINER_NAME" echo "Stopping service ${CONTAINER_NAME}..." _stop_container $CONTAINER_NAME || _die "Failed to stop container ${CONTAINER_NAME}" diff --git a/templates/simple-object-storage/uninstall.sh b/templates/simple-object-storage/uninstall.sh index 82e0310..3aded75 100644 --- a/templates/simple-object-storage/uninstall.sh +++ b/templates/simple-object-storage/uninstall.sh @@ -1,12 +1,12 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars # 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. -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}" _is_container_running && die "Couldn't stop existing container" diff --git a/templates/squashkiwi/backup.sh b/templates/squashkiwi/backup.sh index c546ccb..aabf928 100644 --- a/templates/squashkiwi/backup.sh +++ b/templates/squashkiwi/backup.sh @@ -1,29 +1,13 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" - -# Get backup file path from argument -BACKUP_FILE="$1" -if [ -z "$BACKUP_FILE" ]; then - die "Backup file path not provided" -fi - -# Check if backup file already exists -if [ -f "$BACKUP_FILE" ]; then - die "Backup file $BACKUP_FILE already exists" -fi +check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER" # Stop container before backup _stop_container "$CONTAINER_NAME" -# Create backup of data folder -# We include the parent folder in the backup paths (.), and strip on restore. -echo "Creating backup of $LOCAL_DATA_FOLDER..." -if ! tar zcvf "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER" .; then - _start_container "$CONTAINER_NAME" - die "Failed to create backup" -fi +autobackup "path=${LOCAL_DATA_FOLDER}" $1 $2 || _die "Failed to create backup" # Start container after backup _start_container "$CONTAINER_NAME" -echo "Backup created successfully: $BACKUP_FILE" +echo "Backup created successfully" diff --git a/templates/squashkiwi/install.sh b/templates/squashkiwi/install.sh index ff9da79..ede4c63 100644 --- a/templates/squashkiwi/install.sh +++ b/templates/squashkiwi/install.sh @@ -1,29 +1,11 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +_check_required_env_vars "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "CONTAINER_NAME" "LOCAL_DATA_FOLDER" -check_required_env_vars \ - "IMAGE_REGISTRY" \ - "IMAGE_REPO" \ - "IMAGE_TAG" \ - "CONTAINER_NAME" \ - "LOCAL_DATA_FOLDER" - - -# Create local data folder if it doesn't exist -if [ -d "${LOCAL_DATA_FOLDER}" ]; then - echo "Local data folder ${LOCAL_DATA_FOLDER} exists, using existing data." -else - echo "Local data folder ${LOCAL_DATA_FOLDER} does not exist, creating..." - mkdir -p "${LOCAL_DATA_FOLDER}" -fi - +autocreate path=$LOCAL_DATA_FOLDER || _die "Failed to create local data folder" # Test Docker -_check_docker_installed || die "Docker test failed, aborting installation..." - -# Create deploy and data folders -[ -z "$LOCAL_DATA_FOLDER" ] && die "LOCAL_DATA_FOLDER is not set" -create_folder "$LOCAL_DATA_FOLDER" +_check_docker_installed || _die "Docker test failed, aborting installation..." # 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" diff --git a/templates/squashkiwi/logs.sh b/templates/squashkiwi/logs.sh index 48c67e8..0bb4c69 100644 --- a/templates/squashkiwi/logs.sh +++ b/templates/squashkiwi/logs.sh @@ -1,11 +1,8 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" - -# check required env vars -check_required_env_vars \ - "CONTAINER_NAME" +check_required_env_vars "CONTAINER_NAME" echo "Container ${CONTAINER_NAME} logs:" -grey_start +_grey_start docker logs "${CONTAINER_NAME}" -grey_end +_grey_end diff --git a/templates/squashkiwi/ports.sh b/templates/squashkiwi/ports.sh index 23f71f0..1c94ac7 100644 --- a/templates/squashkiwi/ports.sh +++ b/templates/squashkiwi/ports.sh @@ -1,6 +1,5 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" - check_required_env_vars "HOST_PORT" - + echo $HOST_PORT diff --git a/templates/squashkiwi/restore.sh b/templates/squashkiwi/restore.sh index 918f373..c6c5484 100644 --- a/templates/squashkiwi/restore.sh +++ b/templates/squashkiwi/restore.sh @@ -1,39 +1,16 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER" # 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. -check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER" - -# Get backup file path from first argument -BACKUP_FILE="$1" -if [ -z "$BACKUP_FILE" ]; then - die "Backup file path not provided" -fi - -# Check if backup file already exists -if [ ! -f "$BACKUP_FILE" ]; then - die "Backup file $BACKUP_FILE does not exist" -fi - # # Stop container before backup bash ./uninstall.sh || die "Failed to uninstall service before restore" -# Remove existing data folder -echo "Deleting ALL data in $LOCAL_DATA_FOLDER." -_root_remove_tree "$LOCAL_DATA_FOLDER" -[ ! -d "$LOCAL_DATA_FOLDER" ] || die "Failed to delete $LOCAL_DATA_FOLDER" -mkdir -p "$LOCAL_DATA_FOLDER" -[ -d "$LOCAL_DATA_FOLDER" ] || die "Failed to create $LOCAL_DATA_FOLDER" - -# Restore data folder from backup -# --strip-components=1 removes the parent folder in the tgz from the restore paths. -if ! tar xzvf "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER" --strip-components=1; then - die "Failed to restore data folder from backup" -fi +autorestore "path=${LOCAL_DATA_FOLDER}" $1 $2 || die "Failed to restore data folder from backup" # reinstall service bash ./install.sh || die "Failed to reinstall service after restore" diff --git a/templates/squashkiwi/ssh.sh b/templates/squashkiwi/ssh.sh index 15fc899..001af88 100644 --- a/templates/squashkiwi/ssh.sh +++ b/templates/squashkiwi/ssh.sh @@ -1,6 +1,6 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" - +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." diff --git a/templates/squashkiwi/start.sh b/templates/squashkiwi/start.sh index d12be5f..ec2bc77 100644 --- a/templates/squashkiwi/start.sh +++ b/templates/squashkiwi/start.sh @@ -1,14 +1,6 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" - -check_required_env_vars \ - "CONTAINER_NAME" \ - "HOST_PORT" \ - "CONTAINER_PORT" \ - "LOCAL_DATA_FOLDER" \ - "IMAGE_REGISTRY" \ - "IMAGE_REPO" \ - "IMAGE_TAG" +check_required_env_vars "CONTAINER_NAME" "HOST_PORT" "CONTAINER_PORT" "LOCAL_DATA_FOLDER" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" DOCKER_RUN_CMD="docker run -d \ diff --git a/templates/squashkiwi/status.sh b/templates/squashkiwi/status.sh index 6104384..a7ddff4 100644 --- a/templates/squashkiwi/status.sh +++ b/templates/squashkiwi/status.sh @@ -1,9 +1,6 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" - -check_required_env_vars \ - "CONTAINER_NAME" \ - "HOST_PORT" +check_required_env_vars "CONTAINER_NAME" "HOST_PORT" # check if the service is running _is_container_running $CONTAINER_NAME || die "Service is not running - did not find container $CONTAINER_NAME." diff --git a/templates/squashkiwi/stop.sh b/templates/squashkiwi/stop.sh index a41ec1a..2983646 100644 --- a/templates/squashkiwi/stop.sh +++ b/templates/squashkiwi/stop.sh @@ -1,8 +1,6 @@ #!/bin/bash source "${AGENT_PATH}/_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}" diff --git a/templates/squashkiwi/uninstall.sh b/templates/squashkiwi/uninstall.sh index 3ccd8b3..e1ad3d1 100644 --- a/templates/squashkiwi/uninstall.sh +++ b/templates/squashkiwi/uninstall.sh @@ -1,12 +1,12 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER" # 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. -check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" _remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER_NAME}" _is_container_running && die "Couldn't stop existing container" diff --git a/templates/watchtower/install.sh b/templates/watchtower/install.sh index c946fb2..4ce5598 100644 --- a/templates/watchtower/install.sh +++ b/templates/watchtower/install.sh @@ -1,12 +1,12 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" # Watchtower Install Script # Load service environment variables source ./service.env -_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" echo "Checking Docker installation..." _check_docker_installed || _die "Docker test failed, aborting installation..." diff --git a/templates/watchtower/logs.sh b/templates/watchtower/logs.sh index 6a2d176..272c822 100644 --- a/templates/watchtower/logs.sh +++ b/templates/watchtower/logs.sh @@ -1,12 +1,12 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars "CONTAINER_NAME" # Watchtower Logs Script # Load service environment variables source ./service.env -_check_required_env_vars "CONTAINER_NAME" echo "Showing logs for ${CONTAINER_NAME}... (Press Ctrl+C to stop)" _grey_start diff --git a/templates/watchtower/start.sh b/templates/watchtower/start.sh index 963ba48..eea314c 100644 --- a/templates/watchtower/start.sh +++ b/templates/watchtower/start.sh @@ -1,12 +1,12 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars # Watchtower Start Script # Load service environment variables source ./service.env -_check_required_env_vars "CONTAINER_NAME" "INTERVAL" # Optional arguments (e.g., --cleanup, --monitor-only) EXTRA_ARGS=$1 diff --git a/templates/watchtower/status.sh b/templates/watchtower/status.sh index a6f3c73..a7ac4da 100644 --- a/templates/watchtower/status.sh +++ b/templates/watchtower/status.sh @@ -1,12 +1,12 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars "CONTAINER_NAME" # Watchtower Status Script # Load service environment variables source ./service.env -_check_required_env_vars "CONTAINER_NAME" _is_container_running $CONTAINER_NAME || _die "Service is not running - did not find container $CONTAINER_NAME." diff --git a/templates/watchtower/stop.sh b/templates/watchtower/stop.sh index f0ad18f..ae89820 100644 --- a/templates/watchtower/stop.sh +++ b/templates/watchtower/stop.sh @@ -1,12 +1,12 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars # Watchtower Stop Script # 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}" diff --git a/templates/watchtower/uninstall.sh b/templates/watchtower/uninstall.sh index 72cb6db..37a2779 100644 --- a/templates/watchtower/uninstall.sh +++ b/templates/watchtower/uninstall.sh @@ -1,12 +1,12 @@ #!/bin/bash source "${AGENT_PATH}/_common.sh" +check_required_env_vars # Watchtower Uninstall Script # Load service environment variables source ./service.env -_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" echo "Uninstalling service ${CONTAINER_NAME}..." _remove_container $CONTAINER_NAME || _die "Failed to remove container ${CONTAINER_NAME}"