Skip to content

Commit 85a2696

Browse files
authored
fix(devcontainer): shut down PostgreSQL cleanly (#3219)
1 parent 1636faa commit 85a2696

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

‎.devcontainer/Dockerfile‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ RUN mkdir -p /home/sentry/bundle
5555
# Chromium, ChromeDriver, mise, and the toolchain (Java, Ruby, Node) are
5656
# installed by the local `./features/tools` dev container feature, which runs
5757
# after this Dockerfile — see devcontainer.json.
58+
59+
COPY .devcontainer/keep-alive /usr/local/bin/sentry-devcontainer-keep-alive
60+
CMD ["/usr/local/bin/sentry-devcontainer-keep-alive"]

‎.devcontainer/devcontainer.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"BASE_IMAGE": "${localEnv:BASE_IMAGE:ubuntu:24.04}"
88
}
99
},
10-
"runArgs": ["--init"],
10+
"overrideCommand": false,
11+
"runArgs": ["--init", "--stop-timeout=60"],
1112
"mounts": [
1213
"source=sentry-ruby-bundle,target=/home/sentry/bundle,type=volume"
1314
],

‎.devcontainer/keep-alive‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
stop_postgres() {
4+
local data_dir=/tmp/postgres-data
5+
local pid version
6+
7+
[[ -s "$data_dir/postmaster.pid" ]] || return 0
8+
read -r pid < "$data_dir/postmaster.pid" || return 0
9+
[[ "$pid" =~ ^[1-9][0-9]*$ && /proc/$pid/cwd -ef "$data_dir" ]] || return 0
10+
read -r version < "$data_dir/PG_VERSION" || return 1
11+
local pg_bin="/usr/lib/postgresql/$version/bin"
12+
[[ /proc/$pid/exe -ef "$pg_bin/postgres" ]] || return 0
13+
"$pg_bin/pg_ctl" -D "$data_dir" -m fast -w stop
14+
}
15+
16+
trap 'stop_postgres; exit $?' TERM INT
17+
18+
sleep infinity &
19+
wait "$!"

0 commit comments

Comments
 (0)