Skip to content

Commit 4d83016

Browse files
authored
chore: make autoshutdown toggleable; disable shutdown by default (#670)
1 parent 39760b1 commit 4d83016

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

docker/all-in-one/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ COPY --chown=vector:vector docker/all-in-one/etc/vector/vector.yaml /etc/vector/
186186
# Customizations for supervisor
187187
COPY docker/all-in-one/etc/supervisor /etc/supervisor
188188

189+
# Customizations for supa-shutdown
190+
COPY --chown=adminapi:adminapi docker/all-in-one/etc/supa-shutdown /etc/supa-shutdown
191+
189192
# Configure service ports
190193
ENV PGRST_SERVER_PORT=3000
191194
ENV PGRST_ADMIN_SERVER_PORT=3001

docker/all-in-one/entrypoint.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ else
220220
/init/configure-adminapi.sh
221221
fi
222222

223+
if [ "${AUTOSHUTDOWN_ENABLED:-}" ]; then
224+
sed -i "s/autostart=.*/autostart=true/" /etc/supervisor/db-only/supa-shutdown.conf
225+
fi
223226

224227
touch "$CONFIGURED_FLAG_PATH"
225228
start_supervisor
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SHUTDOWN_IDLE_TIME_MINUTES=

docker/all-in-one/etc/supervisor/db-only/supa-shutdown.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
command=/usr/local/bin/supa-shutdown.sh
33
user=root
44
autorestart=true
5-
autostart=true
5+
autostart=false
66
stdout_logfile=/var/log/services/supa-shutdown.log
77
redirect_stderr=true
88
stdout_logfile_maxbytes=10MB

docker/all-in-one/shutdown.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
# If all of these conditions are met, then Postgres is shut down, allowing it to wrap up any pending transactions (such as WAL shippipng) and gracefully exit.
1010
# To terminate the machine/container, a SIGTERM signal is sent to the top-level process (supervisord) which will then shut down all other processes and exit.
1111

12-
MAX_IDLE_TIME_MINUTES=${MAX_IDLE_TIME_MINUTES:-5}
12+
DEFAULT_MAX_IDLE_TIME_MINUTES=${MAX_IDLE_TIME_MINUTES:-5}
13+
CONFIG_FILE_PATH=${CONFIG_FILE_PATH:-/etc/supa-shutdown/shutdown.conf}
1314

1415
run_sql() {
1516
psql -h localhost -U supabase_admin -d postgres "$@"
@@ -73,6 +74,18 @@ run_sql -c "SELECT pg_reload_conf();"
7374

7475
sleep $((MAX_IDLE_TIME_MINUTES * 60))
7576
while true; do
77+
if [ -f "$CONFIG_FILE_PATH" ]; then
78+
source "$CONFIG_FILE_PATH"
79+
80+
if [ -z "$SHUTDOWN_IDLE_TIME_MINUTES" ]; then
81+
MAX_IDLE_TIME_MINUTES="$DEFAULT_MAX_IDLE_TIME_MINUTES"
82+
else
83+
MAX_IDLE_TIME_MINUTES="$SHUTDOWN_IDLE_TIME_MINUTES"
84+
fi
85+
else
86+
MAX_IDLE_TIME_MINUTES="$DEFAULT_MAX_IDLE_TIME_MINUTES"
87+
fi
88+
7689
check_activity
7790
sleep 30
7891
done

0 commit comments

Comments
 (0)