#!/bin/bash source "${AGENT_PATH}/common.sh" _check_required_env_vars # START SCRIPT # The start script is required for all templates. # It is used to start the service on the server. if [ ! -f "${CONFIG_PATH}/caddyfile/Caddyfile" ]; then _die "Caddyfile not found in ${CONFIG_PATH}/caddyfile/Caddyfile" fi # Determine static files directory # Use HOST_STATIC_DIR if set, otherwise use config/static if [ -n "${HOST_STATIC_DIR}" ]; then STATIC_DIR="${HOST_STATIC_DIR}" else STATIC_DIR="${CONFIG_PATH}/static" fi DOCKER_RUN_CMD="docker run -d \ --restart unless-stopped \ --name ${CONTAINER_NAME} \ --cap-add=NET_ADMIN \ -p 80:80 \ -p 443:443 \ -p 443:443/udp \ -v ${CONFIG_PATH}/caddyfile:/etc/caddy \ -v ${DATA_VOLUME}:/data \ -v ${CONFIG_VOLUME}:/config \ -v ${STATIC_DIR}:/static \ ${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG}" if ! _create_and_start_container "$DOCKER_RUN_CMD" "$CONTAINER_NAME"; then _die "Failed to start container ${CONTAINER_NAME}" fi # Check if the container is running if ! _is_container_running "$CONTAINER_NAME"; then _die "Container ${CONTAINER_NAME} is not running" fi echo "Container ${CONTAINER_NAME} started"