fix script

This commit is contained in:
2025-03-17 12:25:01 +04:00
parent 886af20792
commit f429bb2ab1

20
lib.nix
View File

@@ -115,9 +115,8 @@ in
set -euo pipefail
export PATH=${package}/bin:${pkgs.coreutils}/bin
POSTGRES_RUN_INITIAL_SCRIPT="false"
if [[ ! -d "${data_dir}" ]]; then
initdb -D ${data_dir} --no-instructions
if [[ ! -d "$PGDATA" ]]; then
initdb --no-instructions
POSTGRES_RUN_INITIAL_SCRIPT="true"
echo
echo "PostgreSQL initdb process completed"
@@ -128,16 +127,8 @@ in
echo
echo "PostgreSQL is setting up the initial database"
echo
if [[ -z "''${PGHOST+x}" ]]; then
OLDPGHOST=""
else
OLDPGHOST="$PGHOST"
fi
PGHOST=${lib.escapeShellArg runtimeDir}
pg_ctl -D "${data_dir}" -w start -o "-c unix_socket_directories=${data_dir} -c listen_addresses= -p ${builtins.toString port}"
pg_ctl -D "${data_dir}" -m fast -w stop
PGHOST="$OLDPGHOST"
unset OLDPGHOST
pg_ctl -w start -o "-c unix_socket_directories=${data_dir} -c listen_addresses= -p ${builtins.toString port}"
pg_ctl -m fast -w stop
else
echo
echo "Database directory exists. Skipping initialization"
@@ -151,9 +142,10 @@ in
name = "run-postgres";
text = ''
set -euo pipefail
export PGDATA=${data_dir} PGHOST=${runtimeDir} PGPORT=${builtins.toString port}
mkdir -p ${lib.escapeShellArg runtimeDir}
${setupScript}/bin/setup-postgres
exec ${package}/bin/postgres -D${data_dir}
exec ${package}/bin/postgres
'';
};
in