diff --git a/runme.sh b/runme.sh new file mode 100755 index 0000000000000000000000000000000000000000..1e5217c00ba2a230e0b8ea36898812c2ffc5f84e --- /dev/null +++ b/runme.sh @@ -0,0 +1,64 @@ +#!/bin/bash +#******************************************************************************* +#* Copyright (c) 2022 onward Eclipse Foundation and others. +#* All rights reserved. This program and the accompanying materials +#* are made available under the terms of the Eclipse Public License v2.0 +#* which accompanies this distribution, and is available at +#* http://www.eclipse.org/legal/epl-v20.html +#* +#* Contributors: +#* Matt Ward (Eclipse Foundation) +#*******************************************************************************/ + +umask 0022 + +#setup basic definitions +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="" +LATEST_IMAGE="" + +function pull_image { +# echo "Fetching $IMAGE" + $PODMAN pull -q $IMAGE +} + +function get_image_id { + local IMAGE_ID=$($PODMAN history --format "{{.ID}}" $IMAGE | head -1) + echo $IMAGE_ID +} + +function run_image { +# echo "Running Image $LATEST_IMAGE" + $PODMAN run --name=$CONTAINER_NAME -d -p 18181:8080 $LATEST_IMAGE +} + +#main loop starts here. + +pull_image +LATEST_IMAGE=$(get_image_id) +if [[ $RUNNING_IMAGE == "" ]]; then +# echo "Init setting RUNNING_IMAGE=LATEST_IMAGE" + RUNNING_IMAGE=$LATEST_IMAGE +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 +