fix script

This commit is contained in:
2025-03-17 13:38:21 +04:00
parent c7d116be87
commit f5ab052719

56
lib.nix
View File

@@ -108,32 +108,38 @@ in
) )
); );
}; };
setupScript = pkgs.writeShellScriptBin "setup-postgres" '' setupScript = pkgs.writeShellApplication {
set -euo pipefail name = "setup-postgres";
export PATH=${package}/bin:${pkgs.coreutils}/bin runtimeInputs = [
POSTGRES_RUN_INITIAL_SCRIPT="false" package
if [[ ! -d "$PGDATA" ]]; then pkgs.coreutils
initdb --no-instructions pkgs.gnused
POSTGRES_RUN_INITIAL_SCRIPT="true" ];
echo text = ''
echo "PostgreSQL initdb process completed" POSTGRES_RUN_INITIAL_SCRIPT="false"
echo if [[ ! -d "$PGDATA" ]]; then
fi initdb --no-instructions
sed "s|@PGHOST|''${PGHOST}|g" ${configFile} > "$PGDATA"/postgresql.conf POSTGRES_RUN_INITIAL_SCRIPT="true"
if [[ "$POSTGRES_RUN_INITIAL_SCRIPT" == "true" ]]; then echo
echo echo "PostgreSQL initdb process completed"
echo "PostgreSQL is setting up the initial database" echo
echo fi
pg_ctl -w start -o "-c unix_socket_directories=$PGHOST -c listen_addresses= -p ${builtins.toString port}" sed "s|@PGHOST|''${PGHOST}|g" ${configFile} > "$PGDATA"/postgresql.conf
pg_ctl -m fast -w stop if [[ "$POSTGRES_RUN_INITIAL_SCRIPT" == "true" ]]; then
else echo
echo echo "PostgreSQL is setting up the initial database"
echo "Database directory exists. Skipping initialization" echo
echo pg_ctl -w start -o "-c unix_socket_directories=$PGHOST -c listen_addresses= -p ${builtins.toString port}"
fi pg_ctl -m fast -w stop
else
echo
echo "Database directory exists. Skipping initialization"
echo
fi
unset POSTGRES_RUN_INITIAL_SCRIPT unset POSTGRES_RUN_INITIAL_SCRIPT
''; '';
};
script = pkgs.writeShellApplication { script = pkgs.writeShellApplication {
name = "run-postgres"; name = "run-postgres";