mirror of
https://github.com/juspay/services-flake.git
synced 2024-09-19 16:27:29 +03:00
fix(postgres): empty socketDir
by default (#160)
resolves #139 > empty `unix_socket_directories` means not listening on any Unix-domain sockets, in which case only TCP/IP sockets can be used to connect to the server. see: https://www.postgresql.org/docs/current/runtime-config-connection.html#GUC-UNIX-SOCKET-DIRECTORIES * use TCP/IP by default for health check
This commit is contained in:
parent
3090d6f489
commit
18d5c1d168
@ -20,6 +20,9 @@
|
|||||||
{#socket-path}
|
{#socket-path}
|
||||||
### Unix-domain socket path is too long
|
### Unix-domain socket path is too long
|
||||||
|
|
||||||
|
> [!warning]
|
||||||
|
> Only relevant if `socketDir` is set. If not, postgres uses TCP/IP by default.
|
||||||
|
|
||||||
We already talk about this in the [data directory guide](datadir.md#socket-path). In case of postgres, you can set `socketDir` while keeping the `dataDir` unchanged.
|
We already talk about this in the [data directory guide](datadir.md#socket-path). In case of postgres, you can set `socketDir` while keeping the `dataDir` unchanged.
|
||||||
|
|
||||||
>[!note]
|
>[!note]
|
||||||
|
@ -52,8 +52,12 @@ in
|
|||||||
|
|
||||||
socketDir = lib.mkOption {
|
socketDir = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
default = config.dataDir;
|
default = "";
|
||||||
description = "The DB socket directory";
|
description = "The DB socket directory";
|
||||||
|
defaultText = ''
|
||||||
|
An empty value specifies not listening on any Unix-domain sockets, in which case only TCP/IP sockets can be used to connect to the server.
|
||||||
|
See: https://www.postgresql.org/docs/current/runtime-config-connection.html#GUC-UNIX-SOCKET-DIRECTORIES
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
# Based on: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING-URIS
|
# Based on: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING-URIS
|
||||||
@ -128,7 +132,7 @@ in
|
|||||||
listen_addresses = lib.mkOption {
|
listen_addresses = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
description = "Listen address";
|
description = "Listen address";
|
||||||
default = "";
|
default = "127.0.0.1";
|
||||||
example = "127.0.0.1";
|
example = "127.0.0.1";
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -309,13 +313,17 @@ in
|
|||||||
text = ''
|
text = ''
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
PGDATA=$(readlink -f "${config.dataDir}")
|
PGDATA=$(readlink -f "${config.dataDir}")
|
||||||
PGSOCKETDIR=$(readlink -f "${config.socketDir}")
|
|
||||||
export PGDATA
|
export PGDATA
|
||||||
|
${ if config.socketDir != "" then ''
|
||||||
|
PGSOCKETDIR=$(readlink -f "${config.socketDir}")
|
||||||
postgres -k "$PGSOCKETDIR"
|
postgres -k "$PGSOCKETDIR"
|
||||||
|
'' else ''
|
||||||
|
postgres
|
||||||
|
''}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
pg_isreadyArgs = [
|
pg_isreadyArgs = [
|
||||||
"-h $(readlink -f \"${config.socketDir}\")"
|
"-h ${config.listen_addresses}"
|
||||||
"-p ${toString config.port}"
|
"-p ${toString config.port}"
|
||||||
"-d template1"
|
"-d template1"
|
||||||
] ++ (lib.optional (config.superuser != null) "-U ${config.superuser}");
|
] ++ (lib.optional (config.superuser != null) "-U ${config.superuser}");
|
||||||
|
@ -97,17 +97,24 @@ in
|
|||||||
# Setup config
|
# Setup config
|
||||||
echo "Setting up postgresql.conf"
|
echo "Setting up postgresql.conf"
|
||||||
cp ${configFile} "$PGDATA/postgresql.conf"
|
cp ${configFile} "$PGDATA/postgresql.conf"
|
||||||
# Create socketDir if it doesn't exist
|
# Create socketDir if it doesn't exist and it is not empty
|
||||||
|
${lib.optionalString (config.socketDir != "") ''
|
||||||
if [ ! -d "${config.socketDir}" ]; then
|
if [ ! -d "${config.socketDir}" ]; then
|
||||||
echo "Creating socket directory"
|
echo "Creating socket directory"
|
||||||
mkdir -p "${config.socketDir}"
|
mkdir -p "${config.socketDir}"
|
||||||
fi
|
fi
|
||||||
|
''}
|
||||||
|
|
||||||
if [[ "$POSTGRES_RUN_INITIAL_SCRIPT" = "true" ]]; then
|
if [[ "$POSTGRES_RUN_INITIAL_SCRIPT" = "true" ]]; then
|
||||||
echo
|
echo
|
||||||
echo "PostgreSQL is setting up the initial database."
|
echo "PostgreSQL is setting up the initial database."
|
||||||
echo
|
echo
|
||||||
|
${ if config.socketDir != "" then ''
|
||||||
PGHOST=$(mktemp -d "$(readlink -f "${config.socketDir}")/pg-init-XXXXXX")
|
PGHOST=$(mktemp -d "$(readlink -f "${config.socketDir}")/pg-init-XXXXXX")
|
||||||
|
'' else ''
|
||||||
|
PGHOST=$(mktemp -d /tmp/pg-init-XXXXXX)
|
||||||
|
''
|
||||||
|
}
|
||||||
export PGHOST
|
export PGHOST
|
||||||
|
|
||||||
function remove_tmp_pg_init_sock_dir() {
|
function remove_tmp_pg_init_sock_dir() {
|
||||||
|
Loading…
Reference in New Issue
Block a user