diff --git a/templates/simple-object-storage/install.sh b/templates/simple-object-storage/install.sh index 00e2fcf..760bc04 100644 --- a/templates/simple-object-storage/install.sh +++ b/templates/simple-object-storage/install.sh @@ -8,7 +8,7 @@ source "$(dirname "$0")/_common.sh" # Required environment variables -check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "VOLUME_NAME" "HOST_NAME" "HOST_PORT" +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 @@ -32,4 +32,12 @@ _remove_container $CONTAINER_NAME || die "Failed to remove container ${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://${HOST_NAME}:${HOST_PORT}" + + +# 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}" diff --git a/templates/simple-object-storage/ports.sh b/templates/simple-object-storage/ports.sh index 8250a3c..6eaf762 100644 --- a/templates/simple-object-storage/ports.sh +++ b/templates/simple-object-storage/ports.sh @@ -8,19 +8,12 @@ source "$(dirname "$0")/_common.sh" # Required environment variables -# check_required_env_vars "HOST_PORT" +check_required_env_vars "CONFIG_PATH" -# check if jq is installed -if ! command -v jq &> /dev/null; then - die "jq could not be found, please install it" -fi - -# check if sos_config.json exists -if [ ! -f "${CONFIG_PATH}/sos_config.json" ]; then - die "sos_config.json does not exist" -fi - -# extract port from sos_config.json +# 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 $PORT diff --git a/templates/simple-object-storage/restore.sh b/templates/simple-object-storage/restore.sh index 1c6c4b8..4d82373 100644 --- a/templates/simple-object-storage/restore.sh +++ b/templates/simple-object-storage/restore.sh @@ -43,4 +43,4 @@ docker run --rm \ # reinstall service - ensure everything is latest. bash ./install.sh || die "Failed to reinstall service after restore" -echo "Restore complete! Service is running again on port $HOST_PORT with restored content." +echo "Restore complete! Service is running again." diff --git a/templates/simple-object-storage/start.sh b/templates/simple-object-storage/start.sh index 9f5df67..5722d66 100644 --- a/templates/simple-object-storage/start.sh +++ b/templates/simple-object-storage/start.sh @@ -6,18 +6,23 @@ # 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" "VOLUME_NAME" "WRITE_TOKENS" "CONFIG_PATH" +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" 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" +PORT=$(jq -r '.port' "${CONFIG_PATH}/sos_config.json") + DOCKER_RUN_CMD="docker run -d \ --restart unless-stopped \ --name ${CONTAINER_NAME} \ - -p ${HOST_PORT}:80 \ + -p ${PORT}:${PORT} \ -v ${VOLUME_NAME}:/data/storage \ -v ${CONFIG_PATH}/sos_config.json:/data/sos_config.json:ro \ ${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG}" diff --git a/templates/simple-object-storage/status.sh b/templates/simple-object-storage/status.sh index 5018f97..fb13ad8 100644 --- a/templates/simple-object-storage/status.sh +++ b/templates/simple-object-storage/status.sh @@ -13,8 +13,13 @@ check_required_env_vars "CONTAINER_NAME" # check if the service is running _is_container_running $CONTAINER_NAME || die "Service is not running - did not find container $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") + # check if the service is healthy -curl -s -X GET http://localhost:${HOST_PORT}/status | jq -e '.result == "success"' \ +curl -s -X GET http://localhost:${PORT}/status | jq -e '.result == "success"' \ || die "Service is not healthy - did not get OK response from /status endpoint." echo "Service is healthy"