broken broken broken
This commit is contained in:
parent
0c2b90cf8e
commit
46ca0003af
@ -1,155 +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}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function create_folder() {
|
|
||||||
local folder="$1"
|
|
||||||
if [ -d "$folder" ]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
if ! mkdir -p "$folder"; then
|
|
||||||
die "Failed to create folder: $folder"
|
|
||||||
fi
|
|
||||||
chmod 777 "$folder"
|
|
||||||
echo "Folder created: $folder"
|
|
||||||
}
|
|
||||||
|
|
||||||
# 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"
|
|
||||||
}
|
|
||||||
|
|
||||||
# get container status
|
|
||||||
_get_container_status() {
|
|
||||||
docker ps --format "{{.Status}}" --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
|
|
||||||
}
|
|
||||||
|
|
||||||
# get container logs
|
|
||||||
_get_container_logs() {
|
|
||||||
if ! _is_container_exists $1; then
|
|
||||||
echo "Container $1 does not exist"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
docker logs $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,22 +1,13 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
source "$AGENT_PATH/_common.sh"
|
||||||
# BACKUP SCRIPT
|
|
||||||
# The backup script is OPTIONAL.
|
|
||||||
# It is used to backup the service on the server.
|
|
||||||
# It is called with one argument: the path to the destination backup file.
|
|
||||||
# If the backup file already exists, the script should exit with a message.
|
|
||||||
|
|
||||||
source "$(dirname "$0")/_common.sh"
|
|
||||||
check_required_env_vars "CONTAINER_NAME" "DATA_VOLUME" "CONFIG_VOLUME" "CONFIG_PATH"
|
check_required_env_vars "CONTAINER_NAME" "DATA_VOLUME" "CONFIG_VOLUME" "CONFIG_PATH"
|
||||||
|
|
||||||
# Stop container before backup
|
|
||||||
_stop_container "$CONTAINER_NAME"
|
_stop_container "$CONTAINER_NAME"
|
||||||
|
|
||||||
if ! autobackup volume=$DATA_VOLUME volume=$CONFIG_VOLUME $1 $2; then
|
if ! autobackup volume=$DATA_VOLUME volume=$CONFIG_VOLUME $1 $2; then
|
||||||
die "Failed to create backup"
|
die "Failed to create backup"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start container after backup
|
|
||||||
_start_container "$CONTAINER_NAME"
|
_start_container "$CONTAINER_NAME"
|
||||||
|
|
||||||
echo "Backup created successfully: $BACKUP_FILE"
|
echo "Backup created successfully: $BACKUP_FILE"
|
||||||
|
@ -1,28 +1,17 @@
|
|||||||
#!/bin/bash
|
#!/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.
|
|
||||||
# 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 "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "DATA_VOLUME" "CONFIG_VOLUME"
|
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "DATA_VOLUME" "CONFIG_VOLUME"
|
||||||
|
|
||||||
if ! autocreate volume=$DATA_VOLUME volume=$CONFIG_VOLUME; then
|
if ! autocreate volume=$DATA_VOLUME volume=$CONFIG_VOLUME; then
|
||||||
die "Failed to autocreate volumes and paths"
|
die "Failed to autocreate volumes and paths"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Test Docker
|
|
||||||
_check_docker_installed || die "Docker test failed, aborting installation..."
|
_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"
|
||||||
|
|
||||||
[ -f "${CONFIG_PATH}/Caddyfile" ] || die "Caddyfile not found in ${CONFIG_PATH}!"
|
[ -f "${CONFIG_PATH}/Caddyfile" ] || die "Caddyfile not found in ${CONFIG_PATH}!"
|
||||||
|
|
||||||
# remove and restart, as the env may have changed.
|
|
||||||
bash ./stop.sh || die "Failed to stop container ${CONTAINER_NAME}"
|
bash ./stop.sh || die "Failed to stop container ${CONTAINER_NAME}"
|
||||||
_remove_container $CONTAINER_NAME || die "Failed to remove 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 ./start.sh || die "Failed to start container ${CONTAINER_NAME}"
|
||||||
|
@ -1,15 +1,9 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# LOGS SCRIPT
|
source "$AGENT_PATH/_common.sh"
|
||||||
# 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.
|
|
||||||
|
|
||||||
source "$(dirname "$0")/_common.sh"
|
|
||||||
|
|
||||||
# Required environment variables
|
|
||||||
check_required_env_vars "CONTAINER_NAME"
|
check_required_env_vars "CONTAINER_NAME"
|
||||||
|
|
||||||
|
# Main script.
|
||||||
echo "Container ${CONTAINER_NAME} logs:"
|
echo "Container ${CONTAINER_NAME} logs:"
|
||||||
grey_start
|
grey_start
|
||||||
docker logs "${CONTAINER_NAME}"
|
docker logs "${CONTAINER_NAME}"
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
source "$AGENT_PATH/_common.sh"
|
||||||
|
|
||||||
# NUKE SCRIPT
|
# NUKE SCRIPT
|
||||||
# This is run after the uninstall.sh script to delete all data.
|
# This is run after the uninstall.sh script to delete all data.
|
||||||
# dropshell handles the configuration files, so we just need to remove
|
# dropshell handles the configuration files, so we just need to remove
|
||||||
# any docker volumes and any custom local data folders.
|
# any docker volumes and any custom local data folders.
|
||||||
|
|
||||||
source "$(dirname "$0")/_common.sh"
|
|
||||||
check_required_env_vars "CONTAINER_NAME" "DATA_VOLUME" "CONFIG_VOLUME" "CONFIG_PATH"
|
check_required_env_vars "CONTAINER_NAME" "DATA_VOLUME" "CONFIG_VOLUME" "CONFIG_PATH"
|
||||||
|
|
||||||
if ! autonuke volume=$DATA_VOLUME volume=$CONFIG_VOLUME; then
|
if ! autonuke volume=$DATA_VOLUME volume=$CONFIG_VOLUME; then
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
source "$AGENT_PATH/_common.sh"
|
||||||
|
|
||||||
|
|
||||||
source "$(dirname "$0")/_common.sh"
|
|
||||||
echo 80
|
echo 80
|
||||||
echo 443
|
echo 443
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
source "$AGENT_PATH/_common.sh"
|
||||||
|
|
||||||
# RESTORE SCRIPT
|
# 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.
|
|
||||||
|
|
||||||
source "$(dirname "$0")/_common.sh"
|
|
||||||
check_required_env_vars "DATA_VOLUME" "CONFIG_VOLUME" "CONFIG_PATH"
|
check_required_env_vars "DATA_VOLUME" "CONFIG_VOLUME" "CONFIG_PATH"
|
||||||
|
|
||||||
# uninstall container before restore
|
# uninstall container before restore
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
source "$AGENT_PATH/_common.sh"
|
||||||
|
|
||||||
# START SCRIPT
|
# START SCRIPT
|
||||||
# The start script is required for all templates.
|
# The start script is required for all templates.
|
||||||
# It is used to start the service on the server.
|
# 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.
|
|
||||||
|
|
||||||
source "$(dirname "$0")/_common.sh"
|
|
||||||
check_required_env_vars "CONTAINER_NAME" "DATA_VOLUME" "CONFIG_VOLUME"
|
check_required_env_vars "CONTAINER_NAME" "DATA_VOLUME" "CONFIG_VOLUME"
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
source "$AGENT_PATH/_common.sh"
|
||||||
|
|
||||||
# STATUS SCRIPT
|
# STATUS SCRIPT
|
||||||
# The status script is OPTIONAL.
|
# The status script is OPTIONAL.
|
||||||
# It is used to return the status of the service (0 is healthy, 1 is unhealthy).
|
# 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.
|
# 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_required_env_vars "CONTAINER_NAME"
|
||||||
|
|
||||||
# check if the service is running
|
# check if the service is running
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
source "$AGENT_PATH/_common.sh"
|
||||||
|
|
||||||
# STOP SCRIPT
|
# STOP SCRIPT
|
||||||
# The stop script is required for all templates.
|
# The stop script is required for all templates.
|
||||||
# It is used to stop the service on the server.
|
# 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.
|
|
||||||
|
|
||||||
source "$(dirname "$0")/_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}"
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
source "$AGENT_PATH/_common.sh"
|
||||||
|
|
||||||
# UNINSTALL SCRIPT
|
# UNINSTALL SCRIPT
|
||||||
# The uninstall script is required for all templates.
|
# The uninstall script is required for all templates.
|
||||||
# It is used to uninstall the service from the server.
|
# 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"
|
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG"
|
||||||
|
|
||||||
_remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER_NAME}"
|
_remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER_NAME}"
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
# BACKUP SCRIPT
|
# BACKUP SCRIPT
|
||||||
# The backup script is OPTIONAL.
|
# The backup script is OPTIONAL.
|
||||||
# It is used to backup the service on the server.
|
# It is used to backup the service on the server.
|
||||||
# It is called with one argument: the path to the destination backup file.
|
|
||||||
# If the backup file already exists, the script should exit with a message.
|
|
||||||
|
|
||||||
source "$(dirname "$0")/_common.sh"
|
source "$(dirname "$0")/_common.sh"
|
||||||
check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME"
|
check_required_env_vars "CONTAINER_NAME" "VOLUME_NAME"
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
# INSTALL SCRIPT
|
# INSTALL SCRIPT
|
||||||
# The install script is required for all templates.
|
# The install script is required for all templates.
|
||||||
# It is used to install the service on the server.
|
# It is used to install the service on the server.
|
||||||
# It is called with the path to the server specific env file as an argument.
|
|
||||||
|
|
||||||
source "$(dirname "$0")/_common.sh"
|
source "$(dirname "$0")/_common.sh"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user