From cb651fc30ce9381d5217b4d1c1c0e87c80857946 Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Wed, 18 Nov 2026 15:09:42 +0100 Subject: [PATCH] fix(devcontainer): shut down PostgreSQL cleanly --- .devcontainer/Dockerfile | 3 +++ .devcontainer/devcontainer.json | 3 ++- .devcontainer/keep-alive | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100755 .devcontainer/keep-alive diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 590f51c29..0a9afc856 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -55,3 +55,6 @@ RUN mkdir -p /home/sentry/bundle # Chromium, ChromeDriver, mise, and the toolchain (Java, Ruby, Node) are # installed by the local `./features/tools` dev container feature, which runs # after this Dockerfile — see devcontainer.json. + +COPY .devcontainer/keep-alive /usr/local/bin/sentry-devcontainer-keep-alive +CMD ["/usr/local/bin/sentry-devcontainer-keep-alive"] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index c96aac0c2..79c81ea55 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -7,7 +7,8 @@ "BASE_IMAGE": "${localEnv:BASE_IMAGE:ubuntu:24.04}" } }, - "runArgs": ["--init"], + "overrideCommand": false, + "runArgs": ["--init", "--stop-timeout=60"], "mounts": [ "source=sentry-ruby-bundle,target=/home/sentry/bundle,type=volume" ], diff --git a/.devcontainer/keep-alive b/.devcontainer/keep-alive new file mode 100755 index 000000000..826665fbb --- /dev/null +++ b/.devcontainer/keep-alive @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +stop_postgres() { + local data_dir=/tmp/postgres-data + local pid version + + [[ -s "$data_dir/postmaster.pid" ]] || return 0 + read -r pid < "$data_dir/postmaster.pid" || return 0 + [[ "$pid" =~ ^[1-9][0-9]*$ && /proc/$pid/cwd -ef "$data_dir" ]] || return 0 + read -r version < "$data_dir/PG_VERSION" || return 1 + local pg_bin="/usr/lib/postgresql/$version/bin" + [[ /proc/$pid/exe -ef "$pg_bin/postgres" ]] || return 0 + "$pg_bin/pg_ctl" -D "$data_dir" -m fast -w stop +} + +trap 'stop_postgres; exit $?' TERM INT + +sleep infinity & +wait "$!"