Skip to content

Commit 9cdefeb

Browse files
committed
3.3.0pre
1 parent bd6f4e0 commit 9cdefeb

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

rootfs/container/functions/10-postgres

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
postgres_bootstrap_filesystem() {
66
create_folder \
77
"${CERT_PATH},\
8-
${CONFIG_PATH},\
98
${LOG_PATH}" \
109
postgres:postgres 755
1110

1211
if [ -n "${CONFIG_PATH}" ] ; then
1312
create_folder \
1413
"${CONFIG_PATH}" \
15-
postgres:postgres 755
14+
postgres:postgres 750
1615
fi
1716

1817
create_folder \
19-
"${DATA_PATH},\
18+
"/etc/postgres,\
19+
${DATA_PATH},\
2020
${WAL_PATH},\
2121
/var/run/postgresql" \
2222
postgres:postgres 700
@@ -84,7 +84,7 @@ EOF
8484
EOSQL
8585
fi
8686

87-
if ! grep -q "${MONITOR_USER}" "${HBA_FILE}" ; then
87+
if ! ( [ -f "${HBA_FILE}" ] && grep -q "${MONITOR_USER}" "${HBA_FILE}" 2>/dev/null ); then
8888
print_notice "[configure_monitoring] Adding '${MONITOR_USER}' to '${HBA_FILE}'"
8989
echo "host all ${MONITOR_USER} localhost md5" | silent tee -a "${HBA_FILE}"
9090
fi
@@ -121,7 +121,7 @@ postgres_configure_replication() {
121121
EOSQL
122122
fi
123123

124-
if ! grep -q "${REPLICATION_USER}" "${HBA_FILE}" ; then
124+
if ! ( [ -f "${HBA_FILE}" ] && grep -q "${REPLICATION_USER}" "${HBA_FILE}" 2>/dev/null ); then
125125
print_notice "[configure_replication] Adding '${REPLICATION_USER}/${REPLICATION_IP_ALLOW}' to '${HBA_FILE}'"
126126
echo "host replication ${REPLICATION_USER} ${REPLICATION_IP_ALLOW} md5" | silent tee -a "${HBA_FILE}"
127127
fi
@@ -222,14 +222,12 @@ postgres_configure_server() {
222222
local key="$2"
223223
local value="$3"
224224
local pattern="^${key}[[:space:]]*="
225-
if grep -qE "${pattern}" "${file}"; then
226-
s6-setuidgid postgres sed \
227-
-i \
228-
-E "s|${pattern}[[:space:]]*.*|${key} = ${value}|g"
229-
"${file}"
230-
else
231-
echo "${key} = ${value}" | s6-setuidgid tee -a "${file}"
232-
fi
225+
# Only attempt grep/sed if the file exists; silence grep to prevent noisy errors
226+
if [ -f "${file}" ] && grep -qE "${pattern}" "${file}" 2>/dev/null; then
227+
s6-setuidgid postgres sed -i -E "s|${pattern}[[:space:]]*.*|${key} = ${value}|g" "${file}"
228+
else
229+
echo "${key} = ${value}" | silent s6-setuidgid postgres tee -a "${file}"
230+
fi
233231
}
234232

235233
if [ "${SETUP_MODE,,}" = "auto" ] ; then

rootfs/container/init/init.d/10-postgres

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ prepare_service 10-postgres
88
SERVICE_NAME="postgres"
99
output_off
1010

11-
bootstrap_filesystem
12-
initialize_cluster
13-
configure_server
14-
control_server start
15-
create_databases
16-
configure_replication
17-
configure_monitoring
18-
control_server stop
11+
postgres_bootstrap_filesystem
12+
postgres_initialize_cluster
13+
postgres_configure_server
14+
postgres_control_server start
15+
postgres_create_databases
16+
postgres_configure_replication
17+
postgres_configure_monitoring
18+
postgres_control_server stop
1919
liftoff

rootfs/container/run/available/10-postgres/run

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ case "${LOG_TYPE,,}" in
1212
file ) hide_output=silent ;;
1313
esac
1414

15+
if [ "${SETUP_MODE,,}" = "auto" ] ; then
16+
engine_config="/etc/postgres/container.conf"
17+
else
18+
engine_config="${CONFIG_PATH%/}/${CONFIG_FILE}"
19+
fi
20+
1521
liftoff
1622

1723
print_start "Starting PostgreSQL $(psql --version | head -n 1 | awk '{print $NF}')"
1824
TZ="${TIMEZONE}" ${hide_output} exec s6-setuidgid postgres postgres \
19-
--config_file="${CONFIG_PATH%/}"/"${CONFIG_FILE}" ${SERVER_ARGS}
25+
--config_file="${engine_config}" ${SERVER_ARGS}

0 commit comments

Comments
 (0)