This commit is contained in:
Your Name
2025-04-25 12:53:03 +12:00
parent 7e499195e5
commit 2f3135053f
16 changed files with 162 additions and 119 deletions

View File

View File

@ -0,0 +1,9 @@
# Service settings specific to this server
TEMPLATE=example
# Application settings
CONTAINER_PORT=8181
# Image settings
IMAGE_REGISTRY="gitea.jde.nz"
IMAGE_REPO="example/example"

View File

@ -1,5 +1,12 @@
#!/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() {
@ -13,7 +20,18 @@ die() {
load_env() {
local script_dir="$(dirname "${BASH_SOURCE[0]}")"
local env_file
# first load basic.env for the template defaults
if [ -f "$script_dir/_basic.env" ]; then
set -a
source "$script_dir/_basic.env"
set +a
else
echo "Warning: basic.env file not found at $script_dir/_basic.env. Broken template?"
return 1
fi
# now load the server specific env file
if [ -z "$1" ]; then
echo "Usage: $0 [path_to_env_file]"
return 1

View File

@ -1,4 +1,13 @@
#!/bin/bash
# BACKUP SCRIPT
# The backup script is OPTIONAL.
# It is used to backup the service on the server.
# It is called with:
# 1) the path to the server specific env file as the frist argument.
# 2) the path to the destination backup file as the second argument.
# If the backup file already exists, the script should exit with a message.
source "$(dirname "$0")/_common.sh"
load_env "$1" || die "Failed to load environment variables"

View File

@ -1,15 +1,7 @@
# Service settings
TEMPLATE=example
# Service settings specific to this server
# (can also override anything in the basic.env file in the template to make it specific to this server)
# Application settings
CONTAINER_PORT=8181
HOST_PORT=80
# Deployment settings
LOCAL_DATA_FOLDER="${HOME}/.example"
CONTAINER_NAME="example"
# Image settings
IMAGE_REGISTRY="gitea.jde.nz"
IMAGE_REPO="example/example"
IMAGE_TAG="latest"

View File

@ -1,4 +1,10 @@
#!/bin/bash
# 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"
load_env "$1" || die "Failed to load environment variables"

View File

@ -1,4 +1,10 @@
#!/bin/bash
# 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.
source "$(dirname "$0")/_common.sh"
load_env "$1" || die "Failed to load environment variables"

View File

@ -1,4 +1,10 @@
#!/bin/bash
# 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"
load_env "$1" || die "Failed to load environment variables"

View File

@ -1,10 +1,23 @@
#!/bin/bash
# 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"
load_env "$1" || die "Failed to load environment variables"
# Required environment variables
check_required_env_vars "CONTAINER_NAME" "HOST_PORT" "CONTAINER_PORT" "LOCAL_DATA_FOLDER"
if [ -d "${LOCAL_DATA_FOLDER}" ]; then
echo "Local data folder ${LOCAL_DATA_FOLDER} exists, skipping data folder creation"
else
echo "Local data folder ${LOCAL_DATA_FOLDER} does not exist, creating..."
mkdir -p "${LOCAL_DATA_FOLDER}"
fi
DOCKER_RUN_CMD="docker run -d \
--restart unless-stopped \
--name ${CONTAINER_NAME} \

View File

@ -1,4 +1,12 @@
#!/bin/bash
# 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"
load_env "$1" || die "Failed to load environment variables"

View File

@ -1,4 +1,10 @@
#!/bin/bash
# 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"
load_env "$1" || die "Failed to load environment variables"

View File

@ -1,4 +1,10 @@
#!/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.
source "$(dirname "$0")/_common.sh"
load_env "$1" || die "Failed to load environment variables"