Skip to content
Snippets Groups Projects
Commit 770df84f authored by Matt Ward's avatar Matt Ward
Browse files

Updated so the script can be run via cron.

parent ddd9a24f
No related branches found
No related tags found
1 merge request!22Initial pass on a warm standby start/update tool
Pipeline #5059 passed
......@@ -17,12 +17,13 @@ IMAGE="docker.io/eclipsefdn/www.eclipse.org:latest"
#podman should be a drop in replacement for docker
PODMAN="/usr/bin/podman"
CONTAINER_NAME="www-httpd"
RUNNING_IMAGE=""
IMAGE_TRACKER="/var/run/eclipse.org-image"
LATEST_IMAGE=""
function pull_image {
# echo "Fetching $IMAGE"
$PODMAN pull -q $IMAGE
# -q doesn't seem to supress all output, so let's trap it in a local var
local RETURN=$($PODMAN pull -q $IMAGE)
}
function get_image_id {
......@@ -31,34 +32,30 @@ function get_image_id {
}
function run_image {
# echo "Running Image $LATEST_IMAGE"
echo "Running Image $LATEST_IMAGE"
$PODMAN run --name=$CONTAINER_NAME -d -p 18181:8080 $LATEST_IMAGE
}
#main loop starts here.
if [ -f ${IMAGE_TRACKER} ] && [ -s ${IMAGE_TRACKER} ] ; then
RUNNING_IMAGE=$(cat $IMAGE_TRACKER)
else
RUNNING_IMAGE=""
fi
#pull and get the image id
pull_image
LATEST_IMAGE=$(get_image_id)
if [[ $RUNNING_IMAGE == "" ]]; then
# echo "Init setting RUNNING_IMAGE=LATEST_IMAGE"
RUNNING_IMAGE=$LATEST_IMAGE
echo "Init setting RUNNING_IMAGE=LATEST_IMAGE"
run_image
echo -n $LATEST_IMAGE > $IMAGE_TRACKER
elif [[ $RUNNING_IMAGE != $LATEST_IMAGE ]]; then
echo "Latest image id is not the running image, restarting"
$PODMAN stop $CONTAINER_NAME
$PODMAN rm $CONTAINER_NAME
run_image
#update the image 'version' tracker file
echo -n $LATEST_IMAGE > $IMAGE_TRACKER
fi
run_image
while :
do
sleep 300;
#pull and get the image id
pull_image
LATEST_IMAGE=$(get_image_id)
if [[ $RUNNING_IMAGE != $LATEST_IMAGE ]]; then
echo "Latest image id is not the running image, restarting"
$PODMAN stop $CONTAINER_NAME
$PODMAN rm $CONTAINER_NAME
run_image
RUNNING_IMAGE=$LATEST_IMAGE
fi
done
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment