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

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