Skip to content

Commit 78f949b

Browse files
committed
go back to what we had
1 parent 681ea18 commit 78f949b

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
FROM percona/percona-postgresql-operator:2.6.0-ppg16.8-postgres
22

3+
# Switch to root user temporarily to gain necessary privileges for setup
4+
USER 0
5+
36
COPY postgres-oom-adjuster.sh /usr/local/bin/
47
COPY entrypoint-wrapper.sh /usr/local/bin/
58

entrypoint-wrapper.sh

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,34 @@
22
set -e
33

44
# For Percona PostgreSQL Operator, we need to focus on protecting the postmaster process
5+
# Original user in the Percona PostgreSQL Operator image
6+
ORIGINAL_USER=26
57
ORIGINAL_ENTRYPOINT="/opt/crunchy/bin/postgres-ha/bootstrap-postgres-ha.sh"
68

7-
# Try to set OOM score adjustment if possible, but don't fail if we can't
8-
if command -v sudo >/dev/null 2>&1; then
9-
# If sudo is available, use it to set OOM score
10-
sudo -n sh -c 'echo -900 > /proc/self/oom_score_adj' >/dev/null 2>&1 || true
11-
echo "Attempted to set OOM score adjustment using sudo"
12-
elif command -v setcap >/dev/null 2>&1; then
13-
# Try to give the oom-adjuster script the capability to adjust OOM scores
14-
setcap 'cap_sys_resource=+ep' /usr/local/bin/postgres-oom-adjuster.sh >/dev/null 2>&1 || true
15-
echo "Attempted to grant capabilities to OOM adjuster"
9+
# Set OOM score adjustment for our own process (will be inherited)
10+
if [ -f "/proc/self/oom_score_adj" ]; then
11+
echo -900 > /proc/self/oom_score_adj
12+
echo "Set OOM score adjustment to -900 for pid 1"
13+
else
14+
echo "WARNING: Cannot set OOM score adjustment (file not found)"
1615
fi
1716

18-
# Start a background process to monitor and adjust PostgreSQL if possible
17+
# Start the OOM adjuster in the background
1918
nohup /usr/local/bin/postgres-oom-adjuster.sh >> /tmp/postgres-oom-adjuster.log 2>&1 &
2019
echo "Started postmaster OOM adjuster in background"
2120

22-
# Execute the original entrypoint
23-
echo "Executing original entrypoint: $ORIGINAL_ENTRYPOINT $@"
24-
exec "$ORIGINAL_ENTRYPOINT" "$@"
21+
# Set environment variables for PostgreSQL child processes
22+
export PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
23+
export PG_OOM_ADJUST_VALUE=0
24+
25+
# Switching to the original user and executing original entrypoint
26+
echo "Switching to user $ORIGINAL_USER and executing original entrypoint: $ORIGINAL_ENTRYPOINT $@"
27+
28+
# Check which user-switching command is available
29+
if command -v runuser >/dev/null 2>&1; then
30+
# Use runuser (available on RHEL/CentOS/Fedora)
31+
exec runuser -u "#$ORIGINAL_USER" -- "$ORIGINAL_ENTRYPOINT" "$@"
32+
else
33+
# Fall back to su
34+
exec su -s /bin/bash $ORIGINAL_USER -c "$ORIGINAL_ENTRYPOINT $*"
35+
fi

0 commit comments

Comments
 (0)