Skip to content

Commit

Permalink
try fix premature shutdown if startup takes too long
Browse files Browse the repository at this point in the history
  • Loading branch information
remcoros committed Jul 30, 2024
1 parent 5b694eb commit d814116
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ COPY ./Labelbase/django /app
# create migrations and static files, working around issues with manage.py of Labelbase
# need to run 'manage.py help' to create a /app/config.ini first
RUN \
MYSQL_PASSWORD=not_used python manage.py help && \
python manage.py makemigrations --noinput && \
MYSQL_PASSWORD=not_used python manage.py help >/dev/null && \
python manage.py collectstatic --noinput && \
rm /app/config.ini

Expand Down
13 changes: 10 additions & 3 deletions docker_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,19 @@ cd /app
if [ -f /root/data/config.ini ]; then
cp /root/data/config.ini /app
else
echo "Executing manage.py help"
python manage.py help
python manage.py help >/dev/null
cp /app/config.ini /root/data
fi

# prevent premature shutdown while migrations are running
trap ' ' TERM
python manage.py makemigrations --noinput
python manage.py migrate --noinput
trap - TERM

python manage.py process_tasks &
app_process_tasks=$!

gunicorn labellabor.wsgi:application -b 127.0.0.1:8000 --reload &
app_process=$!

Expand All @@ -146,8 +152,9 @@ _term() {
echo "Caught TERM signal!"
kill -TERM "$nginx_process" 2>/dev/null
kill -TERM "$app_process" 2>/dev/null
kill -TERM "$app_process_tasks" 2>/dev/null
kill -TERM "$db_process" 2>/dev/null
}

trap _term TERM
wait $db_process $app_process $nginx_process
wait $db_process $app_process_tasks $app_process $nginx_process
2 changes: 2 additions & 0 deletions scripts/deps.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from "https://deno.land/x/embassyd_sdk@v0.3.3.0.11/mod.ts";
export * from "https://deno.land/x/embassyd_sdk@v0.3.3.0.11/util.ts";
export * from "https://deno.land/x/embassyd_sdk@v0.3.3.0.11/healthUtil.ts";
19 changes: 17 additions & 2 deletions scripts/procedures/healthChecks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
import { healthUtil, types as T } from "../deps.ts";
import { error, guardDurationAboveMinimum, ok, types as T } from "../deps.ts";

const url = "http://labelbase.embassy:8080";

export const health: T.ExpectedExports.health = {
"app-ui": healthUtil.checkWebUrl("http://labelbase.embassy:8080"),
async "app-ui"(effects, duration) {
// Ensure the starting duration is past a minimum
const value = guardDurationAboveMinimum({ duration, minimumTime: 60_000 });
if (value) {
return value;
}
try {
await effects.fetch(url);
return ok;
} catch (e) {
console.warn(e);
return error("Can not reach Labelbase");
}
},
};

0 comments on commit d814116

Please sign in to comment.