biiig wrench
This commit is contained in:
templates
caddy
dropshell-agent
example-nginx
simple-object-storage
squashkiwi
watchtower
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
source "$AGENT_PATH/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME" "DATA_VOLUME" "CONFIG_VOLUME" "CONFIG_PATH"
|
||||
|
||||
_stop_container "$CONTAINER_NAME"
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
source "$AGENT_PATH/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
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
|
||||
|
@ -1,6 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
source "$AGENT_PATH/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME"
|
||||
|
||||
# Main script.
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
source "$AGENT_PATH/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
# NUKE SCRIPT
|
||||
# This is run after the uninstall.sh script to delete all data.
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
source "$AGENT_PATH/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
|
||||
echo 80
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
source "$AGENT_PATH/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
# RESTORE SCRIPT
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
source "$AGENT_PATH/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
# START SCRIPT
|
||||
# The start script is required for all templates.
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
source "$AGENT_PATH/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
# STATUS SCRIPT
|
||||
# The status script is OPTIONAL.
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
source "$AGENT_PATH/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
# STOP SCRIPT
|
||||
# The stop script is required for all templates.
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
source "$AGENT_PATH/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
# UNINSTALL SCRIPT
|
||||
# The uninstall script is required for all templates.
|
||||
|
@ -6,12 +6,7 @@
|
||||
# It is called with the path to the server specific env file as an argument.
|
||||
|
||||
|
||||
install_prerequisites() {
|
||||
# this script works on debian, ubuntu and Raspberry Pi OS
|
||||
# it checks the following prerequisites, and installs them if missing.
|
||||
# if the user is root it proceeds, otherwise it checks for sudo privileges.
|
||||
# if neither exists, and a prerequisite is missing, the script exits with failure.
|
||||
|
||||
check_prerequisites() {
|
||||
# prerequisites:
|
||||
# - bash
|
||||
# - curl
|
||||
@ -29,6 +24,6 @@ install_prerequisites() {
|
||||
done
|
||||
}
|
||||
|
||||
install_prerequisites
|
||||
check_prerequisites
|
||||
exit 0
|
||||
|
||||
|
@ -1,6 +1 @@
|
||||
#!/bin/bash
|
||||
|
||||
# NUKE SCRIPT
|
||||
# run after uninstall.sh to delete all data.
|
||||
|
||||
|
||||
|
@ -7,11 +7,11 @@
|
||||
# ----------------------------------------------------------------------------------------------------------
|
||||
|
||||
# summary of functions:
|
||||
# die "message" : Prints an error message in red and exits with status code 1.
|
||||
# grey_start : Switches terminal output color to grey.
|
||||
# grey_end : Resets terminal output color from grey.
|
||||
# create_and_start_container "<run_cmd>" <container_name> : Creates/starts a container, verifying it runs.
|
||||
# create_folder <folder_path> : Creates a directory if it doesn't exist (chmod 777).
|
||||
# _die "message" : Prints an error message in red and exits with status code 1.
|
||||
# _grey_start : Switches terminal output color to grey.
|
||||
# _grey_end : Resets terminal output color from grey.
|
||||
# _create_and_start_container "<run_cmd>" <container_name> : Creates/starts a container, verifying it runs.
|
||||
# _create_folder <folder_path> : Creates a directory if it doesn't exist (chmod 777).
|
||||
# _check_docker_installed : Checks if Docker is installed, running, and user has permission. Returns 1 on failure.
|
||||
# _is_container_exists <container_name> : Checks if a container (any state) exists. Returns 1 if not found.
|
||||
# _is_container_running <container_name>: Checks if a container is currently running. Returns 1 if not running.
|
||||
@ -21,29 +21,31 @@
|
||||
# _stop_container <container_name> : Stops a running container.
|
||||
# _remove_container <container_name> : Stops (if needed) and removes a container.
|
||||
# _get_container_logs <container_name> : Prints the logs for a container.
|
||||
# check_required_env_vars "VAR1" ... : Checks if listed environment variables are set; calls die() if any are missing.
|
||||
# _check_required_env_vars "VAR1" ... : Checks if listed environment variables are set; calls _die() if any are missing.
|
||||
# _root_remove_tree <path> : Removes a path using a root Docker container (for permissions).
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------
|
||||
|
||||
# Print error message and exit with code 1
|
||||
# Usage: die "error message"
|
||||
die() {
|
||||
# Prints an error message in red and exits with status code 1.
|
||||
_die() {
|
||||
echo -e "\033[91mError: $1\033[0m"
|
||||
exit 1
|
||||
}
|
||||
|
||||
grey_start() {
|
||||
# Switches terminal output color to grey.
|
||||
_grey_start() {
|
||||
echo -e -n "\033[90m"
|
||||
}
|
||||
|
||||
grey_end() {
|
||||
# Resets terminal output color from grey.
|
||||
_grey_end() {
|
||||
echo -e -n "\033[0m"
|
||||
}
|
||||
|
||||
create_and_start_container() {
|
||||
# Creates/starts a container, verifying it runs.
|
||||
_create_and_start_container() {
|
||||
if [ -z "$1" ] || [ -z "$2" ]; then
|
||||
die "Template error: create_and_start_container <run_cmd> <container_name>"
|
||||
_die "Template error: create_and_start_container <run_cmd> <container_name>"
|
||||
fi
|
||||
|
||||
local run_cmd="$1"
|
||||
@ -53,32 +55,33 @@ create_and_start_container() {
|
||||
_is_container_running $container_name && return 0
|
||||
_start_container $container_name
|
||||
else
|
||||
grey_start
|
||||
_grey_start
|
||||
$run_cmd
|
||||
grey_end
|
||||
_grey_end
|
||||
fi
|
||||
|
||||
if ! _is_container_running $container_name; then
|
||||
die "Container ${container_name} failed to start"
|
||||
_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() {
|
||||
# Creates a directory if it doesn't exist (chmod 777).
|
||||
_create_folder() {
|
||||
local folder="$1"
|
||||
if [ -d "$folder" ]; then
|
||||
return 0
|
||||
fi
|
||||
if ! mkdir -p "$folder"; then
|
||||
die "Failed to create folder: $folder"
|
||||
_die "Failed to create folder: $folder"
|
||||
fi
|
||||
chmod 777 "$folder"
|
||||
echo "Folder created: $folder"
|
||||
}
|
||||
|
||||
# Check if docker is installed
|
||||
# Checks if Docker is installed, running, and user has permission. Returns 1 on failure.
|
||||
_check_docker_installed() {
|
||||
if ! command -v docker &> /dev/null; then
|
||||
echo "Docker is not installed"
|
||||
@ -100,7 +103,7 @@ _check_docker_installed() {
|
||||
return 0
|
||||
}
|
||||
|
||||
# Check if a container exists
|
||||
# Checks if a container (any state) exists. Returns 1 if not found.
|
||||
_is_container_exists() {
|
||||
if ! docker ps -a --format "{{.Names}}" | grep -q "^$1$"; then
|
||||
return 1
|
||||
@ -108,7 +111,7 @@ _is_container_exists() {
|
||||
return 0
|
||||
}
|
||||
|
||||
# Check if a container is running
|
||||
# Checks if a container is currently running. Returns 1 if not running.
|
||||
_is_container_running() {
|
||||
if ! docker ps --format "{{.Names}}" | grep -q "^$1$"; then
|
||||
return 1
|
||||
@ -116,37 +119,37 @@ _is_container_running() {
|
||||
return 0
|
||||
}
|
||||
|
||||
# get contianer ID
|
||||
# Prints the ID of the named container.
|
||||
_get_container_id() {
|
||||
docker ps --format "{{.ID}}" --filter "name=$1"
|
||||
}
|
||||
|
||||
# get container status
|
||||
# Prints the status string of the named container.
|
||||
_get_container_status() {
|
||||
docker ps --format "{{.Status}}" --filter "name=$1"
|
||||
}
|
||||
|
||||
# start container that exists
|
||||
# Starts an existing, stopped container.
|
||||
_start_container() {
|
||||
_is_container_exists $1 || return 1
|
||||
_is_container_running $1 && return 0
|
||||
docker start $1
|
||||
}
|
||||
|
||||
# stop container that exists
|
||||
# Stops a running container.
|
||||
_stop_container() {
|
||||
_is_container_running $1 || return 0;
|
||||
docker stop $1
|
||||
}
|
||||
|
||||
# remove container that exists
|
||||
# Stops (if needed) and removes a container.
|
||||
_remove_container() {
|
||||
_stop_container $1
|
||||
_is_container_exists $1 || return 0;
|
||||
docker rm $1
|
||||
}
|
||||
|
||||
# get container logs
|
||||
# Prints the logs for a container.
|
||||
_get_container_logs() {
|
||||
if ! _is_container_exists $1; then
|
||||
echo "Container $1 does not exist"
|
||||
@ -156,16 +159,18 @@ _get_container_logs() {
|
||||
docker logs $1
|
||||
}
|
||||
|
||||
check_required_env_vars() {
|
||||
# Checks if listed environment variables are set; calls _die() if any are missing.
|
||||
_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"
|
||||
_die "Required environment variable $var is not set in your service.env file"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function _root_remove_tree() {
|
||||
# Removes a path using a root Docker container (for permissions).
|
||||
_root_remove_tree() {
|
||||
local to_remove="$1"
|
||||
parent=$(dirname "$to_remove")
|
||||
abs_parent=$(realpath "$parent")
|
||||
|
@ -1,7 +1 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 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.
|
||||
|
||||
|
@ -1,36 +1,42 @@
|
||||
#!/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.
|
||||
# Nginx Example Backup Script
|
||||
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
|
||||
|
||||
# Get backup file path from first argument
|
||||
# Load service environment variables
|
||||
source ./service.env
|
||||
_check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
|
||||
|
||||
BACKUP_FILE="$1"
|
||||
|
||||
if [ -z "$BACKUP_FILE" ]; then
|
||||
die "Backup file path not provided"
|
||||
_die "Backup file path not provided"
|
||||
fi
|
||||
|
||||
# Check if backup file already exists
|
||||
if [ -f "$BACKUP_FILE" ]; then
|
||||
die "Backup file $BACKUP_FILE already exists"
|
||||
if [ -e "$BACKUP_FILE" ]; then
|
||||
_die "Backup file $BACKUP_FILE already exists"
|
||||
fi
|
||||
|
||||
# Stop container before backup
|
||||
_stop_container "$CONTAINER_NAME"
|
||||
echo "Backing up data for ${CONTAINER_NAME} from ${LOCAL_DATA_FOLDER} to ${BACKUP_FILE}..."
|
||||
|
||||
Create backup of data folder
|
||||
echo "Creating backup of $LOCAL_DATA_FOLDER..."
|
||||
if ! tar zcvf "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER" .; then
|
||||
_start_container "$CONTAINER_NAME"
|
||||
die "Failed to create backup"
|
||||
# Stop container before backup?
|
||||
# echo "Stopping container ${CONTAINER_NAME} for backup..."
|
||||
# _stop_container "$CONTAINER_NAME"
|
||||
|
||||
# Create backup of data folder
|
||||
tar -czf "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER" .
|
||||
|
||||
# Check if backup command was successful
|
||||
if [ $? -ne 0 ]; then
|
||||
# Start container again if it was stopped
|
||||
# echo "Restarting container ${CONTAINER_NAME}..."
|
||||
# _start_container "$CONTAINER_NAME"
|
||||
_die "Failed to create backup"
|
||||
fi
|
||||
|
||||
# Start container after backup
|
||||
_start_container "$CONTAINER_NAME"
|
||||
# Start container again if it was stopped
|
||||
# echo "Restarting container ${CONTAINER_NAME}..."
|
||||
# _start_container "$CONTAINER_NAME"
|
||||
|
||||
echo "Backup created successfully: $BACKUP_FILE"
|
||||
echo "Backup complete: ${BACKUP_FILE}"
|
||||
|
50
templates/example-nginx/install.sh
Executable file → Normal file
50
templates/example-nginx/install.sh
Executable file → Normal file
@ -1,41 +1,33 @@
|
||||
#!/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.
|
||||
# Nginx Example Install Script
|
||||
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
|
||||
# Required environment variables
|
||||
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "LOCAL_DATA_FOLDER"
|
||||
# Load service environment variables
|
||||
source ./service.env
|
||||
_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "LOCAL_DATA_FOLDER"
|
||||
|
||||
# Create local data folder if it doesn't exist
|
||||
if [ -d "${LOCAL_DATA_FOLDER}" ]; then
|
||||
echo "Local data folder ${LOCAL_DATA_FOLDER} exists, using existing data."
|
||||
else
|
||||
echo "Local data folder ${LOCAL_DATA_FOLDER} does not exist, creating..."
|
||||
# Ensure local data folder exists
|
||||
if [ ! -d "${LOCAL_DATA_FOLDER}" ]; then
|
||||
echo "Creating local data folder ${LOCAL_DATA_FOLDER}..."
|
||||
mkdir -p "${LOCAL_DATA_FOLDER}"
|
||||
cat <<EOF > "${LOCAL_DATA_FOLDER}/index.html"
|
||||
<html>
|
||||
<body>
|
||||
<h1>Hello, World!</h1>
|
||||
</body>
|
||||
</html>
|
||||
EOF
|
||||
chmod 777 "${LOCAL_DATA_FOLDER}"
|
||||
# Optionally, copy default content if needed
|
||||
# cp -r ./example/* "${LOCAL_DATA_FOLDER}/"
|
||||
fi
|
||||
|
||||
# Test Docker
|
||||
_check_docker_installed || die "Docker test failed, aborting installation..."
|
||||
echo "Checking Docker installation..."
|
||||
_check_docker_installed || _die "Docker test failed, aborting installation..."
|
||||
|
||||
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"
|
||||
|
||||
# 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"
|
||||
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}"
|
||||
|
||||
# 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 "Starting container..."
|
||||
bash ./start.sh || _die "Failed to start container ${CONTAINER_NAME}"
|
||||
|
||||
echo "Installation of ${CONTAINER_NAME} complete"
|
||||
echo "You can access the service at http://${SERVER}:${HOST_PORT}"
|
||||
echo "Installation complete for service ${CONTAINER_NAME}."
|
||||
|
@ -1,16 +1,14 @@
|
||||
#!/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.
|
||||
# Nginx Example Logs Script
|
||||
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
|
||||
# Required environment variables
|
||||
check_required_env_vars "CONTAINER_NAME"
|
||||
# Load service environment variables
|
||||
source ./service.env
|
||||
_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
|
||||
|
@ -1,14 +1,18 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
# NUKE SCRIPT
|
||||
# This is run after the uninstall.sh script to delete all data.
|
||||
# dropshell handles the configuration files, so we just need to remove
|
||||
# any docker volumes and any custom local data folders.
|
||||
# Nginx Example Nuke Script
|
||||
# Removes container and local data folder.
|
||||
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
check_required_env_vars "LOCAL_DATA_FOLDER" "CONTAINER_NAME"
|
||||
|
||||
# remove the local data folder
|
||||
rm -rf $LOCAL_DATA_FOLDER || die "Failed to remove local data folder ${LOCAL_DATA_FOLDER}"
|
||||
# Load service environment variables
|
||||
source ./service.env
|
||||
_check_required_env_vars "LOCAL_DATA_FOLDER" "CONTAINER_NAME"
|
||||
|
||||
echo "Nuking of ${CONTAINER_NAME} complete."
|
||||
# Call uninstall script first
|
||||
./uninstall.sh
|
||||
|
||||
echo "Removing local data folder ${LOCAL_DATA_FOLDER}..."
|
||||
rm -rf $LOCAL_DATA_FOLDER || _die "Failed to remove local data folder ${LOCAL_DATA_FOLDER}"
|
||||
|
||||
echo "Nuke complete for service ${CONTAINER_NAME}."
|
||||
|
@ -1,13 +1,18 @@
|
||||
#!/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.
|
||||
# Nginx Example Ports Script
|
||||
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
|
||||
# Required environment variables
|
||||
# check_required_env_vars "HOST_PORT"
|
||||
# Load service environment variables
|
||||
source ./service.env
|
||||
|
||||
echo $HOST_PORT
|
||||
# This template uses HOST_PORT directly if set
|
||||
# check_required_env_vars "HOST_PORT"
|
||||
|
||||
if [ -n "$HOST_PORT" ]; then
|
||||
echo $HOST_PORT
|
||||
else
|
||||
# Default or logic to determine port if not in env
|
||||
echo 80 # Default Nginx port
|
||||
fi
|
||||
|
@ -1,41 +1,42 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_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.
|
||||
# Nginx Example Restore Script
|
||||
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
|
||||
|
||||
# Get backup file path from first argument
|
||||
# Load service environment variables
|
||||
source ./service.env
|
||||
_check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
|
||||
|
||||
BACKUP_FILE="$1"
|
||||
|
||||
if [ -z "$BACKUP_FILE" ]; then
|
||||
die "Backup file path not provided"
|
||||
_die "Backup file path not provided"
|
||||
fi
|
||||
|
||||
# Check if backup file already exists
|
||||
if [ ! -f "$BACKUP_FILE" ]; then
|
||||
die "Backup file $BACKUP_FILE does not exist"
|
||||
_die "Backup file $BACKUP_FILE does not exist"
|
||||
fi
|
||||
|
||||
# # Stop container before backup
|
||||
bash ./uninstall.sh || die "Failed to uninstall service before restore"
|
||||
echo "Uninstalling service before restore..."
|
||||
bash ./uninstall.sh || _die "Failed to uninstall service before restore"
|
||||
|
||||
# Remove existing data folder
|
||||
echo "Deleting ALL data in $LOCAL_DATA_FOLDER."
|
||||
echo "Removing existing data folder ${LOCAL_DATA_FOLDER}..."
|
||||
# Use root remove in case of permission issues
|
||||
_root_remove_tree "$LOCAL_DATA_FOLDER"
|
||||
[ ! -d "$LOCAL_DATA_FOLDER" ] || die "Failed to delete $LOCAL_DATA_FOLDER"
|
||||
[ ! -d "$LOCAL_DATA_FOLDER" ] || _die "Failed to delete $LOCAL_DATA_FOLDER"
|
||||
mkdir -p "$LOCAL_DATA_FOLDER"
|
||||
[ -d "$LOCAL_DATA_FOLDER" ] || die "Failed to create $LOCAL_DATA_FOLDER"
|
||||
[ -d "$LOCAL_DATA_FOLDER" ] || _die "Failed to create $LOCAL_DATA_FOLDER"
|
||||
chmod 777 "$LOCAL_DATA_FOLDER" # Ensure permissions
|
||||
|
||||
# Restore data folder from backup
|
||||
# --strip-components=1 removes the parent folder in the tgz from the restore paths.
|
||||
if ! tar xzvf "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER" --strip-components=1; then
|
||||
die "Failed to restore data folder from backup"
|
||||
echo "Restoring data from ${BACKUP_FILE} to ${LOCAL_DATA_FOLDER}..."
|
||||
# Assuming backup is a simple tarball of the folder contents
|
||||
tar -xzf "$BACKUP_FILE" -C "$LOCAL_DATA_FOLDER" --strip-components=1
|
||||
if [ $? -ne 0 ]; then
|
||||
_die "Failed to restore data folder from backup"
|
||||
fi
|
||||
|
||||
# reinstall service
|
||||
bash ./install.sh || die "Failed to reinstall service after restore"
|
||||
echo "Restore complete. Reinstalling service..."
|
||||
bash ./install.sh || _die "Failed to reinstall service after restore"
|
||||
|
||||
echo "Restore complete! Service is running again on port $HOST_PORT with restored website."
|
||||
echo "Service ${CONTAINER_NAME} restored and reinstalled."
|
||||
|
2
templates/example-nginx/start.sh
Executable file → Normal file
2
templates/example-nginx/start.sh
Executable file → Normal file
@ -1,11 +1,11 @@
|
||||
#!/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.
|
||||
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME" "HOST_PORT" "LOCAL_DATA_FOLDER"
|
||||
|
||||
[ -d "${LOCAL_DATA_FOLDER}" ] || die "Local data folder ${LOCAL_DATA_FOLDER} does not exist."
|
||||
|
@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
# STATUS SCRIPT
|
||||
# The status script is OPTIONAL.
|
||||
@ -7,7 +8,6 @@
|
||||
|
||||
|
||||
# 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
|
||||
|
2
templates/example-nginx/stop.sh
Executable file → Normal file
2
templates/example-nginx/stop.sh
Executable file → Normal file
@ -1,11 +1,11 @@
|
||||
#!/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.
|
||||
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME"
|
||||
|
||||
_stop_container $CONTAINER_NAME || die "Failed to stop container ${CONTAINER_NAME}"
|
||||
|
@ -1,19 +1,21 @@
|
||||
#!/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.
|
||||
# Nginx Example Uninstall Script
|
||||
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "LOCAL_DATA_FOLDER"
|
||||
|
||||
_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"
|
||||
# Load service environment variables
|
||||
source ./service.env
|
||||
_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "LOCAL_DATA_FOLDER"
|
||||
|
||||
# remove the image
|
||||
docker rmi "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || echo "Failed to remove image $IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG"
|
||||
echo "Uninstalling service ${CONTAINER_NAME}..."
|
||||
_remove_container $CONTAINER_NAME || _die "Failed to remove container ${CONTAINER_NAME}"
|
||||
if _is_container_running $CONTAINER_NAME; then _die "Couldn't stop existing container"; fi
|
||||
if _is_container_exists $CONTAINER_NAME; then _die "Couldn't remove existing container"; fi
|
||||
|
||||
echo "Uninstallation of ${CONTAINER_NAME} complete."
|
||||
echo "Local data folder ${LOCAL_DATA_FOLDER} still in place."
|
||||
# Optional: Remove image?
|
||||
# echo "Removing image ${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG}..."
|
||||
# docker rmi "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || echo "Warning: Failed to remove image (might be in use)"
|
||||
|
||||
echo "Service ${CONTAINER_NAME} uninstalled."
|
||||
# Note: This does NOT remove the local data folder. Use nuke.sh for that.
|
||||
|
@ -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}"
|
||||
|
@ -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}"
|
||||
|
@ -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
|
||||
|
@ -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}"
|
||||
|
@ -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"
|
||||
|
@ -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."
|
||||
|
@ -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}"
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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."
|
||||
|
@ -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}"
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
# Get backup file path from argument
|
||||
BACKUP_FILE="$1"
|
||||
|
2
templates/squashkiwi/install.sh
Executable file → Normal file
2
templates/squashkiwi/install.sh
Executable file → Normal file
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
check_required_env_vars \
|
||||
"IMAGE_REGISTRY" \
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
# check required env vars
|
||||
check_required_env_vars \
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
check_required_env_vars "HOST_PORT"
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
#!/bin/bash
|
||||
source "${AGENT_PATH}/_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.
|
||||
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
|
||||
|
||||
# Get backup file path from first argument
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
|
||||
if ! _is_container_running "$CONTAINER_NAME"; then
|
||||
|
2
templates/squashkiwi/start.sh
Executable file → Normal file
2
templates/squashkiwi/start.sh
Executable file → Normal file
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
check_required_env_vars \
|
||||
"CONTAINER_NAME" \
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
check_required_env_vars \
|
||||
"CONTAINER_NAME" \
|
||||
|
2
templates/squashkiwi/stop.sh
Executable file → Normal file
2
templates/squashkiwi/stop.sh
Executable file → Normal file
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
check_required_env_vars \
|
||||
"CONTAINER_NAME"
|
||||
|
@ -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"
|
||||
|
||||
_remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER_NAME}"
|
||||
|
33
templates/watchtower/install.sh
Executable file → Normal file
33
templates/watchtower/install.sh
Executable file → Normal file
@ -1,20 +1,25 @@
|
||||
#!/bin/bash
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
# Required environment variables
|
||||
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG"
|
||||
# Watchtower Install Script
|
||||
|
||||
# Test Docker
|
||||
_check_docker_installed || die "Docker test failed, aborting installation..."
|
||||
|
||||
# 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"
|
||||
# Load service environment variables
|
||||
source ./service.env
|
||||
_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG"
|
||||
|
||||
# remove and restart, as the env may have changed.
|
||||
echo "Removing old container ${CONTAINER_NAME}"
|
||||
_remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER_NAME}"
|
||||
echo "Starting container ${CONTAINER_NAME}"
|
||||
bash ./start.sh $1 || die "Failed to start container ${CONTAINER_NAME}"
|
||||
echo "Checking Docker installation..."
|
||||
_check_docker_installed || _die "Docker test failed, aborting installation..."
|
||||
|
||||
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..."
|
||||
# No need to check failure, might not exist
|
||||
_stop_container $CONTAINER_NAME
|
||||
_remove_container $CONTAINER_NAME || _die "Failed to remove container ${CONTAINER_NAME}"
|
||||
|
||||
echo "Starting container..."
|
||||
bash ./start.sh $1 || _die "Failed to start container ${CONTAINER_NAME}"
|
||||
|
||||
echo "Installation complete for service ${CONTAINER_NAME}."
|
||||
|
@ -1,10 +1,14 @@
|
||||
#!/bin/bash
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
# Required environment variables
|
||||
check_required_env_vars "CONTAINER_NAME"
|
||||
# Watchtower Logs Script
|
||||
|
||||
echo "Container ${CONTAINER_NAME} logs:"
|
||||
grey_start
|
||||
docker logs "${CONTAINER_NAME}"
|
||||
grey_end
|
||||
|
||||
# Load service environment variables
|
||||
source ./service.env
|
||||
_check_required_env_vars "CONTAINER_NAME"
|
||||
|
||||
echo "Showing logs for ${CONTAINER_NAME}... (Press Ctrl+C to stop)"
|
||||
_grey_start
|
||||
_get_container_logs $CONTAINER_NAME
|
||||
_grey_end
|
||||
|
44
templates/watchtower/start.sh
Executable file → Normal file
44
templates/watchtower/start.sh
Executable file → Normal file
@ -1,28 +1,38 @@
|
||||
#!/bin/bash
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
SERVICE_CONFIG_DIR="$1"
|
||||
# Watchtower Start Script
|
||||
|
||||
# Required environment variables
|
||||
check_required_env_vars "CONTAINER_NAME" "INTERVAL"
|
||||
|
||||
# Load service environment variables
|
||||
source ./service.env
|
||||
_check_required_env_vars "CONTAINER_NAME" "INTERVAL"
|
||||
|
||||
# Optional arguments (e.g., --cleanup, --monitor-only)
|
||||
EXTRA_ARGS=$1
|
||||
|
||||
DOCKER_RUN_CMD="docker run -d \
|
||||
--restart unless-stopped \
|
||||
--name ${CONTAINER_NAME} \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
-v ${SERVICE_CONFIG_DIR}/config.json:/config.json
|
||||
${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG} \
|
||||
--interval ${INTERVAL}"
|
||||
--name ${CONTAINER_NAME} \
|
||||
--restart=always \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG} \
|
||||
--interval ${INTERVAL} ${EXTRA_ARGS}"
|
||||
|
||||
if ! create_and_start_container "$DOCKER_RUN_CMD" "$CONTAINER_NAME"; then
|
||||
echo "RUN_CMD failed:"
|
||||
echo "$DOCKER_RUN_CMD"
|
||||
die "Failed to start container ${CONTAINER_NAME}"
|
||||
echo "Starting container ${CONTAINER_NAME}..."
|
||||
|
||||
if ! _create_and_start_container "$DOCKER_RUN_CMD" "$CONTAINER_NAME"; then
|
||||
# If creation/start failed, attempt to display logs if container exists
|
||||
if _is_container_exists $CONTAINER_NAME; then
|
||||
echo "Attempting to get logs from failed container..."
|
||||
_get_container_logs $CONTAINER_NAME
|
||||
fi
|
||||
_die "Failed to start container ${CONTAINER_NAME}"
|
||||
fi
|
||||
|
||||
# Check if the container is running
|
||||
# Check if the container is running after successful start command
|
||||
if ! _is_container_running "$CONTAINER_NAME"; then
|
||||
die "Container ${CONTAINER_NAME} is not running"
|
||||
_get_container_logs $CONTAINER_NAME # Show logs if it immediately exited
|
||||
_die "Container ${CONTAINER_NAME} is not running after start attempt"
|
||||
fi
|
||||
|
||||
echo "Container ${CONTAINER_NAME} started"
|
||||
echo "Service ${CONTAINER_NAME} started successfully."
|
||||
|
@ -1,14 +1,17 @@
|
||||
#!/bin/bash
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
# Required environment variables
|
||||
check_required_env_vars "CONTAINER_NAME"
|
||||
# Watchtower Status Script
|
||||
|
||||
# check if the service is running
|
||||
_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."
|
||||
# Load service environment variables
|
||||
source ./service.env
|
||||
_check_required_env_vars "CONTAINER_NAME"
|
||||
|
||||
echo "Service is healthy"
|
||||
_is_container_running $CONTAINER_NAME || _die "Service is not running - did not find container $CONTAINER_NAME."
|
||||
|
||||
# Optional: Add specific health checks for Watchtower if needed.
|
||||
# For example, check logs for recent activity or errors.
|
||||
|
||||
echo "Service ${CONTAINER_NAME} is running."
|
||||
exit 0
|
||||
|
14
templates/watchtower/stop.sh
Executable file → Normal file
14
templates/watchtower/stop.sh
Executable file → Normal file
@ -1,9 +1,13 @@
|
||||
#!/bin/bash
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
# Required environment variables
|
||||
check_required_env_vars "CONTAINER_NAME"
|
||||
# Watchtower Stop Script
|
||||
|
||||
_stop_container $CONTAINER_NAME || die "Failed to stop container ${CONTAINER_NAME}"
|
||||
|
||||
echo "Container ${CONTAINER_NAME} stopped"
|
||||
# Load service environment variables
|
||||
source ./service.env
|
||||
_check_required_env_vars "CONTAINER_NAME"
|
||||
|
||||
echo "Stopping service ${CONTAINER_NAME}..."
|
||||
_stop_container $CONTAINER_NAME || _die "Failed to stop container ${CONTAINER_NAME}"
|
||||
echo "Service ${CONTAINER_NAME} stopped."
|
||||
|
@ -1,13 +1,17 @@
|
||||
#!/bin/bash
|
||||
source "$(dirname "$0")/_common.sh"
|
||||
source "${AGENT_PATH}/_common.sh"
|
||||
|
||||
# Required environment variables
|
||||
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG"
|
||||
# Watchtower Uninstall Script
|
||||
|
||||
_remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER_NAME}"
|
||||
|
||||
# remove the image
|
||||
docker rmi "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || echo "Failed to remove image $IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG"
|
||||
# Load service environment variables
|
||||
source ./service.env
|
||||
_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG"
|
||||
|
||||
echo "Uninstallation of ${CONTAINER_NAME} complete."
|
||||
echo "Uninstalling service ${CONTAINER_NAME}..."
|
||||
_remove_container $CONTAINER_NAME || _die "Failed to remove container ${CONTAINER_NAME}"
|
||||
|
||||
echo "Service ${CONTAINER_NAME} uninstalled."
|
||||
|
||||
# Note: Watchtower doesn't typically have volumes to nuke.
|
||||
|
||||
|
Reference in New Issue
Block a user