From 3325fb93d86a50ed2bd448631f2619908140ad1a Mon Sep 17 00:00:00 2001 From: John Date: Sun, 27 Apr 2025 15:14:02 +1200 Subject: [PATCH] Tidying --- templates/dropshell-agent/backup.sh | 41 ------------------- templates/example-nginx/README.txt | 33 +++++++++++++++ .../{example => example-nginx}/_common.sh | 0 .../{example => example-nginx}/_default.env | 0 .../{example => example-nginx}/backup.sh | 8 ++-- .../example/service.env | 2 +- .../{example => example-nginx}/install.sh | 0 templates/{example => example-nginx}/logs.sh | 0 templates/{example => example-nginx}/ports.sh | 0 templates/example-nginx/restore.sh | 37 +++++++++++++++++ templates/{example => example-nginx}/start.sh | 0 .../{example => example-nginx}/status.sh | 0 templates/{example => example-nginx}/stop.sh | 0 .../{example => example-nginx}/uninstall.sh | 0 templates/example/README.txt | 24 ----------- 15 files changed, 74 insertions(+), 71 deletions(-) delete mode 100644 templates/dropshell-agent/backup.sh create mode 100644 templates/example-nginx/README.txt rename templates/{example => example-nginx}/_common.sh (100%) rename templates/{example => example-nginx}/_default.env (100%) rename templates/{example => example-nginx}/backup.sh (79%) rename templates/{example => example-nginx}/example/service.env (95%) rename templates/{example => example-nginx}/install.sh (100%) rename templates/{example => example-nginx}/logs.sh (100%) rename templates/{example => example-nginx}/ports.sh (100%) create mode 100644 templates/example-nginx/restore.sh rename templates/{example => example-nginx}/start.sh (100%) rename templates/{example => example-nginx}/status.sh (100%) rename templates/{example => example-nginx}/stop.sh (100%) rename templates/{example => example-nginx}/uninstall.sh (100%) delete mode 100644 templates/example/README.txt diff --git a/templates/dropshell-agent/backup.sh b/templates/dropshell-agent/backup.sh deleted file mode 100644 index ccceb35..0000000 --- a/templates/dropshell-agent/backup.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -# BACKUP SCRIPT -# The backup script is OPTIONAL. -# It is used to backup the service on the server. -# It is called with: -# 1) the path to the server specific env file as the frist argument. -# 2) the path to the destination backup file as the second argument. -# If the backup file already exists, the script should exit with a message. - -source "$(dirname "$0")/_common.sh" -load_env "$1" || die "Failed to load environment variables" - -# Required environment variables -check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER" - -# Get backup file path from second argument -BACKUP_FILE="$2" -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 - -# Stop container before backup -_stop_container "$CONTAINER_NAME" - -Create backup of data folder -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 - -# Start container after backup -_start_container "$CONTAINER_NAME" - -echo "Backup created successfully: $BACKUP_FILE" diff --git a/templates/example-nginx/README.txt b/templates/example-nginx/README.txt new file mode 100644 index 0000000..ff3141d --- /dev/null +++ b/templates/example-nginx/README.txt @@ -0,0 +1,33 @@ +DropShell Template Example - Nginx simple webserver + +A simple service example, creating a single docker container running nginx, with contant on the host +in the configurable LOCAL_DATA_FOLDER directory. + +Shell scripts defined in this folder are run as DropShell commands on the remote server (not locally!). + +When they are run, the following environment variables will be set: +- SERVER (server name), SERVICE (service name) and CONFIG_PATH (path to the user's service configuration folder) +- everything in _default.env +- everything in the server's particular service.env file (defaults in example/service.env) + +The optional backup and restore scripts get a second argument, which is the backup file to create/restore +(must be a single tgz file). + +Mandatory scripts are: +- install.sh +- uninstall.sh + +Optional standard scripts are: +- start.sh +- stop.sh +- backup.sh +- restore.sh +- status.sh +- ports.sh +- logs.sh + + +The example/ folder gets copied to the service's configuration, edited for the particular server settings, +then copied onto the server. The location is server-specific, but can be accessed via CONFIG_PATH. + +You can use it to store things like an nginx config file (this example does not). diff --git a/templates/example/_common.sh b/templates/example-nginx/_common.sh similarity index 100% rename from templates/example/_common.sh rename to templates/example-nginx/_common.sh diff --git a/templates/example/_default.env b/templates/example-nginx/_default.env similarity index 100% rename from templates/example/_default.env rename to templates/example-nginx/_default.env diff --git a/templates/example/backup.sh b/templates/example-nginx/backup.sh similarity index 79% rename from templates/example/backup.sh rename to templates/example-nginx/backup.sh index 2080983..3833655 100644 --- a/templates/example/backup.sh +++ b/templates/example-nginx/backup.sh @@ -3,16 +3,14 @@ # BACKUP SCRIPT # The backup script is OPTIONAL. # It is used to backup the service on the server. -# It is called with: -# 1) the path to the server specific env file as the frist argument. -# 2) the path to the destination backup file as the second argument. +# 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 second argument -BACKUP_FILE="$2" +# Get backup file path from first argument +BACKUP_FILE="$1" if [ -z "$BACKUP_FILE" ]; then die "Backup file path not provided" fi diff --git a/templates/example/example/service.env b/templates/example-nginx/example/service.env similarity index 95% rename from templates/example/example/service.env rename to templates/example-nginx/example/service.env index 37f056c..d7718dd 100644 --- a/templates/example/example/service.env +++ b/templates/example-nginx/example/service.env @@ -1,5 +1,5 @@ # Template to use - always required! -TEMPLATE=example +TEMPLATE=example-nginx # Service settings specific to this server # (can also override anything in the _default.env file in the template to make it specific to this server) diff --git a/templates/example/install.sh b/templates/example-nginx/install.sh similarity index 100% rename from templates/example/install.sh rename to templates/example-nginx/install.sh diff --git a/templates/example/logs.sh b/templates/example-nginx/logs.sh similarity index 100% rename from templates/example/logs.sh rename to templates/example-nginx/logs.sh diff --git a/templates/example/ports.sh b/templates/example-nginx/ports.sh similarity index 100% rename from templates/example/ports.sh rename to templates/example-nginx/ports.sh diff --git a/templates/example-nginx/restore.sh b/templates/example-nginx/restore.sh new file mode 100644 index 0000000..4755a6c --- /dev/null +++ b/templates/example-nginx/restore.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# 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 +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 +# _stop_container "$CONTAINER_NAME" + +# Create backup of data folder +# 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 + +# # Start container after backup +# _start_container "$CONTAINER_NAME" + +# echo "Backup created successfully: $BACKUP_FILE" + +echo "Backup restored successfully!" diff --git a/templates/example/start.sh b/templates/example-nginx/start.sh similarity index 100% rename from templates/example/start.sh rename to templates/example-nginx/start.sh diff --git a/templates/example/status.sh b/templates/example-nginx/status.sh similarity index 100% rename from templates/example/status.sh rename to templates/example-nginx/status.sh diff --git a/templates/example/stop.sh b/templates/example-nginx/stop.sh similarity index 100% rename from templates/example/stop.sh rename to templates/example-nginx/stop.sh diff --git a/templates/example/uninstall.sh b/templates/example-nginx/uninstall.sh similarity index 100% rename from templates/example/uninstall.sh rename to templates/example-nginx/uninstall.sh diff --git a/templates/example/README.txt b/templates/example/README.txt deleted file mode 100644 index 3d4ae2b..0000000 --- a/templates/example/README.txt +++ /dev/null @@ -1,24 +0,0 @@ -DropShell Template Example - -Shell scripts defined in this folder are run as DropShell commands on the remote server (not locally!). -All scripts are passed the directory containing the server-specific service environment (SSSE) as an argument -(the environment file, along with any other server and service-specific files, is then in $1/service.env) - -The default SSSE file included when a new service is created is in example/service.env. This must exist, -and must at minimum contain the TEMPLATE= variable. - -The optional backups script gets a second argument, which is the backup file to create (a single tgz file). - -Mandatory scripts are: -- install.sh -- uninstall.sh - -Optional standard scripts are: -- start.sh -- stop.sh -- backup.sh -- restore.sh -- status.sh -- ports.sh -- logs.sh -