646: Add error message for webapp startup hang #647

Merged
telackey merged 3 commits from telackey/644 into main 2023-11-14 22:07:26 +00:00
3 changed files with 28 additions and 12 deletions
Showing only changes of commit 11be077dc8 - Show all commits

View File

@ -39,4 +39,4 @@ EXPOSE 3000
COPY /scripts /scripts
# Default command sleeps forever so docker doesn't kill it
CMD ["/scripts/start-serving-app.sh"]
ENTRYPOINT ["/scripts/start-serving-app.sh"]

View File

@ -23,7 +23,7 @@ Built host container for $CERC_CONTAINER_BUILD_WORK_DIR with tag:
To test locally run:
docker run -p 3000:3000 $CERC_CONTAINER_BUILD_TAG
docker run -p 3000:3000 --env-file /path/to/environment.env $CERC_CONTAINER_BUILD_TAG
EOF
fi

View File

@ -6,6 +6,13 @@ fi
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
CERC_MAX_GENERATE_TIME=${CERC_MAX_GENERATE_TIME:-60}
tpid=""
ctrl_c() {
kill $tpid $(ps -ef | grep node | grep next | awk '{print $2}') 2>/dev/null
}
trap ctrl_c INT
CERC_BUILD_TOOL="${CERC_BUILD_TOOL}"
if [ -z "$CERC_BUILD_TOOL" ]; then
@ -27,23 +34,32 @@ if [ "$CERC_NEXTJS_SKIP_GENERATE" != "true" ]; then
jq -e '.scripts.cerc_generate' package.json >/dev/null
if [ $? -eq 0 ]; then
npm run cerc_generate > gen.out 2>&1 &
timeout $CERC_MAX_GENERATE_TIME bash -c "tail -n0 -f gen.out | sed '/rendered as static HTML/ q'"
if [ $? -ne 0 ]; then
echo "ERROR: 'npm run cerc_generate' exceeded CERC_MAX_GENERATE_TIME."
exit 1
fi
tail -f gen.out &
tpid=$!
count=0
while [ $count -lt 10 ]; do
generate_done="false"
while [ $count -lt $CERC_MAX_GENERATE_TIME ]; do
sleep 1
ps -ef | grep 'node' | grep 'next' | grep 'generate' >/dev/null
if [ $? -ne 0 ]; then
break
grep 'rendered as static HTML' gen.out > /dev/null
if [ $? -eq 0 ]; then
generate_done="true"
ps -ef | grep 'node' | grep 'next' | grep 'generate' >/dev/null
if [ $? -ne 0 ]; then
break
fi
else
count=$((count + 1))
fi
done
kill $(ps -ef |grep node | grep next | grep generate | awk '{print $2}') 2>/dev/null
if [ $generate_done != "true" ]; then
echo "ERROR: 'npm run cerc_generate' not successful within CERC_MAX_GENERATE_TIME" 1>&2
exit 1
fi
kill $tpid $(ps -ef | grep node | grep next | grep generate | awk '{print $2}') 2>/dev/null
tpid=""
fi
fi