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

3
caddy/README.txt Normal file
View File

@ -0,0 +1,3 @@
Caddy!
Edit the static site, and the Caddyfile.

8
caddy/_default.env Normal file
View File

@ -0,0 +1,8 @@
# Service settings specific to this server
# Image settings
IMAGE_REGISTRY="docker.io"
IMAGE_REPO="caddy"
DATA_VOLUME=caddy_data
CONFIG_VOLUME=caddy_config

11
caddy/backup.sh Normal file
View File

@ -0,0 +1,11 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars
_stop_container "$CONTAINER_NAME"
autobackup "$1" "$2" "volume=$DATA_VOLUME" "volume=$CONFIG_VOLUME" || _die "Failed to create backup"
_start_container "$CONTAINER_NAME"
echo "Backup created successfully: $BACKUP_FILE"

View File

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

6
caddy/config/Caddyfile Normal file
View File

@ -0,0 +1,6 @@
# See https://caddyserver.com/docs/caddyfile
localhost {
root * /srv
file_server
}

10
caddy/config/service.env Normal file
View File

@ -0,0 +1,10 @@
# 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)
CONTAINER_NAME=caddy
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!

View File

@ -0,0 +1,9 @@
<html>
<head>
<title>Static Site</title>
</head>
<body>
<h1>Static Site</h1>
<p>This is a static site.</p>
</body>
</html>

17
caddy/install.sh Normal file
View File

@ -0,0 +1,17 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "DATA_VOLUME" "CONFIG_VOLUME" "CONFIG_PATH"
autocreate "volume=$DATA_VOLUME" "volume=$CONFIG_VOLUME" || _die "Failed to autocreate volumes $DATA_VOLUME and $CONFIG_VOLUME"
_check_docker_installed || _die "Docker test failed, aborting installation..."
docker pull "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || _die "Failed to pull image $IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG"
[ -f "${CONFIG_PATH}/Caddyfile" ] || _die "Caddyfile not found in ${CONFIG_PATH}!"
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"

9
caddy/logs.sh Normal file
View File

@ -0,0 +1,9 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars
# Main script.
echo "Container ${CONTAINER_NAME} logs:"
_grey_start
docker logs "${CONTAINER_NAME}"
_grey_end

13
caddy/nuke.sh Normal file
View File

@ -0,0 +1,13 @@
#!/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.
autonuke "volume=$DATA_VOLUME" "volume=$CONFIG_VOLUME" || _die "Failed to nuke"
echo "Nuking of ${CONTAINER_NAME} complete."

6
caddy/ports.sh Normal file
View File

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

17
caddy/restore.sh Normal file
View File

@ -0,0 +1,17 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars
# RESTORE SCRIPT
# uninstall container before restore
bash ./uninstall.sh || _die "Failed to uninstall service before restore"
# restore data from backup file
autorestore "$1" "$2" "volume=$DATA_VOLUME" "volume=$CONFIG_VOLUME" || _die "Failed to restore data from backup file"
# reinstall service
bash ./install.sh || _die "Failed to reinstall service after restore"
echo "Restore complete! Service is running again."

33
caddy/start.sh Normal file
View File

@ -0,0 +1,33 @@
#!/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.
DOCKER_RUN_CMD="docker run -d \
--restart unless-stopped \
--name ${CONTAINER_NAME} \
-p 80:80 \
-p 443:443 \
-p 443:443/udp \
-v ${CONFIG_PATH}/Caddyfile:/etc/caddy/Caddyfile \
-v ${DATA_VOLUME}:/data \
-v ${CONFIG_VOLUME}:/config \
-v ${CONFIG_PATH}/static:/srv \
${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"

15
caddy/status.sh Normal file
View File

@ -0,0 +1,15 @@
#!/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 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

12
caddy/stop.sh Normal file
View File

@ -0,0 +1,12 @@
#!/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.
_stop_container $CONTAINER_NAME || _die "Failed to stop container ${CONTAINER_NAME}"
echo "Container ${CONTAINER_NAME} stopped"

18
caddy/uninstall.sh Normal file
View File

@ -0,0 +1,18 @@
#!/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.
_remove_container $CONTAINER_NAME || _die "Failed to remove container ${CONTAINER_NAME}"
_is_container_running && _die "Couldn't stop existing container"
_is_container_exists && _die "Couldn't remove existing container"
# remove the image
docker rmi "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || echo "Failed to remove image $IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG"
echo "Uninstallation of ${CONTAINER_NAME} complete."
echo "Local data still in place."

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."

View File

@ -0,0 +1 @@
simple-object-storage

View File

@ -0,0 +1,12 @@
# Service settings specific to this server
# Image settings
IMAGE_REGISTRY="gitea.jde.nz"
IMAGE_REPO="j/simple-object-storage"
IMAGE_TAG="latest"
# Container settings
CONTAINER_NAME="simple-object-storage"
# Volume settings
VOLUME_NAME="simple-object-storage"

View File

@ -0,0 +1,13 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "VOLUME_NAME" "BACKUP_FILE" "TEMP_DIR"
# Simple Object Storage Backup Script
# Creates a backup tarball of the volume contents.
# HOT backup is fine for simple-object-storage
autobackup "volume=${VOLUME_NAME}" || _die "Failed to create backup"
echo "Backup complete: ${BACKUP_FILE}"

View File

@ -0,0 +1,2 @@
# Template to use - always required!
TEMPLATE=simple-object-storage

View File

@ -0,0 +1,4 @@
# note the port and write tokens are not set here, they are set in the sos_config.json file.
CONTAINER_NAME="simple-object-storage"
VOLUME_NAME="simple-object-storage"

View File

@ -0,0 +1,8 @@
{
"write_tokens": [
"fizzle1",
"fizzle2",
"fizzle3"
],
"port": 8123
}

View File

@ -0,0 +1,25 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars
# Simple Object Storage Install Script
# Pulls image, creates volume/config, starts container.
autocreate "volume=${VOLUME_NAME}"
# check can pull image on remote host and exit if fails
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}"
bash ./start.sh || _die "Failed to start container ${CONTAINER_NAME}"
echo "Installation complete for service ${CONTAINER_NAME}."
# determine port.
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"
PORT=$(jq -r '.port' "${CONFIG_PATH}/sos_config.json")
echo "You can access the service at http://${HOST_NAME}:${PORT}"

View File

@ -0,0 +1,13 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars
# Simple Object Storage Logs Script
# Shows the logs for the running container.
echo "Showing logs for ${CONTAINER_NAME}... (Press Ctrl+C to stop)"
_grey_start
_get_container_logs $CONTAINER_NAME
_grey_end

View File

@ -0,0 +1,11 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars
# Simple Object Storage Nuke Script
# Removes container AND volume.
autonuke "volume=${VOLUME_NAME}" || _die "Failed to nuke volume ${VOLUME_NAME}"
echo "Nuke complete for service ${CONTAINER_NAME}."

View File

@ -0,0 +1,19 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "CONFIG_PATH"
# PORT 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.
# Required environment variables
# determine port.
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"
PORT=$(jq -r '.port' "${CONFIG_PATH}/sos_config.json")
echo $PORT

View File

@ -0,0 +1,21 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh" || _die "Failed to source _common.sh"
_check_required_env_vars "BACKUP_FILE" "TEMP_DIR" "VOLUME_NAME" "CONTAINER_NAME"
# Simple Object Storage Restore Script
# Restores data from a backup file.
echo "Uninstalling service before restore..."
bash ./uninstall.sh || _die "Failed to uninstall service before restore"
echo "Restoring data for ${CONTAINER_NAME} from ${BACKUP_FILE}..."
autorestore "volume=${VOLUME_NAME}" || _die "Failed to restore data from backup file"
echo "Restore complete. Reinstalling service..."
bash ./install.sh || _die "Failed to reinstall service after restore"
echo "Service ${CONTAINER_NAME} restored and reinstalled."

View File

@ -0,0 +1,17 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars
# 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."
fi
echo "Connecting to container ${CONTAINER_NAME}..."
docker exec -it "${CONTAINER_NAME}" /bin/bash
echo "Disconnected from ${CONTAINER_NAME}"

View File

@ -0,0 +1,38 @@
#!/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 volume exists.
if ! docker volume inspect "${VOLUME_NAME}" &>/dev/null; then
_die "Docker volume ${VOLUME_NAME} does not exist"
fi
# determine port.
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"
PORT=$(jq -r '.port' "${CONFIG_PATH}/sos_config.json")
DOCKER_RUN_CMD="docker run -d \
--restart unless-stopped \
--name ${CONTAINER_NAME} \
-p ${PORT}:${PORT} \
-v ${VOLUME_NAME}:/data/storage \
-v ${CONFIG_PATH}/sos_config.json:/data/sos_config.json: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"

View File

@ -0,0 +1,22 @@
#!/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 if the service is running
_is_container_running $CONTAINER_NAME || _die "Service is not running - did not find container $CONTAINER_NAME."
# determine port.
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"
PORT=$(jq -r '.port' "${CONFIG_PATH}/sos_config.json")
# check if the service is healthy
curl -s -X GET http://localhost:${PORT}/status | jq -e '.result == "success"' \
|| _die "Service is not healthy - did not get OK response from /status endpoint."
echo "Service is healthy"
exit 0

View File

@ -0,0 +1,12 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars
# Simple Object Storage Stop Script
# Stops the running container.
echo "Stopping service ${CONTAINER_NAME}..."
_stop_container $CONTAINER_NAME || _die "Failed to stop container ${CONTAINER_NAME}"
echo "Service ${CONTAINER_NAME} stopped."

View File

@ -0,0 +1,19 @@
#!/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.
_remove_container $CONTAINER_NAME || _die "Failed to remove container ${CONTAINER_NAME}"
_is_container_running && _die "Couldn't stop existing container"
_is_container_exists && _die "Couldn't remove existing container"
# remove the image
docker rmi "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || echo "Failed to remove image $IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG"
echo "Uninstallation of ${CONTAINER_NAME} complete."
echo "Data volume ${VOLUME_NAME} still in place."

10
squashkiwi/_default.env Normal file
View File

@ -0,0 +1,10 @@
# Application settings
CONTAINER_PORT=8181
# Deployment settings
CONTAINER_NAME="squashkiwi"
# Image settings
IMAGE_REGISTRY="gitea.jde.nz"
IMAGE_REPO="squashkiwi/squashkiwi"
IMAGE_TAG="latest"

13
squashkiwi/backup.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER" "BACKUP_FILE" "TEMP_DIR"
# Stop container before backup
_stop_container "$CONTAINER_NAME"
autobackup "path=${LOCAL_DATA_FOLDER}" || _die "Failed to create backup"
# Start container after backup
_start_container "$CONTAINER_NAME"
echo "Backup created successfully"

View File

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

View File

@ -0,0 +1,6 @@
# Service settings specific to this server
# (can also override anything in the _basic.env file in the template to make it specific to this server)
HOST_PORT=80
LOCAL_DATA_FOLDER="/home/dropshell/example-squashkiwi"
IMAGE_TAG="latest"

18
squashkiwi/install.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
autocreate path=$LOCAL_DATA_FOLDER || _die "Failed to create local data folder"
# Test Docker
_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"
# 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"

8
squashkiwi/logs.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "CONTAINER_NAME"
echo "Container ${CONTAINER_NAME} logs:"
_grey_start
docker logs "${CONTAINER_NAME}"
_grey_end

8
squashkiwi/nuke.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "LOCAL_DATA_FOLDER"
autonuke "path=${LOCAL_DATA_FOLDER}" || _die "Failed to nuke ${LOCAL_DATA_FOLDER}"
echo "Nuke of ${CONTAINER_NAME} complete"

5
squashkiwi/ports.sh Executable file
View File

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

18
squashkiwi/restore.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER" "BACKUP_FILE" "TEMP_DIR"
# 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.
# # Stop container before backup
bash ./uninstall.sh || _die "Failed to uninstall service before restore"
autorestore "path=${LOCAL_DATA_FOLDER}" || _die "Failed to restore data folder from backup"
# reinstall service
bash ./install.sh || _die "Failed to reinstall service after restore"
echo "Restore complete! Service is running again on port $HOST_PORT with restored website."

13
squashkiwi/ssh.sh Executable file
View File

@ -0,0 +1,13 @@
#!/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."
fi
echo "Connecting to ${CONTAINER_NAME}..."
docker exec -it ${CONTAINER_NAME} bash
echo "Disconnected from ${CONTAINER_NAME}"

24
squashkiwi/start.sh Executable file
View File

@ -0,0 +1,24 @@
#!/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"
DOCKER_RUN_CMD="docker run -d \
--restart unless-stopped \
--name ${CONTAINER_NAME} \
-p ${HOST_PORT}:${CONTAINER_PORT} \
-v ${LOCAL_DATA_FOLDER}:/skdata \
${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG}"
if ! _create_and_start_container "$DOCKER_RUN_CMD" "$CONTAINER_NAME"; then
echo "${DOCKER_RUN_CMD}"
_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, on port ${HOST_PORT}"

13
squashkiwi/status.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_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."
# 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

7
squashkiwi/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"

16
squashkiwi/uninstall.sh Executable file
View File

@ -0,0 +1,16 @@
#!/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.
_remove_container $CONTAINER_NAME || _die "Failed to remove container ${CONTAINER_NAME}"
_is_container_running && _die "Couldn't stop existing container"
_is_container_exists && _die "Couldn't remove existing container"
echo "Uninstallation of ${CONTAINER_NAME} complete."
echo "Local data folder ${LOCAL_DATA_FOLDER} still in place."

96
test_template.sh Executable file
View File

@ -0,0 +1,96 @@
#!/bin/bash
SCRIPT_DIR=$(dirname "$0")
# default config should always work for localhost
function die() {
echo "$1"
exit 1
}
function dashes() {
for ((i=0; i<$1; i++)); do
echo -n "-"
done
echo ""
}
function centerprint() {
# print $1 centered
local width=$2
local padding=$(( (width - ${#1}) / 2 ))
for ((i=0; i<$padding; i++)); do
echo -n " "
done
echo "$1"
}
function title() {
# determine terminal width
TERMINAL_WIDTH=$(tput cols)
echo " "
dashes $TERMINAL_WIDTH
centerprint "$1" $TERMINAL_WIDTH
dashes $TERMINAL_WIDTH
}
# do we have the first argument?
if [ -z "$1" ]; then
echo "Usage: $0 <template>"
exit 1
fi
TEMPLATE=$(basename "$1")
if [ ! -d "$SCRIPT_DIR/$TEMPLATE" ]; then
echo "Local Template $TEMPLATE does not exist"
exit 1
fi
# for now, we need to build and locally install to test the template. Check if it's up to date.
title "Checking template $TEMPLATE"
SERVICE_NAME="test-$TEMPLATE"
title "Nuking old service"
ds fullnuke localhost $SERVICE_NAME || die "Failed to fullnuke old service"
title "Creating service"
ds create-service localhost $TEMPLATE $SERVICE_NAME || die "Failed to create service"
title "Installing service"
ds install localhost $SERVICE_NAME || die "Failed to install service"
title "Stopping service"
ds stop localhost $SERVICE_NAME || die "Failed to stop service"
title "Starting service"
ds start localhost $SERVICE_NAME || die "Failed to start service"
title "Listing services"
ds list localhost || die "Failed to list services"
title "Backing up service"
ds backup localhost $SERVICE_NAME || die "Failed to backup service"
title "Restoring service"
ds restore localhost $SERVICE_NAME latest || die "Failed to restore service"
title "Checking status"
ds status localhost $SERVICE_NAME || die "Failed to check status"
title "Nuking service"
ds nuke localhost $SERVICE_NAME || die "Failed to nuke service"
title "Listing services"
ds list localhost || die "Failed to list services"
# change to green font
echo -e "\033[32m"
title "ALL TESTS PASSED FOR $TEMPLATE"
echo -e "\033[0m"
echo " "

11
watchtower/_default.env Normal file
View File

@ -0,0 +1,11 @@
# Service settings
CONTAINER_NAME=watchtower
# Interval in seconds between checks.
# Default is 1800 seconds (30 minutes).
INTERVAL=1800
# Image settings
IMAGE_REGISTRY="docker.io"
IMAGE_REPO="containrrr/watchtower"
IMAGE_TAG="latest"

View File

@ -0,0 +1,3 @@
# Template to use - always required!
TEMPLATE=watchtower

View File

@ -0,0 +1,5 @@
{
"auths": {
}
}

View File

@ -0,0 +1,6 @@
# Service settings specific to this server
# (can also override anything in the _basic.env file in the template to make it specific to this server)
# Interval in seconds between checks.
# Default is 1800 seconds (30 minutes).
INTERVAL=1800

21
watchtower/install.sh Normal file
View File

@ -0,0 +1,21 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG"
# Watchtower Install Script
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..."
# 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}."

10
watchtower/logs.sh Normal file
View File

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

34
watchtower/start.sh Normal file
View File

@ -0,0 +1,34 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars
# Watchtower Start Script
# Optional arguments (e.g., --cleanup, --monitor-only)
EXTRA_ARGS=$1
DOCKER_RUN_CMD="docker run -d \
--name ${CONTAINER_NAME} \
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG} \
--interval ${INTERVAL} ${EXTRA_ARGS}"
echo "Starting container ${CONTAINER_NAME}..."
if ! _create_and_start_container "$DOCKER_RUN_CMD" "$CONTAINER_NAME"; then
# 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
# Check if the container is running after successful start command
if ! _is_container_running "$CONTAINER_NAME"; then
_get_container_logs $CONTAINER_NAME # Show logs if it immediately exited
_die "Container ${CONTAINER_NAME} is not running after start attempt"
fi
echo "Service ${CONTAINER_NAME} started successfully."

13
watchtower/status.sh Normal file
View File

@ -0,0 +1,13 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "CONTAINER_NAME"
# Watchtower Status Script
_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

9
watchtower/stop.sh Normal file
View File

@ -0,0 +1,9 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars
# Watchtower Stop Script
echo "Stopping service ${CONTAINER_NAME}..."
_stop_container $CONTAINER_NAME || _die "Failed to stop container ${CONTAINER_NAME}"
echo "Service ${CONTAINER_NAME} stopped."

13
watchtower/uninstall.sh Normal file
View File

@ -0,0 +1,13 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars
# Watchtower Uninstall Script
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.