'Generic Commit'

This commit is contained in:
Your Name
2025-06-16 22:26:06 +12:00
parent 5c4560b74b
commit f917e8cb4f
15 changed files with 4 additions and 4 deletions

View File

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

13
simple-object-server/backup.sh Executable file
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
databackup "volume=${VOLUME_NAME}" || _die "Failed to create backup"
echo "Backup complete: ${BACKUP_FILE}"

View File

@@ -0,0 +1,21 @@
# DO NOT EDIT THIS FILE FOR YOUR SERVICE!
# This file is replaced from the template whenever there is an update.
# Edit the service.env file to make changes.
# Template to use - always required!
TEMPLATE=simple-object-server
REQUIRES_HOST_ROOT=false
REQUIRES_DOCKER=true
REQUIRES_DOCKER_ROOT=true
# Image settings
IMAGE_REGISTRY="gitea.jde.nz"
IMAGE_REPO="public/simple-object-server"
IMAGE_TAG="latest"
# Container settings
CONTAINER_NAME="simple-object-server"
# Volume settings
VOLUME_NAME="simple-object-server"

View File

@@ -0,0 +1,10 @@
# Service settings specific to this server
# (can also override anything in the .template_info.env file in the template to make it specific to this server)
# 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"
# Server Settings
SSH_USER="root"

View File

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

12
simple-object-server/destroy.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/bash
source "${AGENT_PATH}/common.sh"
_check_required_env_vars
# Simple Object Storage Destroy Script
# Removes container AND volume.
./uninstall.sh
datadestroy "volume=${VOLUME_NAME}" || _die "Failed to Destroy volume ${VOLUME_NAME}"
echo "Destroyed ${CONTAINER_NAME}."

25
simple-object-server/install.sh Executable file
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.
datacreate "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}"

13
simple-object-server/logs.sh Executable file
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

19
simple-object-server/ports.sh Executable file
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

21
simple-object-server/restore.sh Executable file
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}..."
datarestore "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."

17
simple-object-server/ssh.sh Executable file
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}"

38
simple-object-server/start.sh Executable file
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"

22
simple-object-server/status.sh Executable file
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

12
simple-object-server/stop.sh Executable file
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."