-
-
Notifications
You must be signed in to change notification settings - Fork 198
chore: fly fixes; PITR + logging + shutdown + perms #665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
b2add77
3b6138e
39370e2
bee3a36
a830c08
28c7cf5
17850ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,8 @@ function configure_services { | |
PG_CONF=/etc/postgresql/postgresql.conf | ||
SUPERVISOR_CONF=/etc/supervisor/supervisord.conf | ||
|
||
export CONFIGURED_FLAG_PATH=${CONFIGURED_FLAG_PATH:-$DATA_VOLUME_MOUNTPOINT/machine.configured} | ||
|
||
function setup_postgres { | ||
tar -xzvf "$INIT_PAYLOAD_PATH" -C / ./etc/postgresql.schema.sql | ||
mv /etc/postgresql.schema.sql /docker-entrypoint-initdb.d/migrations/99-schema.sql | ||
|
@@ -75,6 +77,40 @@ function setup_postgres { | |
-e "s|ssl_key_file = ''|ssl_key_file = '$PGSSLKEY'|g" \ | ||
$PG_CONF | ||
|
||
if [ "${DATA_VOLUME_MOUNTPOINT}" ]; then | ||
# Preserve postgresql configs across restarts | ||
POSTGRESQL_CUSTOM_DIR="${DATA_VOLUME_MOUNTPOINT}/etc/postgresql-custom" | ||
|
||
mkdir -p "${POSTGRESQL_CUSTOM_DIR}" | ||
|
||
if [ ! -f "${CONFIGURED_FLAG_PATH}" ]; then | ||
echo "Copying existing custom postgresql config from /etc/postgresql-custom to ${POSTGRESQL_CUSTOM_DIR}" | ||
cp -R "/etc/postgresql-custom/." "${POSTGRESQL_CUSTOM_DIR}/" | ||
fi | ||
|
||
rm -rf "/etc/postgresql-custom" | ||
ln -s "${POSTGRESQL_CUSTOM_DIR}" "/etc/postgresql-custom" | ||
chown -R postgres:postgres "/etc/postgresql-custom" | ||
chown -R postgres:postgres "${POSTGRESQL_CUSTOM_DIR}" | ||
chmod g+rx "${POSTGRESQL_CUSTOM_DIR}" | ||
|
||
# Preserve wal-g configs across restarts | ||
WALG_CONF_DIR="${DATA_VOLUME_MOUNTPOINT}/etc/wal-g" | ||
mkdir -p "${WALG_CONF_DIR}" | ||
|
||
if [ ! -f "${CONFIGURED_FLAG_PATH}" ]; then | ||
echo "Copying existing custom wal-g config from /etc/wal-g to ${WALG_CONF_DIR}" | ||
cp -R "/etc/wal-g/." "${WALG_CONF_DIR}/" | ||
fi | ||
|
||
rm -rf "/etc/wal-g" | ||
ln -s "${WALG_CONF_DIR}" "/etc/wal-g" | ||
chown -R adminapi:adminapi "/etc/wal-g" | ||
chown -R adminapi:adminapi "${WALG_CONF_DIR}" | ||
chmod g+rx "/etc/wal-g" | ||
chmod g+rx "${WALG_CONF_DIR}" | ||
fi | ||
|
||
# TODO: define instance size and type for running optimizations | ||
# /opt/supabase-admin-api optimize db --destination-config-file-path /etc/postgresql-custom/generated-optimizations.conf | ||
# /opt/supabase-admin-api optimize pgbouncer --destination-config-file-path /etc/pgbouncer-custom/generated-optimizations.ini | ||
|
@@ -121,14 +157,15 @@ fi | |
if [ "${PGDATA_REAL:-}" ]; then | ||
mkdir -p "${PGDATA_REAL}" | ||
chown -R postgres:postgres "${PGDATA_REAL}" | ||
chmod g+rx "${PGDATA_REAL}" | ||
chmod -R g+rx "${PGDATA_REAL}" | ||
fi | ||
|
||
if [ "${PGDATA:-}" ]; then | ||
if [ "${PGDATA_REAL:-}" ]; then | ||
mkdir -p "$(dirname "${PGDATA}")" | ||
rm -rf "${PGDATA}" | ||
ln -s "${PGDATA_REAL}" "${PGDATA}" | ||
chmod -R g+rx "${PGDATA}" | ||
else | ||
mkdir -p "$PGDATA" | ||
chown postgres:postgres "$PGDATA" | ||
|
@@ -138,10 +175,28 @@ fi | |
|
||
# Download and extract init payload from s3 | ||
export INIT_PAYLOAD_PATH=${INIT_PAYLOAD_PATH:-/tmp/payload.tar.gz} | ||
export CONFIGURED_FLAG_PATH=${CONFIGURED_FLAG_PATH:-$PGDATA/../machine.configured} | ||
|
||
if [ "${INIT_PAYLOAD_PRESIGNED_URL:-}" ]; then | ||
curl -sSL "$INIT_PAYLOAD_PRESIGNED_URL" -o "$INIT_PAYLOAD_PATH" | ||
curl -sSL "$INIT_PAYLOAD_PRESIGNED_URL" -o "/tmp/payload.tar.gz" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
mv "/tmp/payload.tar.gz" "$INIT_PAYLOAD_PATH" | ||
fi | ||
|
||
if [ "${DATA_VOLUME_MOUNTPOINT}" ]; then | ||
LOGS_FOLDER="${DATA_VOLUME_MOUNTPOINT}/logs" | ||
|
||
mkdir -p "${LOGS_FOLDER}/postgresql" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could be a loop over postgresql, services, wal-g, but this is fine too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fair point - refactored into a loop |
||
mkdir -p "${LOGS_FOLDER}/services" | ||
mkdir -p "${LOGS_FOLDER}/wal-g" | ||
|
||
rm -rf "/var/log/postgresql" | ||
rm -rf "/var/log/services" | ||
rm -rf "/var/log/wal-g" | ||
|
||
ln -s "${LOGS_FOLDER}/postgresql" "/var/log/postgresql" | ||
ln -s "${LOGS_FOLDER}/services" "/var/log/services" | ||
ln -s "${LOGS_FOLDER}/wal-g" "/var/log/wal-g" | ||
|
||
chown -R postgres:postgres "${LOGS_FOLDER}" | ||
fi | ||
|
||
# Process init payload | ||
|
@@ -152,7 +207,7 @@ else | |
echo "Skipped extracting init payload: $INIT_PAYLOAD_PATH does not exist" | ||
fi | ||
|
||
mkdir /var/log/services | ||
mkdir -p /var/log/services | ||
|
||
SUPERVISOR_CONF=/etc/supervisor/supervisord.conf | ||
find /etc/supervisor/ -type d -exec chmod 0770 {} + | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,5 @@ log_rotation_size = 0 # Automatic rotation of logfiles will | |
# or size-driven rotation. Default is | ||
# off, meaning append to existing files | ||
# in all cases. | ||
|
||
log_disconnections = on # log end of a session, including duration | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. intentional? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Postgres output related to disconnections is filtered out by Vector, so it won't additionally be shipped to Logflare. This approach diverges the configs, thus we could have the shutdown script run an |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[program:supa-shutdown] | ||
command=/usr/local/bin/supa-shutdown | ||
user=root | ||
autorestart=true | ||
autostart=true | ||
stdout_logfile=/var/log/services/supa-shutdown.log | ||
redirect_stderr=true | ||
stdout_logfile_maxbytes=10MB | ||
priority=50 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason not to preserve the
.sh
ext?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no reason - will add extension