Some basics working (squashkiwi, dropshell-agent).
This commit is contained in:
parent
3d9b1fa6d2
commit
77c7315b0b
7
replace_die.sh
Normal file → Executable file
7
replace_die.sh
Normal file → Executable file
@ -1,2 +1,9 @@
|
||||
#!/bin/bash
|
||||
echo "Replacing die with _die in all template scripts..."
|
||||
find templates -type f -name "*.sh" | grep -v "_common.sh\|test_template.sh" | while read -r file; do
|
||||
if grep -q "\bdie\b" "$file"; then
|
||||
sed -i "s/\\bdie\\b/_die/g" "$file"
|
||||
echo "Updated: $file"
|
||||
fi
|
||||
done
|
||||
echo "Replacement complete!"
|
||||
|
@ -1,11 +1,11 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars
|
||||
_check_required_env_vars
|
||||
|
||||
_stop_container "$CONTAINER_NAME"
|
||||
|
||||
if ! autobackup volume=$DATA_VOLUME volume=$CONFIG_VOLUME $1 $2; then
|
||||
die "Failed to create backup"
|
||||
_die "Failed to create backup"
|
||||
fi
|
||||
|
||||
_start_container "$CONTAINER_NAME"
|
||||
|
@ -1,19 +1,19 @@
|
||||
#!/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"
|
||||
_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "DATA_VOLUME" "CONFIG_VOLUME" "CONFIG_PATH"
|
||||
|
||||
if ! autocreate volume=$DATA_VOLUME volume=$CONFIG_VOLUME; then
|
||||
die "Failed to autocreate volumes and paths"
|
||||
_die "Failed to autocreate volumes and paths"
|
||||
fi
|
||||
|
||||
_check_docker_installed || die "Docker test failed, aborting installation..."
|
||||
_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"
|
||||
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}!"
|
||||
[ -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}"
|
||||
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"
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars
|
||||
_check_required_env_vars
|
||||
|
||||
# Main script.
|
||||
echo "Container ${CONTAINER_NAME} logs:"
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars
|
||||
_check_required_env_vars
|
||||
|
||||
# NUKE SCRIPT
|
||||
# This is run after the uninstall.sh script to delete all data.
|
||||
@ -9,7 +9,7 @@ check_required_env_vars
|
||||
|
||||
|
||||
if ! autonuke volume=$DATA_VOLUME volume=$CONFIG_VOLUME; then
|
||||
die "Failed to nuke"
|
||||
_die "Failed to nuke"
|
||||
fi
|
||||
|
||||
echo "Nuking of ${CONTAINER_NAME} complete."
|
||||
|
@ -1,19 +1,19 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars
|
||||
_check_required_env_vars
|
||||
|
||||
# RESTORE SCRIPT
|
||||
|
||||
|
||||
# uninstall container before restore
|
||||
bash ./uninstall.sh || die "Failed to uninstall service before restore"
|
||||
bash ./uninstall.sh || _die "Failed to uninstall service before restore"
|
||||
|
||||
# restore data from backup file
|
||||
if ! autorestore volume=$DATA_VOLUME volume=$CONFIG_VOLUME "$1" "$2"; then
|
||||
die "Failed to restore data from backup file"
|
||||
_die "Failed to restore data from backup file"
|
||||
fi
|
||||
|
||||
# reinstall service
|
||||
bash ./install.sh || die "Failed to reinstall service after restore"
|
||||
bash ./install.sh || _die "Failed to reinstall service after restore"
|
||||
|
||||
echo "Restore complete! Service is running again."
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars
|
||||
_check_required_env_vars
|
||||
|
||||
# START SCRIPT
|
||||
# The start script is required for all templates.
|
||||
@ -22,12 +22,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"
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars
|
||||
_check_required_env_vars
|
||||
|
||||
# STATUS SCRIPT
|
||||
# The status script is OPTIONAL.
|
||||
@ -9,7 +9,7 @@ check_required_env_vars
|
||||
# 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."
|
||||
_is_container_running $CONTAINER_NAME || _die "Service is not running - did not find container $CONTAINER_NAME."
|
||||
|
||||
echo "Service is healthy"
|
||||
exit 0
|
||||
|
@ -1,12 +1,12 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars
|
||||
_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}"
|
||||
_stop_container $CONTAINER_NAME || _die "Failed to stop container ${CONTAINER_NAME}"
|
||||
|
||||
echo "Container ${CONTAINER_NAME} stopped"
|
||||
|
@ -1,15 +1,15 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars
|
||||
_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_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"
|
||||
|
84
templates/dropshell-agent/shared/_autocommands.sh
Normal file
84
templates/dropshell-agent/shared/_autocommands.sh
Normal file
@ -0,0 +1,84 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
_autocommandrun() {
|
||||
command="$1"
|
||||
key="$2"
|
||||
value="$3"
|
||||
backup_file="$4"
|
||||
temp_path="$5"
|
||||
|
||||
case "$key" in
|
||||
volume)
|
||||
echo "Volume: $value"
|
||||
;;
|
||||
path)
|
||||
echo "Path: $value"
|
||||
;;
|
||||
file)
|
||||
echo "File: $value"
|
||||
;;
|
||||
*)
|
||||
_die "Unknown key $key passed to auto${command}. We only support volume, path and file."
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
_autocommandparse() {
|
||||
# first argument is the command
|
||||
# last two arguments are the backup file and the temporary path
|
||||
# all other arguments are of form:
|
||||
# key=value
|
||||
# where key can be one of volume, path or file.
|
||||
# value is the path or volume name.
|
||||
|
||||
# we iterate over the key=value arguments, and for each we call:
|
||||
# autorun <command> <key> <value> <backup_file> <temp_path>
|
||||
|
||||
local command="$1"
|
||||
shift
|
||||
|
||||
# Extract the backup file and temp path (last two arguments)
|
||||
local args=("$@")
|
||||
local arg_count=${#args[@]}
|
||||
local backup_file="${args[$arg_count-2]}"
|
||||
local temp_path="${args[$arg_count-1]}"
|
||||
|
||||
# Process all key=value pairs
|
||||
for ((i=0; i<$arg_count-2; i++)); do
|
||||
local pair="${args[$i]}"
|
||||
|
||||
# Skip if not in key=value format
|
||||
if [[ "$pair" != *"="* ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
local key="${pair%%=*}"
|
||||
local value="${pair#*=}"
|
||||
|
||||
# Key must be one of volume, path or file
|
||||
_autocommandrun "$command" "$key" "$value" "$backup_file" "$temp_path"
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
autocreate() {
|
||||
_autocommandparse create "$@" "-" "-"
|
||||
}
|
||||
|
||||
|
||||
autonuke() {
|
||||
_autocommandparse nuke "$@" "-" "-"
|
||||
}
|
||||
|
||||
|
||||
autobackup() {
|
||||
_autocommandparse backup "$@"
|
||||
}
|
||||
|
||||
|
||||
autorestore() {
|
||||
_autocommandparse restore "$@"
|
||||
}
|
||||
|
||||
|
@ -177,3 +177,7 @@ _root_remove_tree() {
|
||||
child=$(basename "$to_remove")
|
||||
docker run --rm -v "$abs_parent":/data alpine rm -rf "/data/$child"
|
||||
}
|
||||
|
||||
|
||||
# Load autocommands
|
||||
source "${AGENT_PATH}/_autocommands.sh"
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "LOCAL_DATA_FOLDER"
|
||||
_check_required_env_vars "LOCAL_DATA_FOLDER"
|
||||
|
||||
# Nginx Example Backup Script
|
||||
# hot backup is fine for nginx website content.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "LOCAL_DATA_FOLDER" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "CONTAINER_NAME"
|
||||
_check_required_env_vars "LOCAL_DATA_FOLDER" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "CONTAINER_NAME"
|
||||
|
||||
# Nginx Example Install Script
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME"
|
||||
_check_required_env_vars "CONTAINER_NAME"
|
||||
|
||||
# Nginx Example Logs Script
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "LOCAL_DATA_FOLDER" "CONTAINER_NAME"
|
||||
_check_required_env_vars "LOCAL_DATA_FOLDER" "CONTAINER_NAME"
|
||||
|
||||
# Nginx Example Nuke Script
|
||||
# Removes container and local data folder.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "HOST_PORT"
|
||||
_check_required_env_vars "HOST_PORT"
|
||||
|
||||
# Nginx Example Ports Script
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "LOCAL_DATA_FOLDER"
|
||||
_check_required_env_vars "LOCAL_DATA_FOLDER"
|
||||
|
||||
# Nginx Example Restore Script
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER" "HOST_PORT" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG"
|
||||
_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.
|
||||
@ -8,7 +8,7 @@ check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER" "HOST_PORT" "IMAGE_
|
||||
# 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."
|
||||
[ -d "${LOCAL_DATA_FOLDER}" ] || _die "Local data folder ${LOCAL_DATA_FOLDER} does not exist."
|
||||
|
||||
DOCKER_RUN_CMD="docker run -d \
|
||||
--restart unless-stopped \
|
||||
@ -19,12 +19,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"
|
||||
|
@ -1,13 +1,13 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME"
|
||||
_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."
|
||||
_is_container_running $CONTAINER_NAME || _die "Service is not running - did not find container $CONTAINER_NAME."
|
||||
|
||||
echo "Service is healthy"
|
||||
exit 0
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME"
|
||||
_check_required_env_vars "CONTAINER_NAME"
|
||||
|
||||
_stop_container $CONTAINER_NAME || die "Failed to stop container ${CONTAINER_NAME}"
|
||||
_stop_container $CONTAINER_NAME || _die "Failed to stop container ${CONTAINER_NAME}"
|
||||
|
||||
echo "Container ${CONTAINER_NAME} stopped"
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME"
|
||||
_check_required_env_vars "CONTAINER_NAME"
|
||||
|
||||
# Nginx Example Uninstall Script
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars
|
||||
_check_required_env_vars
|
||||
|
||||
# Simple Object Storage Backup Script
|
||||
# Creates a backup tarball of the volume contents.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars
|
||||
_check_required_env_vars
|
||||
|
||||
# Simple Object Storage Install Script
|
||||
# Pulls image, creates volume/config, starts container.
|
||||
@ -20,8 +20,8 @@ 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"
|
||||
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}"
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars
|
||||
_check_required_env_vars
|
||||
|
||||
# Simple Object Storage Logs Script
|
||||
# Shows the logs for the running container.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars
|
||||
_check_required_env_vars
|
||||
|
||||
# Simple Object Storage Nuke Script
|
||||
# Removes container AND volume.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars
|
||||
_check_required_env_vars
|
||||
|
||||
# PORT SCRIPT
|
||||
# The port script is OPTIONAL.
|
||||
@ -11,8 +11,8 @@ check_required_env_vars
|
||||
# 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"
|
||||
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
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh" || _die "Failed to source _common.sh"
|
||||
check_required_env_vars
|
||||
_check_required_env_vars
|
||||
|
||||
# Simple Object Storage Restore Script
|
||||
# Restores data from a backup file.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars
|
||||
_check_required_env_vars
|
||||
|
||||
# Simple Object Storage SSH Script
|
||||
# Opens a shell in the running container.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME" "CONFIG_PATH" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG"
|
||||
_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.
|
||||
|
@ -1,22 +1,22 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars
|
||||
_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."
|
||||
_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"
|
||||
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."
|
||||
|| _die "Service is not healthy - did not get OK response from /status endpoint."
|
||||
|
||||
echo "Service is healthy"
|
||||
exit 0
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars
|
||||
_check_required_env_vars
|
||||
|
||||
# Simple Object Storage Stop Script
|
||||
# Stops the running container.
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars
|
||||
_check_required_env_vars
|
||||
|
||||
# UNINSTALL SCRIPT
|
||||
# The uninstall script is required for all templates.
|
||||
@ -8,9 +8,9 @@ check_required_env_vars
|
||||
# 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_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"
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
|
||||
_check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
|
||||
|
||||
# Stop container before backup
|
||||
_stop_container "$CONTAINER_NAME"
|
||||
|
@ -8,11 +8,11 @@ autocreate path=$LOCAL_DATA_FOLDER || _die "Failed to create local data folder"
|
||||
_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"
|
||||
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}"
|
||||
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"
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME"
|
||||
_check_required_env_vars "CONTAINER_NAME"
|
||||
|
||||
echo "Container ${CONTAINER_NAME} logs:"
|
||||
_grey_start
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "HOST_PORT"
|
||||
_check_required_env_vars "HOST_PORT"
|
||||
|
||||
echo $HOST_PORT
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
|
||||
_check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
|
||||
|
||||
# RESTORE SCRIPT
|
||||
# The restore script is OPTIONAL.
|
||||
@ -8,11 +8,11 @@ check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
|
||||
# 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"
|
||||
bash ./uninstall.sh || _die "Failed to uninstall service before restore"
|
||||
|
||||
autorestore "path=${LOCAL_DATA_FOLDER}" $1 $2 || die "Failed to restore data folder from backup"
|
||||
autorestore "path=${LOCAL_DATA_FOLDER}" $1 $2 || _die "Failed to restore data folder from backup"
|
||||
|
||||
# reinstall service
|
||||
bash ./install.sh || die "Failed to reinstall service after restore"
|
||||
bash ./install.sh || _die "Failed to reinstall service after restore"
|
||||
|
||||
echo "Restore complete! Service is running again on port $HOST_PORT with restored website."
|
||||
|
@ -1,9 +1,9 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME"
|
||||
_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."
|
||||
_die "Container ${CONTAINER_NAME} is not running. Can't connect to it."
|
||||
fi
|
||||
|
||||
echo "Connecting to ${CONTAINER_NAME}..."
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/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"
|
||||
_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 \
|
||||
@ -11,13 +11,13 @@ DOCKER_RUN_CMD="docker run -d \
|
||||
${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG}"
|
||||
|
||||
|
||||
if ! create_and_start_container "$DOCKER_RUN_CMD" "$CONTAINER_NAME"; then
|
||||
die "Failed to start container ${CONTAINER_NAME}"
|
||||
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"
|
||||
_die "Container ${CONTAINER_NAME} is not running"
|
||||
fi
|
||||
|
||||
echo "Container ${CONTAINER_NAME} started, on port ${HOST_PORT}"
|
||||
|
@ -1,13 +1,13 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME" "HOST_PORT"
|
||||
_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."
|
||||
_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."
|
||||
|| _die "Service is not healthy - did not get OK response from /health endpoint."
|
||||
|
||||
echo "Service is healthy"
|
||||
exit 0
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME"
|
||||
_check_required_env_vars "CONTAINER_NAME"
|
||||
|
||||
_stop_container $CONTAINER_NAME || die "Failed to stop container ${CONTAINER_NAME}"
|
||||
_stop_container $CONTAINER_NAME || _die "Failed to stop container ${CONTAINER_NAME}"
|
||||
|
||||
echo "Container ${CONTAINER_NAME} stopped"
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
|
||||
_check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
|
||||
|
||||
# UNINSTALL SCRIPT
|
||||
# The uninstall script is required for all templates.
|
||||
@ -8,9 +8,9 @@ check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
|
||||
# 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_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"
|
||||
|
@ -1,128 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# COMMON FUNCTIONS
|
||||
# JDE
|
||||
# 2025-04-25
|
||||
|
||||
# This file is not required if you write your own template.
|
||||
|
||||
|
||||
# Print error message and exit with code 1
|
||||
# Usage: die "error message"
|
||||
die() {
|
||||
echo -e "\033[91mError: $1\033[0m"
|
||||
exit 1
|
||||
}
|
||||
|
||||
grey_start() {
|
||||
echo -e -n "\033[90m"
|
||||
}
|
||||
|
||||
grey_end() {
|
||||
echo -e -n "\033[0m"
|
||||
}
|
||||
|
||||
create_and_start_container() {
|
||||
if [ -z "$1" ] || [ -z "$2" ]; then
|
||||
die "Template error: create_and_start_container <run_cmd> <container_name>"
|
||||
fi
|
||||
|
||||
local run_cmd="$1"
|
||||
local container_name="$2"
|
||||
|
||||
if _is_container_exists $container_name; then
|
||||
_is_container_running $container_name && return 0
|
||||
_start_container $container_name
|
||||
else
|
||||
grey_start
|
||||
$run_cmd
|
||||
grey_end
|
||||
fi
|
||||
|
||||
if ! _is_container_running $container_name; then
|
||||
die "Container ${container_name} failed to start"
|
||||
fi
|
||||
|
||||
ID=$(_get_container_id $container_name)
|
||||
echo "Container ${container_name} is running with ID ${ID}"
|
||||
}
|
||||
|
||||
# Check if docker is installed
|
||||
_check_docker_installed() {
|
||||
if ! command -v docker &> /dev/null; then
|
||||
echo "Docker is not installed"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# check if docker daemon is running
|
||||
if ! docker info &> /dev/null; then
|
||||
echo "Docker daemon is not running"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# check if user has permission to run docker
|
||||
if ! docker run --rm hello-world &> /dev/null; then
|
||||
echo "User does not have permission to run docker"
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# Check if a container exists
|
||||
_is_container_exists() {
|
||||
if ! docker ps -a --format "{{.Names}}" | grep -q "^$1$"; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# Check if a container is running
|
||||
_is_container_running() {
|
||||
if ! docker ps --format "{{.Names}}" | grep -q "^$1$"; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# get contianer ID
|
||||
_get_container_id() {
|
||||
docker ps --format "{{.ID}}" --filter "name=$1"
|
||||
}
|
||||
|
||||
# start container that exists
|
||||
_start_container() {
|
||||
_is_container_exists $1 || return 1
|
||||
_is_container_running $1 && return 0
|
||||
docker start $1
|
||||
}
|
||||
|
||||
# stop container that exists
|
||||
_stop_container() {
|
||||
_is_container_running $1 || return 0;
|
||||
docker stop $1
|
||||
}
|
||||
|
||||
# remove container that exists
|
||||
_remove_container() {
|
||||
_stop_container $1
|
||||
_is_container_exists $1 || return 0;
|
||||
docker rm $1
|
||||
}
|
||||
|
||||
check_required_env_vars() {
|
||||
local required_vars=("$@")
|
||||
for var in "${required_vars[@]}"; do
|
||||
if [ -z "${!var}" ]; then
|
||||
die "Required environment variable $var is not set in your service.env file"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function _root_remove_tree() {
|
||||
local to_remove="$1"
|
||||
parent=$(dirname "$to_remove")
|
||||
abs_parent=$(realpath "$parent")
|
||||
child=$(basename "$to_remove")
|
||||
docker run --rm -v "$abs_parent":/data alpine rm -rf "/data/$child"
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG"
|
||||
_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG"
|
||||
|
||||
# Watchtower Install Script
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME"
|
||||
_check_required_env_vars "CONTAINER_NAME"
|
||||
|
||||
# Watchtower Logs Script
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars
|
||||
_check_required_env_vars
|
||||
|
||||
# Watchtower Start Script
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME"
|
||||
_check_required_env_vars "CONTAINER_NAME"
|
||||
|
||||
# Watchtower Status Script
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars
|
||||
_check_required_env_vars
|
||||
|
||||
# Watchtower Stop Script
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars
|
||||
_check_required_env_vars
|
||||
|
||||
# Watchtower Uninstall Script
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user