Merge branch 'master' of github.com:hectic-lab/util.nix
This commit is contained in:
@@ -148,7 +148,7 @@ log() {
|
||||
''
|
||||
|
||||
# shellcheck disable=SC1003
|
||||
fmt="$(printf "%s$delimetr" "$@" | sed 's/\\033\[0m/'\'"$color"'/g')"
|
||||
fmt="$(printf "%s$delimetr" "$@" | sed 's/\\033\[0m/''\'"$color"'/g')"
|
||||
shift
|
||||
# shellcheck disable=SC1003
|
||||
printf "${BBLACK}${HECTIC_NAMESPACE}> %b\n" "$color$fmt$NC" >&3
|
||||
|
||||
@@ -35,6 +35,7 @@ These variables must be set for `db-tool` to function.
|
||||
| `HECTIC_DOTENV_FILE` | (unset) | Optional dotenv file. When set and readable, `database hydrate` passes its contents to `hectic.load_secrets_from_env(...)` after applying the bundle. Falls back to `${LOCAL_DIR}/.env.${ENVIRONMENT}` when unset. |
|
||||
| `PATCH_LOG` | (stdout) | Path to log the output of database patches. |
|
||||
| `HYDRATE_LOG` | (stdout) | Path to log the output of database hydration. |
|
||||
| `NO_TTY` | `0` | Set to `1` to redirect `pg_ctl` stdout/stderr to `/dev/null`. Prevents hanging in non-interactive environments (e.g., CI, agents) where open file descriptors from background PostgreSQL processes keep the parent session alive. |
|
||||
|
||||
## Postgres Package Override
|
||||
|
||||
|
||||
@@ -4,8 +4,14 @@ postgres_cleanup_main() {
|
||||
if [ -z "${PG_WORKING_DIR:-}" ] && [ -z "${LOCAL_DIR:-}" ]; then return 0; fi
|
||||
: "${PG_WORKING_DIR:=$LOCAL_DIR/focus/postgresql}"
|
||||
if [ -f "${PG_WORKING_DIR}/data/postmaster.pid" ]; then
|
||||
if [ "${NO_TTY:-0}" = "1" ]; then
|
||||
_pg_log="$(mktemp /tmp/postgres-cleanup.XXXXXX.log)"
|
||||
pg_ctl -D "${PG_WORKING_DIR}/data" -m fast -w stop > "$_pg_log" 2>&1 || :
|
||||
printf '%s\n' "postgres-cleanup: pg_ctl stop output redirected to $_pg_log" >&2
|
||||
else
|
||||
pg_ctl -D "${PG_WORKING_DIR}/data" -m fast -w stop || :
|
||||
fi
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,13 @@ postgres_init_main() {
|
||||
mkdir -p "$PG_WORKING_DIR" || return 1
|
||||
wd="$PG_WORKING_DIR"; data="$wd/data"; sockdir="$wd/sock"; db="$PG_DATABASE"
|
||||
|
||||
pg_ctl -D "$data" -m fast -w stop >/dev/null 2>&1 || :
|
||||
if [ "${NO_TTY:-0}" = "1" ]; then
|
||||
_pg_log="$(mktemp /tmp/postgres-init-stop.XXXXXX.log)"
|
||||
pg_ctl -D "$data" -m fast -w stop >"$_pg_log" 2>&1 || :
|
||||
printf '%s\n' "postgres-init: pg_ctl stop output redirected to $_pg_log" >&2
|
||||
else
|
||||
pg_ctl -D "$data" -m fast -w stop || :
|
||||
fi
|
||||
mkdir -p "$sockdir" || return 1
|
||||
|
||||
if [ "${PG_REUSE+x}" ] && [ -f "$data/PG_VERSION" ]; then PG_REUSE=1; else PG_REUSE=0; fi
|
||||
@@ -36,7 +42,13 @@ postgres_init_main() {
|
||||
sed -i '/^[[:space:]]*port[[:space:]]*=/d' "$data/postgresql.conf" || return 1
|
||||
sed -i '/^[[:space:]]*unix_socket_directories[[:space:]]*=/d' "$data/postgresql.conf" || return 1
|
||||
{ printf '%s\n' "port = $PG_PORT"; printf '%s\n' "unix_socket_directories = '$sockdir'"; } >> "$data/postgresql.conf" || return 1
|
||||
if [ "${NO_TTY:-0}" = "1" ]; then
|
||||
_pg_log="$(mktemp /tmp/postgres-init-start.XXXXXX.log)"
|
||||
with_closed_fds pg_ctl -D "$data" -o "-F" -w start >"$_pg_log" 2>&1 || return 2
|
||||
printf '%s\n' "postgres-init: pg_ctl start output redirected to $_pg_log" >&2
|
||||
else
|
||||
with_closed_fds pg_ctl -D "$data" -o "-F" -w start || return 2
|
||||
fi
|
||||
|
||||
user="$(id -un)" || return 1
|
||||
if [ "$PG_REUSE" -eq 0 ]; then
|
||||
|
||||
Reference in New Issue
Block a user