@@ -40,6 +40,8 @@ function configure_services {
40
40
PG_CONF=/etc/postgresql/postgresql.conf
41
41
SUPERVISOR_CONF=/etc/supervisor/supervisord.conf
42
42
43
+ export CONFIGURED_FLAG_PATH=${CONFIGURED_FLAG_PATH:- $DATA_VOLUME_MOUNTPOINT / machine.configured}
44
+
43
45
function setup_postgres {
44
46
tar -xzvf " $INIT_PAYLOAD_PATH " -C / ./etc/postgresql.schema.sql
45
47
mv /etc/postgresql.schema.sql /docker-entrypoint-initdb.d/migrations/99-schema.sql
@@ -75,6 +77,40 @@ function setup_postgres {
75
77
-e " s|ssl_key_file = ''|ssl_key_file = '$PGSSLKEY '|g" \
76
78
$PG_CONF
77
79
80
+ if [ " ${DATA_VOLUME_MOUNTPOINT} " ]; then
81
+ # Preserve postgresql configs across restarts
82
+ POSTGRESQL_CUSTOM_DIR=" ${DATA_VOLUME_MOUNTPOINT} /etc/postgresql-custom"
83
+
84
+ mkdir -p " ${POSTGRESQL_CUSTOM_DIR} "
85
+
86
+ if [ ! -f " ${CONFIGURED_FLAG_PATH} " ]; then
87
+ echo " Copying existing custom postgresql config from /etc/postgresql-custom to ${POSTGRESQL_CUSTOM_DIR} "
88
+ cp -R " /etc/postgresql-custom/." " ${POSTGRESQL_CUSTOM_DIR} /"
89
+ fi
90
+
91
+ rm -rf " /etc/postgresql-custom"
92
+ ln -s " ${POSTGRESQL_CUSTOM_DIR} " " /etc/postgresql-custom"
93
+ chown -R postgres:postgres " /etc/postgresql-custom"
94
+ chown -R postgres:postgres " ${POSTGRESQL_CUSTOM_DIR} "
95
+ chmod g+rx " ${POSTGRESQL_CUSTOM_DIR} "
96
+
97
+ # Preserve wal-g configs across restarts
98
+ WALG_CONF_DIR=" ${DATA_VOLUME_MOUNTPOINT} /etc/wal-g"
99
+ mkdir -p " ${WALG_CONF_DIR} "
100
+
101
+ if [ ! -f " ${CONFIGURED_FLAG_PATH} " ]; then
102
+ echo " Copying existing custom wal-g config from /etc/wal-g to ${WALG_CONF_DIR} "
103
+ cp -R " /etc/wal-g/." " ${WALG_CONF_DIR} /"
104
+ fi
105
+
106
+ rm -rf " /etc/wal-g"
107
+ ln -s " ${WALG_CONF_DIR} " " /etc/wal-g"
108
+ chown -R adminapi:adminapi " /etc/wal-g"
109
+ chown -R adminapi:adminapi " ${WALG_CONF_DIR} "
110
+ chmod g+rx " /etc/wal-g"
111
+ chmod g+rx " ${WALG_CONF_DIR} "
112
+ fi
113
+
78
114
# TODO: define instance size and type for running optimizations
79
115
# /opt/supabase-admin-api optimize db --destination-config-file-path /etc/postgresql-custom/generated-optimizations.conf
80
116
# /opt/supabase-admin-api optimize pgbouncer --destination-config-file-path /etc/pgbouncer-custom/generated-optimizations.ini
121
157
if [ " ${PGDATA_REAL:- } " ]; then
122
158
mkdir -p " ${PGDATA_REAL} "
123
159
chown -R postgres:postgres " ${PGDATA_REAL} "
124
- chmod g+rx " ${PGDATA_REAL} "
160
+ chmod -R g+rx " ${PGDATA_REAL} "
125
161
fi
126
162
127
163
if [ " ${PGDATA:- } " ]; then
128
164
if [ " ${PGDATA_REAL:- } " ]; then
129
165
mkdir -p " $( dirname " ${PGDATA} " ) "
130
166
rm -rf " ${PGDATA} "
131
167
ln -s " ${PGDATA_REAL} " " ${PGDATA} "
168
+ chmod -R g+rx " ${PGDATA} "
132
169
else
133
170
mkdir -p " $PGDATA "
134
171
chown postgres:postgres " $PGDATA "
138
175
139
176
# Download and extract init payload from s3
140
177
export INIT_PAYLOAD_PATH=${INIT_PAYLOAD_PATH:-/ tmp/ payload.tar.gz}
141
- export CONFIGURED_FLAG_PATH=${CONFIGURED_FLAG_PATH:- $PGDATA / ../ machine.configured}
142
178
143
179
if [ " ${INIT_PAYLOAD_PRESIGNED_URL:- } " ]; then
144
- curl -sSL " $INIT_PAYLOAD_PRESIGNED_URL " -o " $INIT_PAYLOAD_PATH "
180
+ curl -fsSL " $INIT_PAYLOAD_PRESIGNED_URL " -o " /tmp/payload.tar.gz"
181
+ mv " /tmp/payload.tar.gz" " $INIT_PAYLOAD_PATH "
182
+ fi
183
+
184
+ if [ " ${DATA_VOLUME_MOUNTPOINT} " ]; then
185
+ BASE_LOGS_FOLDER=" ${DATA_VOLUME_MOUNTPOINT} /logs"
186
+
187
+ for folder in " postgresql" " services" " wal-g" ; do
188
+ mkdir -p " ${BASE_LOGS_FOLDER} /${folder} "
189
+ rm -rf " /var/log/${folder} "
190
+ ln -s " ${BASE_LOGS_FOLDER} /${folder} " " /var/log/${folder} "
191
+ done
192
+
193
+ chown -R postgres:postgres " ${LOGS_FOLDER} "
145
194
fi
146
195
147
196
# Process init payload
152
201
echo " Skipped extracting init payload: $INIT_PAYLOAD_PATH does not exist"
153
202
fi
154
203
155
- mkdir /var/log/services
204
+ mkdir -p /var/log/services
156
205
157
206
SUPERVISOR_CONF=/etc/supervisor/supervisord.conf
158
207
find /etc/supervisor/ -type d -exec chmod 0770 {} +
0 commit comments