Dropshell basic templates (WIP)

This commit is contained in:
Your Name
2025-05-13 21:15:52 +12:00
parent e061feadc6
commit 4a74bbf551
71 changed files with 969 additions and 0 deletions

1
example-nginx/README.txt Normal file
View File

@@ -0,0 +1 @@
Caddy

View File

@@ -0,0 +1,5 @@
# Service settings specific to this server
# Image settings
IMAGE_REGISTRY="docker.io"
IMAGE_REPO="nginx"

10
example-nginx/backup.sh Normal file
View File

@@ -0,0 +1,10 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "LOCAL_DATA_FOLDER" "BACKUP_FILE" "TEMP_DIR" "CONTAINER_NAME"
# Nginx Example Backup Script
# hot backup is fine for nginx website content.
autobackup "path=${LOCAL_DATA_FOLDER}" || _die "Failed to create backup"
echo "Backup complete for ${CONTAINER_NAME}"

View File

@@ -0,0 +1,2 @@
# Template to use - always required!
TEMPLATE=example-nginx

View File

@@ -0,0 +1,12 @@
# 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)
HOST_PORT=60123
LOCAL_DATA_FOLDER="/home/dropshell/nginx-example-website"
CONTAINER_NAME="example-nginx"
IMAGE_TAG="latest"
# Scripts will have these environment variables set, plus those in _default.env, plus:
# SERVER, SERVICE, CONFIG_PATH
# CONFIG_PATH points to this directory!

23
example-nginx/install.sh Normal file
View File

@@ -0,0 +1,23 @@
#!/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
# Ensure local data folder exists
autocreate "path=${LOCAL_DATA_FOLDER}"
echo "Checking Docker 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"
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}"
echo "Starting container..."
bash ./start.sh || _die "Failed to start container ${CONTAINER_NAME}"
echo "Installation complete for service ${CONTAINER_NAME}."

10
example-nginx/logs.sh Normal file
View File

@@ -0,0 +1,10 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "CONTAINER_NAME"
# Nginx Example Logs Script
echo "Showing logs for ${CONTAINER_NAME}... (Press Ctrl+C to stop)"
_grey_start
_get_container_logs $CONTAINER_NAME
_grey_end

13
example-nginx/nuke.sh Normal file
View File

@@ -0,0 +1,13 @@
#!/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.
# Call uninstall script first
./uninstall.sh
autonuke "path=${LOCAL_DATA_FOLDER}" || _die "Failed to nuke ${LOCAL_DATA_FOLDER}"
echo "Nuke complete for service ${CONTAINER_NAME}."

7
example-nginx/ports.sh Normal file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "HOST_PORT"
# Nginx Example Ports Script
echo $HOST_PORT

15
example-nginx/restore.sh Normal file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "LOCAL_DATA_FOLDER" "BACKUP_FILE" "TEMP_DIR" "CONTAINER_NAME"
# Nginx Example Restore Script
echo "Uninstalling service before restore..."
bash ./uninstall.sh || _die "Failed to uninstall service before restore"
autorestore "path=${LOCAL_DATA_FOLDER}" || _die "Failed to restore data folder from backup"
echo "Restore complete. Reinstalling service..."
bash ./install.sh || _die "Failed to reinstall service after restore"
echo "Service ${CONTAINER_NAME} restored and reinstalled."

30
example-nginx/start.sh Normal file
View File

@@ -0,0 +1,30 @@
#!/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.
[ -d "${LOCAL_DATA_FOLDER}" ] || _die "Local data folder ${LOCAL_DATA_FOLDER} does not exist."
DOCKER_RUN_CMD="docker run -d \
--restart unless-stopped \
--name ${CONTAINER_NAME} \
-p ${HOST_PORT}:80 \
-v ${LOCAL_DATA_FOLDER}:/usr/share/nginx/html:ro \
${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG}"
if ! _create_and_start_container "$DOCKER_RUN_CMD" "$CONTAINER_NAME"; then
_die "Failed to start container ${CONTAINER_NAME}"
fi
# Check if the container is running
if ! _is_container_running "$CONTAINER_NAME"; then
_die "Container ${CONTAINER_NAME} is not running"
fi
echo "Container ${CONTAINER_NAME} started"

13
example-nginx/status.sh Normal file
View File

@@ -0,0 +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).
# check if the service is running
_is_container_running $CONTAINER_NAME || _die "Service is not running - did not find container $CONTAINER_NAME."
echo "Service is healthy"
exit 0

7
example-nginx/stop.sh Normal file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "CONTAINER_NAME"
_stop_container $CONTAINER_NAME || _die "Failed to stop container ${CONTAINER_NAME}"
echo "Container ${CONTAINER_NAME} stopped"

View File

@@ -0,0 +1,13 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "CONTAINER_NAME"
# Nginx Example Uninstall Script
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
echo "Service ${CONTAINER_NAME} uninstalled."
echo "Note: This does NOT remove the local data folder. Use nuke.sh for that."