biiig wrench

This commit is contained in:
Your Name
2025-05-03 22:58:39 +12:00
parent 107034cf7b
commit 340170b248
51 changed files with 347 additions and 395 deletions

View File

@ -1,40 +1,13 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
# BACKUP SCRIPT
# The backup script is OPTIONAL.
# It is used to backup the service on the server.
# Simple Object Storage Backup Script
# Creates a backup tarball of the volume contents.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME"
_check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME"
# HOT backup is fine for simple-object-storage
autobackup "volume=${VOLUME_NAME}" $1 $2 || _die "Failed to create backup"
# Get backup file path from first argument
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
die "Backup file path not provided"
fi
TEMP_DIR=$2
if [ -z "$TEMP_DIR" ]; then
die "Temporary directory not provided"
fi
# Check if backup file already exists
if [ -f "$BACKUP_FILE" ]; then
die "Backup file $BACKUP_FILE already exists"
fi
# Create backup of data folder
echo "Creating backup of $VOLUME_NAME..."
docker run --rm -v ${VOLUME_NAME}:/data -v ${TEMP_DIR}:/tempdir alpine sh -c "\
tar zcvf /tempdir/backup.tar.gz -C /data ."
cp ${TEMP_DIR}/backup.tar.gz $BACKUP_FILE
# dropshell cleans up temp dir after script finishes
echo "Backup created successfully: $BACKUP_FILE"
echo "Backup complete: ${BACKUP_FILE}"

View File

@ -1,42 +1,27 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
# INSTALL SCRIPT
# The install script is required for all templates.
# It is used to install the service on the server.
# Simple Object Storage Install Script
# Pulls image, creates volume/config, starts container.
source "$(dirname "$0")/_common.sh"
# Required environment variables
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "VOLUME_NAME" "HOST_NAME"
# Create volume if it doesn't exist
if ! docker volume inspect "${VOLUME_NAME}" &>/dev/null; then
echo "Volume ${VOLUME_NAME} does not exist, creating..."
docker volume create "${VOLUME_NAME}"
fi
if ! docker volume inspect "${VOLUME_NAME}" &>/dev/null; then
die "Failed to create volume ${VOLUME_NAME}"
fi
# Test Docker
_check_docker_installed || die "Docker test failed, aborting installation..."
_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "VOLUME_NAME" "HOST_NAME"
autocreate "volume=${VOLUME_NAME}"
# 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"
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

@ -1,16 +1,13 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
# LOGS SCRIPT
# The logs script is OPTIONAL.
# It is used to return the logs of the service.
# It is called with the path to the server specific env file as an argument.
# Simple Object Storage Logs Script
# Shows the logs for the running container.
source "$(dirname "$0")/_common.sh"
# Required environment variables
check_required_env_vars "CONTAINER_NAME"
_check_required_env_vars "CONTAINER_NAME"
echo "Container ${CONTAINER_NAME} logs:"
grey_start
docker logs "${CONTAINER_NAME}"
grey_end
echo "Showing logs for ${CONTAINER_NAME}... (Press Ctrl+C to stop)"
_grey_start
_get_container_logs $CONTAINER_NAME
_grey_end

View File

@ -1,12 +1,9 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
# NUKE SCRIPT
# Gets run after uninstall.sh
# Simple Object Storage Nuke Script
# Removes container AND volume.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME"
docker volume rm $VOLUME_NAME || die "Failed to remove volume ${VOLUME_NAME}"
echo "Nuking of ${CONTAINER_NAME} complete."
_check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME"
autonuke "volume=${VOLUME_NAME}"

View File

@ -1,11 +1,11 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
# 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.
source "$(dirname "$0")/_common.sh"
# Required environment variables
check_required_env_vars "CONFIG_PATH"

View File

@ -1,46 +1,23 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh" || _die "Failed to source _common.sh"
# 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.
# Simple Object Storage Restore Script
# Restores data from a backup file.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME"
# Get backup file path from first argument
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
die "Backup file path not provided"
_check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME"
echo "Uninstalling service before restore..."
bash ./uninstall.sh || _die "Failed to uninstall service before restore"
echo "Restoring data for ${CONTAINER_NAME} from ${BACKUP_FILE}..."
if ! autorestore "volume=${VOLUME_NAME}" "$1" "$2"; then
_die "Failed to restore data from backup file"
fi
TEMP_DIR=$2
if [ -z "$TEMP_DIR" ]; then
die "Temporary directory not provided"
fi
echo "Restore complete. Reinstalling service..."
# Check if backup file already exists
if [ ! -f "$BACKUP_FILE" ]; then
die "Backup file $BACKUP_FILE does not exist"
fi
bash ./install.sh || _die "Failed to reinstall service after restore"
# # Stop container before backup
bash ./uninstall.sh || die "Failed to uninstall service before restore"
# Remove existing data folder
echo "Deleting ALL data in $VOLUME_NAME."
docker run --rm -v ${VOLUME_NAME}:/data alpine sh -c "\
rm -rf /data/*"
echo "Restoring data from $BACKUP_FILE to $VOLUME_NAME."
docker run --rm \
-v ${VOLUME_NAME}:/data \
-v ${BACKUP_FILE}:/backup.tar.gz \
alpine sh -c "\
tar xzvf /backup.tar.gz -C /data --strip-components=1"
# reinstall service - ensure everything is latest.
bash ./install.sh || die "Failed to reinstall service after restore"
echo "Restore complete! Service is running again."
echo "Service ${CONTAINER_NAME} restored and reinstalled."

View File

@ -1,14 +1,18 @@
#!/bin/bash
source "$(dirname "$0")/_common.sh"
source "${AGENT_PATH}/_common.sh"
check_required_env_vars "CONTAINER_NAME"
# 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."
_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 "Connecting to container ${CONTAINER_NAME}..."
docker exec -it "${CONTAINER_NAME}" /bin/bash
echo "Disconnected from ${CONTAINER_NAME}"

View File

@ -1,21 +1,19 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
# 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.
# Simple Object Storage Start Script
# Creates and starts the container using environment variables.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME" "CONFIG_PATH"
# check volume exists.
if ! docker volume inspect "${VOLUME_NAME}" &>/dev/null; then
die "Docker volume ${VOLUME_NAME} does not exist"
_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"
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")
@ -29,12 +27,12 @@ DOCKER_RUN_CMD="docker run -d \
if ! create_and_start_container "$DOCKER_RUN_CMD" "$CONTAINER_NAME"; then
die "Failed to start container ${CONTAINER_NAME}"
_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"
_die "Container ${CONTAINER_NAME} is not running"
fi
echo "Container ${CONTAINER_NAME} started"

View File

@ -1,13 +1,9 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
# STATUS SCRIPT
# The status script is OPTIONAL.
# It is used to return the status of the service (0 is healthy, 1 is unhealthy).
# It is called with the path to the server specific env file as an argument.
# This is an example of a status script that checks if the service is running.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME"
# check if the service is running

View File

@ -1,13 +1,12 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
# STOP SCRIPT
# The stop script is required for all templates.
# It is used to stop the service on the server.
# It is called with the path to the server specific env file as an argument.
# Simple Object Storage Stop Script
# Stops the running container.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME"
_stop_container $CONTAINER_NAME || die "Failed to stop container ${CONTAINER_NAME}"
_check_required_env_vars "CONTAINER_NAME"
echo "Container ${CONTAINER_NAME} stopped"
echo "Stopping service ${CONTAINER_NAME}..."
_stop_container $CONTAINER_NAME || _die "Failed to stop container ${CONTAINER_NAME}"
echo "Service ${CONTAINER_NAME} stopped."

View File

@ -1,11 +1,11 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
# 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.
source "$(dirname "$0")/_common.sh"
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "VOLUME_NAME"
_remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER_NAME}"