From 60aace48c44b46b313e5b945cb73c82e05e9c064 Mon Sep 17 00:00:00 2001 From: Jafner <40403594+Jafner@users.noreply.github.com> Date: Sun, 1 Aug 2021 12:57:30 -0700 Subject: [PATCH] Add healthcheck functionality --- 5etools-docker/Dockerfile | 4 +++- 5etools-docker/healthcheck.sh | 8 ++++++++ 5etools-docker/init.sh | 13 +++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 5etools-docker/healthcheck.sh diff --git a/5etools-docker/Dockerfile b/5etools-docker/Dockerfile index 570e6736..42130195 100644 --- a/5etools-docker/Dockerfile +++ b/5etools-docker/Dockerfile @@ -1,9 +1,11 @@ FROM httpd COPY init.sh /init.sh +COPY healthcheck.sh /healthcheck.sh RUN apt-get update && \ apt-get -y upgrade && \ apt-get -y install curl p7zip-full WORKDIR /usr/local/apache2/htdocs/ RUN mkdir download ENV IMG false -CMD ["/bin/bash","/init.sh"] +HEALTHCHECK --startperiod=1m CMD /healthcheck.sh +CMD ["/bin/bash","/init.sh"] \ No newline at end of file diff --git a/5etools-docker/healthcheck.sh b/5etools-docker/healthcheck.sh new file mode 100644 index 00000000..2f8abe01 --- /dev/null +++ b/5etools-docker/healthcheck.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +while [ $(cat /status) != "INIT" ] +do + sleep 10; +done + +curl --insecure --fail --silent --show-error -I http://localhost:80 > /dev/null || exit 1 diff --git a/5etools-docker/init.sh b/5etools-docker/init.sh index e4a160be..60751f4d 100644 --- a/5etools-docker/init.sh +++ b/5etools-docker/init.sh @@ -1,5 +1,8 @@ #!/bin/bash # based on: https://wiki.5e.tools/index.php/5eTools_Install_Guide + +echo "STARTING" > /status + FN=`curl -s -k -I https://get.5e.tools/src/|grep filename|cut -d"=" -f2 | awk '{print $1}'` # get filename of most recent version FN=${FN//[$'\t\r\n"']} # remove quotes echo "FN: $FN" @@ -17,6 +20,7 @@ if [ "$VER" != "$CUR" ] then echo " === Local version outdated, updating..." echo -n $VER > version + echo "DOWNLOADING" > /status rm ./index.html 2> /dev/null || true @@ -25,32 +29,41 @@ then curl --progress-bar -k -O -J https://get.5e.tools/src/ -C - if [ "$IMG" = "true" ]; then + echo " === Downloading images === " + echo "DOWNLOADING IMAGES" > /status curl --progress-bar -k -O -J https://get.5e.tools/img/ -C - fi cd .. echo " === Extracting site..." + echo "EXTRACTING" > /status 7z x ./download/$FN -o./ -y if [ "$IMG" = "true" ]; then echo " === Extracting images..." + echo "EXTRACTING IMAGES" > /status 7z x ./download/$FN_IMG -o./img -y mv ./img/tmp/5et/img/* ./img rm -r ./img/tmp fi echo " === Configuring..." + echo "CONFIGURING" > /status find . -name \*.html -exec sed -i 's/"width=device-width, initial-scale=1"/"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/' {} \; sed -i 's//\n/' index.html sed -i 's/navigator.serviceWorker.register("\/sw.js/navigator.serviceWorker.register("sw.js/' index.html sed -i 's/navigator.serviceWorker.register("\/sw.js/navigator.serviceWorker.register("sw.js/' 5etools.html echo " === Cleaning up downloads" + echo "CLEANING" > /status find ./download/ -type f ! -name "*.${VER}.zip" -exec rm {} + echo " === Done!" + echo "INIT" > /status else echo " === Local version matches remote, no action." + echo "INIT" > /status fi + httpd-foreground