This commit is contained in:
Your Name
2025-05-17 19:47:20 +12:00
parent 096dc20a64
commit 7b8ce6a658
15 changed files with 6 additions and 1 deletions

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
static-website/backup.sh Executable 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.
databackup "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!

28
static-website/install.sh Executable file
View File

@ -0,0 +1,28 @@
#!/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
datacreate "path=${LOCAL_DATA_FOLDER}"
if [ -z "$( ls -A "${LOCAL_DATA_FOLDER}" )" ]; then
echo "Creating default index.html file..."
echo "<html><body><h1>Hello, World, this is ${CONTAINER_NAME}!</h1></body></html>" > "${LOCAL_DATA_FOLDER}/index.html"
fi
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
static-website/logs.sh Executable 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
static-website/nuke.sh Executable 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
datanuke "path=${LOCAL_DATA_FOLDER}" || _die "Failed to nuke ${LOCAL_DATA_FOLDER}"
echo "Nuke complete for service ${CONTAINER_NAME}."

9
static-website/ports.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
[ ! -z "$AGENT_PATH" ] || { echo "AGENT_PATH is not set"; exit 1; }
source "${AGENT_PATH}/common.sh"
_check_required_env_vars "HOST_PORT"
# Nginx Example Ports Script
echo $HOST_PORT

15
static-website/restore.sh Executable 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"
datarestore "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
static-website/start.sh Executable 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"

14
static-website/status.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
[ ! -z "$AGENT_PATH" ] || { echo "AGENT_PATH is not set"; exit 1; }
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
static-website/stop.sh Executable 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"

13
static-website/uninstall.sh Executable file
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."