biiig wrench
This commit is contained in:
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}."
|
||||
|
Reference in New Issue
Block a user