From c51d68a7375915154a90c22e716e832f635ca878 Mon Sep 17 00:00:00 2001 From: Beni Ruef Date: Thu, 3 Dec 2020 18:48:04 +0100 Subject: [PATCH 01/21] [type/__postgres_conf] New type based on ALTER SYSTEM command --- .../conf/type/__postgres_conf/gencode-remote | 92 +++++++++++++++++++ cdist/conf/type/__postgres_conf/man.rst | 55 +++++++++++ .../__postgres_conf/parameter/default/state | 1 + .../type/__postgres_conf/parameter/optional | 2 + 4 files changed, 150 insertions(+) create mode 100755 cdist/conf/type/__postgres_conf/gencode-remote create mode 100644 cdist/conf/type/__postgres_conf/man.rst create mode 100644 cdist/conf/type/__postgres_conf/parameter/default/state create mode 100644 cdist/conf/type/__postgres_conf/parameter/optional diff --git a/cdist/conf/type/__postgres_conf/gencode-remote b/cdist/conf/type/__postgres_conf/gencode-remote new file mode 100755 index 00000000..a09e1873 --- /dev/null +++ b/cdist/conf/type/__postgres_conf/gencode-remote @@ -0,0 +1,92 @@ +#!/bin/sh -e +# -*- mode: sh; indent-tabs-mode: t -*- +# +# 2019 Dennis Camera (dennis.camera at ssrq-sds-fds.ch) +# 2020 Beni Ruef (bernhard.ruef at ssrq-sds-fds.ch) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +os=$(cat "${__global}/explorer/os") +state_should=$(cat "${__object}/parameter/state") + +if [ "${state_should}" != 'present' ] && [ "${state_should}" != 'absent' ] +then + echo "Invalid state '${state_should}'." \ + 'Only "present" and "absent" are acceptable' >&2 + exit 1 +fi + +if [ "${state_should}" = 'present' ] && [ ! -f "${__object}/parameter/value" ] +then + echo 'Missing required parameter "value"' >&2 + exit 1 +fi + +# Parameters +conf_name="${__object_id}" +if [ -f "${__object}/parameter/value" ] +then + conf_value=$(cat "${__object}/parameter/value") +fi + +if [ "${state_should}" = 'present' ] +then + set_command="ALTER SYSTEM SET ${conf_name} = '${conf_value}'" + check_command="SHOW ${conf_name}" +else + set_command="ALTER SYSTEM SET ${conf_name} = DEFAULT" +fi + +case $os +in + openbsd|devuan) + case $os + in + openbsd) + postgres_user='_postgresql' + restart_command='/etc/rc.d/postgresql restart' + ;; + devuan) + postgres_user='postgres' + restart_command='/etc/init.d/postgresql restart' + ;; + esac + # needs two separate psql commands because ALTER SYSTEM + # cannot run inside a transaction block + cat <<-EOF + su - ${postgres_user} -c "psql postgres -twAc \ + \"${set_command}\"" + su - ${postgres_user} -c "psql postgres -twAc \ + \"SELECT pg_reload_conf()\"" + EOF + # check success (makes only sense if setting to a non-default value) + # and restart server if needed + if [ "${state_should}" = 'present' ] + then + cat <<-EOF + if [ \$(su - ${postgres_user} -c "psql postgres -twAc \"SHOW ${conf_name}\"") != '${conf_value}' ] + then + ${restart_command} + fi + EOF + fi + ;; + *) + echo "Unsupported OS: ${os}" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__postgres_conf/man.rst b/cdist/conf/type/__postgres_conf/man.rst new file mode 100644 index 00000000..76016c6c --- /dev/null +++ b/cdist/conf/type/__postgres_conf/man.rst @@ -0,0 +1,55 @@ +cdist-type__postgres_conf(7) +============================ + +Configure a PostgreSQL server. + +NOTE: This type might need to be run multiple times to apply all bits of the +configuration due to ordering requirements. + +SSRQ + + +DESCRIPTION +----------- +Configure a PostgreSQL server using ALTER SYSTEM. + + +REQUIRED PARAMETERS +------------------- +value + The value to setup (can be omitted when state is set to "absent"). + + +OPTIONAL PARAMETERS +------------------- +state + "present" or "absent". Defaults to "present". + + +BOOLEAN PARAMETERS +------------------ +None. + + +EXAMPLES +-------- + +.. code-block:: sh + + # set timezone + __postgres_conf timezone --value Europe/Zurich + + # reset maximum number of concurrent connections to default (normally 100) + __postgres_conf max_connections --state absent + + +SEE ALSO +-------- +- `cdist-type(7) `_ + + +COPYING +------- +Copyright \(C) 2020 SSRQ (www.ssrq-sds-fds.ch). +Free use of this software is granted under the terms +of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__postgres_conf/parameter/default/state b/cdist/conf/type/__postgres_conf/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__postgres_conf/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__postgres_conf/parameter/optional b/cdist/conf/type/__postgres_conf/parameter/optional new file mode 100644 index 00000000..d0460d86 --- /dev/null +++ b/cdist/conf/type/__postgres_conf/parameter/optional @@ -0,0 +1,2 @@ +state +value From 534d5f6bb5dd3d8e9cb2256e75ed182d6530a892 Mon Sep 17 00:00:00 2001 From: Beni Ruef Date: Fri, 4 Dec 2020 14:31:04 +0100 Subject: [PATCH 02/21] [type/__postgres_conf] Fix errors found by ShellCheck --- cdist/conf/type/__postgres_conf/gencode-remote | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cdist/conf/type/__postgres_conf/gencode-remote b/cdist/conf/type/__postgres_conf/gencode-remote index a09e1873..e25514d0 100755 --- a/cdist/conf/type/__postgres_conf/gencode-remote +++ b/cdist/conf/type/__postgres_conf/gencode-remote @@ -20,8 +20,8 @@ # along with cdist. If not, see . # -os=$(cat "${__global}/explorer/os") -state_should=$(cat "${__object}/parameter/state") +os=$(cat "${__global:?}/explorer/os") +state_should=$(cat "${__object:?}/parameter/state") if [ "${state_should}" != 'present' ] && [ "${state_should}" != 'absent' ] then @@ -37,7 +37,7 @@ then fi # Parameters -conf_name="${__object_id}" +conf_name="${__object_id:?}" if [ -f "${__object}/parameter/value" ] then conf_value=$(cat "${__object}/parameter/value") @@ -46,7 +46,6 @@ fi if [ "${state_should}" = 'present' ] then set_command="ALTER SYSTEM SET ${conf_name} = '${conf_value}'" - check_command="SHOW ${conf_name}" else set_command="ALTER SYSTEM SET ${conf_name} = DEFAULT" fi From 50bcd951055d7599ec340b4dea80a3a5d11dd9b0 Mon Sep 17 00:00:00 2001 From: Beni Ruef Date: Thu, 10 Dec 2020 11:45:32 +0100 Subject: [PATCH 03/21] [type/__postgres_conf] Remove faulty quotes --- cdist/conf/type/__postgres_conf/gencode-remote | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__postgres_conf/gencode-remote b/cdist/conf/type/__postgres_conf/gencode-remote index e25514d0..8ccb3b42 100755 --- a/cdist/conf/type/__postgres_conf/gencode-remote +++ b/cdist/conf/type/__postgres_conf/gencode-remote @@ -45,7 +45,7 @@ fi if [ "${state_should}" = 'present' ] then - set_command="ALTER SYSTEM SET ${conf_name} = '${conf_value}'" + set_command="ALTER SYSTEM SET ${conf_name} = ${conf_value}" else set_command="ALTER SYSTEM SET ${conf_name} = DEFAULT" fi From b4060720dc3c7cc58aa992285877e4c009caa6be Mon Sep 17 00:00:00 2001 From: Beni Ruef Date: Fri, 11 Dec 2020 11:12:16 +0100 Subject: [PATCH 04/21] [type/__postgres_conf] Fix psql options for ALTER command --- cdist/conf/type/__postgres_conf/gencode-remote | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__postgres_conf/gencode-remote b/cdist/conf/type/__postgres_conf/gencode-remote index 8ccb3b42..7d86028e 100755 --- a/cdist/conf/type/__postgres_conf/gencode-remote +++ b/cdist/conf/type/__postgres_conf/gencode-remote @@ -67,7 +67,7 @@ in # needs two separate psql commands because ALTER SYSTEM # cannot run inside a transaction block cat <<-EOF - su - ${postgres_user} -c "psql postgres -twAc \ + su - ${postgres_user} -c "psql postgres -qwc \ \"${set_command}\"" su - ${postgres_user} -c "psql postgres -twAc \ \"SELECT pg_reload_conf()\"" From 1b49fec972ce5f486f2794571c8e892d1fa6cb51 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Mon, 18 Jan 2021 19:15:49 +0100 Subject: [PATCH 05/21] [type/__postgres_conf] Refactor --- .../type/__postgres_conf/explorer/context | 42 ++++++ .../conf/type/__postgres_conf/explorer/state | 60 ++++++++ .../conf/type/__postgres_conf/gencode-remote | 135 ++++++++++-------- 3 files changed, 180 insertions(+), 57 deletions(-) create mode 100644 cdist/conf/type/__postgres_conf/explorer/context create mode 100644 cdist/conf/type/__postgres_conf/explorer/state diff --git a/cdist/conf/type/__postgres_conf/explorer/context b/cdist/conf/type/__postgres_conf/explorer/context new file mode 100644 index 00000000..3a2fa504 --- /dev/null +++ b/cdist/conf/type/__postgres_conf/explorer/context @@ -0,0 +1,42 @@ +#!/bin/sh -e +# -*- mode: sh; indent-tabs-mode: t -*- +# +# 2021 Dennis Camera (dennis.camera at ssrq-sds-fds.ch) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# Returns the "context" of the configuration setting. +# cf. also https://www.postgresql.org/docs/10/view-pg-settings.html + +os=$("${__explorer:?}/os") + +case ${os} +in + (openbsd) + postgres_user='_postgresql' + ;; + (devuan) + postgres_user='postgres' + ;; + (*) + echo "Unsupported OS: ${os}" >&2 + exit 1 + ;; +esac + +conf_name=${__object_id:?} + +su - "${postgres_user}" -c "psql postgres -twAc \"SELECT context FROM pg_settings WHERE name = '${conf_name}'\"" diff --git a/cdist/conf/type/__postgres_conf/explorer/state b/cdist/conf/type/__postgres_conf/explorer/state new file mode 100644 index 00000000..da904b56 --- /dev/null +++ b/cdist/conf/type/__postgres_conf/explorer/state @@ -0,0 +1,60 @@ +#!/bin/sh -e +# -*- mode: sh; indent-tabs-mode: t -*- +# +# 2021 Dennis Camera (dennis.camera at ssrq-sds-fds.ch) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +os=$("${__explorer:?}/os") + +case ${os} +in + (openbsd) + postgres_user='_postgresql' + ;; + (devuan) + postgres_user='postgres' + ;; + (*) + echo "Unsupported OS: ${os}" >&2 + exit 1 + ;; +esac + +conf_name=${__object_id:?} + +if su - "${postgres_user}" -c "psql postgres -twAc 'SHOW ${conf_name}'" \ + | cmp -s "${__object:?}/parameter/value" - +then + echo present +else + case $(su - "${postgres_user}" -c "psql postgres -tAwc \"SELECT source FROM pg_settings WHERE name = '${conf_name}'\"") + in + ('') + # invalid configuration parameter + # (error message was already printed by SHOW command above. + # Yes, it's a hack) + exit 1 + ;; + (default) + echo absent + ;; + (*) + echo different + ;; + esac +fi diff --git a/cdist/conf/type/__postgres_conf/gencode-remote b/cdist/conf/type/__postgres_conf/gencode-remote index 7d86028e..998b8582 100755 --- a/cdist/conf/type/__postgres_conf/gencode-remote +++ b/cdist/conf/type/__postgres_conf/gencode-remote @@ -1,7 +1,7 @@ #!/bin/sh -e # -*- mode: sh; indent-tabs-mode: t -*- # -# 2019 Dennis Camera (dennis.camera at ssrq-sds-fds.ch) +# 2019-2021 Dennis Camera (dennis.camera at ssrq-sds-fds.ch) # 2020 Beni Ruef (bernhard.ruef at ssrq-sds-fds.ch) # # This file is part of cdist. @@ -21,71 +21,92 @@ # os=$(cat "${__global:?}/explorer/os") +state_is=$(cat "${__object:?}/explorer/state") state_should=$(cat "${__object:?}/parameter/state") -if [ "${state_should}" != 'present' ] && [ "${state_should}" != 'absent' ] +conf_name=${__object_id:?} + +if test "${state_is}" = "${state_should}" then - echo "Invalid state '${state_should}'." \ - 'Only "present" and "absent" are acceptable' >&2 - exit 1 + exit 0 fi -if [ "${state_should}" = 'present' ] && [ ! -f "${__object}/parameter/value" ] -then - echo 'Missing required parameter "value"' >&2 - exit 1 -fi - -# Parameters -conf_name="${__object_id:?}" -if [ -f "${__object}/parameter/value" ] -then - conf_value=$(cat "${__object}/parameter/value") -fi - -if [ "${state_should}" = 'present' ] -then - set_command="ALTER SYSTEM SET ${conf_name} = ${conf_value}" -else - set_command="ALTER SYSTEM SET ${conf_name} = DEFAULT" -fi - -case $os -in - openbsd|devuan) - case $os - in - openbsd) - postgres_user='_postgresql' - restart_command='/etc/rc.d/postgresql restart' - ;; - devuan) - postgres_user='postgres' - restart_command='/etc/init.d/postgresql restart' - ;; - esac - # needs two separate psql commands because ALTER SYSTEM - # cannot run inside a transaction block - cat <<-EOF - su - ${postgres_user} -c "psql postgres -qwc \ - \"${set_command}\"" - su - ${postgres_user} -c "psql postgres -twAc \ - \"SELECT pg_reload_conf()\"" - EOF - # check success (makes only sense if setting to a non-default value) - # and restart server if needed - if [ "${state_should}" = 'present' ] +quote() { + for _arg + do + shift + if test -n "$(printf '%s' "${_arg}" | tr -d -c '\t\n \042-\047\050-\052\073-\077\133\\`|~' | tr -c '' '.')" then - cat <<-EOF - if [ \$(su - ${postgres_user} -c "psql postgres -twAc \"SHOW ${conf_name}\"") != '${conf_value}' ] - then - ${restart_command} - fi - EOF + # needs quoting + set -- "$@" "'$(printf '%s' "${_arg}" | sed -e "s/'/'\\\\''/g")'" + else + set -- "$@" "${_arg}" fi + done + unset _arg + + # NOTE: Use printf because POSIX echo interprets escape sequences + printf '%s' "$*" +} + +case ${os} +in + (openbsd) + postgres_user='_postgresql' + restart_command='/etc/rc.d/postgresql restart' ;; - *) + (devuan) + postgres_user='postgres' + restart_command='/etc/init.d/postgresql restart' + ;; + (*) echo "Unsupported OS: ${os}" >&2 exit 1 ;; esac + + +psql_cmd() { + printf 'su - %s -c %s\n' "$(quote "${postgres_user}")" "$(quote "$(quote psql "$@")")" +} + +case ${state_should} +in + (present) + test -s "${__object:?}/parameter/value" || { + echo 'Missing required parameter --value' >&2 + exit 1 + } + + cat <<-EOF + exec 3< "\${__object:?}/parameter/value" + $(psql_cmd postgres -tAw) <<'SQL' + \\set conf_value \`cat <&3\` + ALTER SYSTEM SET ${conf_name} = :'conf_value'; + SELECT pg_reload_conf(); + SQL + exec 3<&- + EOF + ;; + (absent) + psql_cmd postgres -qwc "ALTER SYSTEM SET ${conf_name} TO DEFAULT" + ;; + (*) + printf 'Invalid --state: %s\n' "${state_should}" >&2 + printf 'Only "present" and "absent" are acceptable.\n' >&2 + exit 1 + ;; +esac + +# check success (makes only sense if setting to a non-default value) +# and restart server if needed +if test "${state_should}" = 'present' +then + cat <<-EOF + + $(psql_cmd postgres -twAc "SHOW ${conf_name}") \\ + | cmp -s "\${__object:?}/parameter/value" - || { + ${restart_command} + } + EOF +fi From 803367b316f5c72c51153172a41b7a745f2d2d83 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Mon, 18 Jan 2021 19:29:42 +0100 Subject: [PATCH 06/21] [type/__postgres_conf] Fix default detection when default is also set in config file e.g. port is usually also set to the default value in postgresql.conf --- cdist/conf/type/__postgres_conf/explorer/state | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__postgres_conf/explorer/state b/cdist/conf/type/__postgres_conf/explorer/state index da904b56..400b27e8 100644 --- a/cdist/conf/type/__postgres_conf/explorer/state +++ b/cdist/conf/type/__postgres_conf/explorer/state @@ -42,7 +42,7 @@ if su - "${postgres_user}" -c "psql postgres -twAc 'SHOW ${conf_name}'" \ then echo present else - case $(su - "${postgres_user}" -c "psql postgres -tAwc \"SELECT source FROM pg_settings WHERE name = '${conf_name}'\"") + case $(su - "${postgres_user}" -c "psql postgres -tAwc \"SELECT CASE WHEN source = 'default' OR setting = boot_val THEN 'default' ELSE source END FROM pg_settings WHERE name = '${conf_name}'\"") in ('') # invalid configuration parameter From 891c98567e1d94577dc4f20d3ec9f73f4927fd24 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Mon, 18 Jan 2021 19:39:56 +0100 Subject: [PATCH 07/21] [type/__postgres_conf] Compare configuration parameter names case insensitively --- cdist/conf/type/__postgres_conf/explorer/context | 3 ++- cdist/conf/type/__postgres_conf/explorer/state | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__postgres_conf/explorer/context b/cdist/conf/type/__postgres_conf/explorer/context index 3a2fa504..def5f676 100644 --- a/cdist/conf/type/__postgres_conf/explorer/context +++ b/cdist/conf/type/__postgres_conf/explorer/context @@ -39,4 +39,5 @@ esac conf_name=${__object_id:?} -su - "${postgres_user}" -c "psql postgres -twAc \"SELECT context FROM pg_settings WHERE name = '${conf_name}'\"" +# NOTE: SHOW/SET are case-insentitive, so this command should also be. +su - "${postgres_user}" -c "psql postgres -twAc \"SELECT context FROM pg_settings WHERE lower(name) = lower('${conf_name}')\"" diff --git a/cdist/conf/type/__postgres_conf/explorer/state b/cdist/conf/type/__postgres_conf/explorer/state index 400b27e8..a4930296 100644 --- a/cdist/conf/type/__postgres_conf/explorer/state +++ b/cdist/conf/type/__postgres_conf/explorer/state @@ -42,7 +42,8 @@ if su - "${postgres_user}" -c "psql postgres -twAc 'SHOW ${conf_name}'" \ then echo present else - case $(su - "${postgres_user}" -c "psql postgres -tAwc \"SELECT CASE WHEN source = 'default' OR setting = boot_val THEN 'default' ELSE source END FROM pg_settings WHERE name = '${conf_name}'\"") + # NOTE: SHOW/SET are case-insentitive, so this command should also be. + case $(su - "${postgres_user}" -c "psql postgres -tAwc \"SELECT CASE WHEN source = 'default' OR setting = boot_val THEN 'default' ELSE source END FROM pg_settings WHERE lower(name) = lower('${conf_name}')\"") in ('') # invalid configuration parameter From 5051d4f40b7097f58431ce334f9ddf5b171dbc7f Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Tue, 19 Jan 2021 16:36:44 +0100 Subject: [PATCH 08/21] [type/__postgres_conf] Catch invalid values --- cdist/conf/type/__postgres_conf/gencode-remote | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__postgres_conf/gencode-remote b/cdist/conf/type/__postgres_conf/gencode-remote index 998b8582..cc9b4e99 100755 --- a/cdist/conf/type/__postgres_conf/gencode-remote +++ b/cdist/conf/type/__postgres_conf/gencode-remote @@ -80,7 +80,7 @@ in cat <<-EOF exec 3< "\${__object:?}/parameter/value" - $(psql_cmd postgres -tAw) <<'SQL' + $(psql_cmd postgres -tAw -v ON_ERROR_STOP=on) <<'SQL' \\set conf_value \`cat <&3\` ALTER SYSTEM SET ${conf_name} = :'conf_value'; SELECT pg_reload_conf(); From 0f2ff477381d67de27149a92744f873322e44fd7 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Tue, 19 Jan 2021 16:37:43 +0100 Subject: [PATCH 09/21] [type/__postgres_conf] Restart PostgreSQL server based on pending_restart column of pg_settings --- .../type/__postgres_conf/explorer/context | 43 ------------------- .../conf/type/__postgres_conf/gencode-remote | 16 +++---- 2 files changed, 6 insertions(+), 53 deletions(-) delete mode 100644 cdist/conf/type/__postgres_conf/explorer/context diff --git a/cdist/conf/type/__postgres_conf/explorer/context b/cdist/conf/type/__postgres_conf/explorer/context deleted file mode 100644 index def5f676..00000000 --- a/cdist/conf/type/__postgres_conf/explorer/context +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh -e -# -*- mode: sh; indent-tabs-mode: t -*- -# -# 2021 Dennis Camera (dennis.camera at ssrq-sds-fds.ch) -# -# This file is part of cdist. -# -# cdist is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# cdist is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with cdist. If not, see . -# -# Returns the "context" of the configuration setting. -# cf. also https://www.postgresql.org/docs/10/view-pg-settings.html - -os=$("${__explorer:?}/os") - -case ${os} -in - (openbsd) - postgres_user='_postgresql' - ;; - (devuan) - postgres_user='postgres' - ;; - (*) - echo "Unsupported OS: ${os}" >&2 - exit 1 - ;; -esac - -conf_name=${__object_id:?} - -# NOTE: SHOW/SET are case-insentitive, so this command should also be. -su - "${postgres_user}" -c "psql postgres -twAc \"SELECT context FROM pg_settings WHERE lower(name) = lower('${conf_name}')\"" diff --git a/cdist/conf/type/__postgres_conf/gencode-remote b/cdist/conf/type/__postgres_conf/gencode-remote index cc9b4e99..fa930cc4 100755 --- a/cdist/conf/type/__postgres_conf/gencode-remote +++ b/cdist/conf/type/__postgres_conf/gencode-remote @@ -98,15 +98,11 @@ in ;; esac -# check success (makes only sense if setting to a non-default value) -# and restart server if needed -if test "${state_should}" = 'present' -then - cat <<-EOF +# Restart PostgreSQL server if required to apply new configuration value +cat < Date: Tue, 19 Jan 2021 17:18:27 +0100 Subject: [PATCH 10/21] [type/__postgres_conf] Add support for more init systems to restart service --- .../conf/type/__postgres_conf/gencode-remote | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/cdist/conf/type/__postgres_conf/gencode-remote b/cdist/conf/type/__postgres_conf/gencode-remote index fa930cc4..15d5bb3e 100755 --- a/cdist/conf/type/__postgres_conf/gencode-remote +++ b/cdist/conf/type/__postgres_conf/gencode-remote @@ -53,11 +53,9 @@ case ${os} in (openbsd) postgres_user='_postgresql' - restart_command='/etc/rc.d/postgresql restart' ;; (devuan) postgres_user='postgres' - restart_command='/etc/init.d/postgresql restart' ;; (*) echo "Unsupported OS: ${os}" >&2 @@ -103,6 +101,37 @@ cat <&2 + exit 1 + esac + ;; + (*) + printf "Don't know how to restart services with your init (%s)\n" "${init}" >&2 + exit 1 + esac + ) fi EOF From 4967c7ebbb7e98af6aa2c7f8bc91511bcbbf9820 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Tue, 19 Jan 2021 17:20:27 +0100 Subject: [PATCH 11/21] [type/__postgres_conf] Silence psql output --- cdist/conf/type/__postgres_conf/gencode-remote | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__postgres_conf/gencode-remote b/cdist/conf/type/__postgres_conf/gencode-remote index 15d5bb3e..9b8227ee 100755 --- a/cdist/conf/type/__postgres_conf/gencode-remote +++ b/cdist/conf/type/__postgres_conf/gencode-remote @@ -78,7 +78,7 @@ in cat <<-EOF exec 3< "\${__object:?}/parameter/value" - $(psql_cmd postgres -tAw -v ON_ERROR_STOP=on) <<'SQL' + $(psql_cmd postgres -tAwq -o /dev/null -v ON_ERROR_STOP=on) <<'SQL' \\set conf_value \`cat <&3\` ALTER SYSTEM SET ${conf_name} = :'conf_value'; SELECT pg_reload_conf(); From f9ebb4333c85e41439635cb00a40c3e07d8a3683 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Tue, 19 Jan 2021 17:21:50 +0100 Subject: [PATCH 12/21] [type/__postgres_conf] Add NetBSD PostgreSQL UNIX user --- cdist/conf/type/__postgres_conf/gencode-remote | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cdist/conf/type/__postgres_conf/gencode-remote b/cdist/conf/type/__postgres_conf/gencode-remote index 9b8227ee..8f8a2bfe 100755 --- a/cdist/conf/type/__postgres_conf/gencode-remote +++ b/cdist/conf/type/__postgres_conf/gencode-remote @@ -51,15 +51,14 @@ quote() { case ${os} in + (netbsd) + postgres_user='pgsql' + ;; (openbsd) postgres_user='_postgresql' ;; - (devuan) - postgres_user='postgres' - ;; (*) - echo "Unsupported OS: ${os}" >&2 - exit 1 + postgres_user='postgres' ;; esac From 6b18cace759d1345cec6c2168c3bd8f238f23bca Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Thu, 21 Jan 2021 19:29:07 +0100 Subject: [PATCH 13/21] [type/__postgres_conf] Catch connection errors early --- cdist/conf/type/__postgres_conf/explorer/state | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cdist/conf/type/__postgres_conf/explorer/state b/cdist/conf/type/__postgres_conf/explorer/state index a4930296..589925de 100644 --- a/cdist/conf/type/__postgres_conf/explorer/state +++ b/cdist/conf/type/__postgres_conf/explorer/state @@ -37,6 +37,11 @@ esac conf_name=${__object_id:?} +su - "${postgres_user}" -c 'psql postgres -c "SELECT 1"' >/dev/null || { + echo 'Connection to PostgreSQL server failed' >&2 + exit 1 +} + if su - "${postgres_user}" -c "psql postgres -twAc 'SHOW ${conf_name}'" \ | cmp -s "${__object:?}/parameter/value" - then From 0835f414a5b2ce41309ee9b265cb80abb1362563 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Tue, 16 Feb 2021 16:03:23 +0100 Subject: [PATCH 14/21] [type/__postgres_conf] Extract PostgreSQL service user detection to separate explorer --- .../__postgres_conf/explorer/postgres_user | 64 +++++++++++++++++++ .../conf/type/__postgres_conf/explorer/state | 16 +---- .../conf/type/__postgres_conf/gencode-remote | 17 +---- 3 files changed, 67 insertions(+), 30 deletions(-) create mode 100644 cdist/conf/type/__postgres_conf/explorer/postgres_user diff --git a/cdist/conf/type/__postgres_conf/explorer/postgres_user b/cdist/conf/type/__postgres_conf/explorer/postgres_user new file mode 100644 index 00000000..c6582dc4 --- /dev/null +++ b/cdist/conf/type/__postgres_conf/explorer/postgres_user @@ -0,0 +1,64 @@ +#!/bin/sh -e +# -*- mode: sh; indent-tabs-mode: t -*- +# +# 2021 Dennis Camera (dennis.camera at ssrq-sds-fds.ch) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# + +os=$("${__explorer:?}/os") + +case ${os} +in + (alpine) + echo 'postgres' + ;; + (centos|rhel|scientific) + echo 'postgres' + ;; + (debian|devuan|ubuntu) + echo 'postgres' + ;; + (freebsd) + test -x /usr/local/etc/rc.d/postgresql || { + printf 'could not find postgresql rc script./n' >&2 + exit 1 + } + pg_status=$(/usr/local/etc/rc.d/postgresql onestatus) || { + printf 'postgresql daemon is not running.\n' >&2 + exit 1 + } + pg_pid=$(printf '%s\n' "${pg_status}" \ + | sed -n 's/^pg_ctl:.*(PID: *\([0-9]*\))$/\1/p') + + # PostgreSQL < 9.6: pgsql + # PostgreSQL >= 9.6: postgres + ps -o user -p "${pg_pid}" | sed -n '2p' + ;; + (netbsd) + echo 'pgsql' + ;; + (openbsd) + echo '_postgresql' + ;; + (suse) + echo 'postgres' + ;; + (*) + echo "Unsupported OS: ${os}" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__postgres_conf/explorer/state b/cdist/conf/type/__postgres_conf/explorer/state index 589925de..de6e8aa0 100644 --- a/cdist/conf/type/__postgres_conf/explorer/state +++ b/cdist/conf/type/__postgres_conf/explorer/state @@ -19,21 +19,7 @@ # along with cdist. If not, see . # -os=$("${__explorer:?}/os") - -case ${os} -in - (openbsd) - postgres_user='_postgresql' - ;; - (devuan) - postgres_user='postgres' - ;; - (*) - echo "Unsupported OS: ${os}" >&2 - exit 1 - ;; -esac +postgres_user=$("${__type_explorer:?}/postgres_user") conf_name=${__object_id:?} diff --git a/cdist/conf/type/__postgres_conf/gencode-remote b/cdist/conf/type/__postgres_conf/gencode-remote index 8f8a2bfe..d0d247b4 100755 --- a/cdist/conf/type/__postgres_conf/gencode-remote +++ b/cdist/conf/type/__postgres_conf/gencode-remote @@ -20,9 +20,9 @@ # along with cdist. If not, see . # -os=$(cat "${__global:?}/explorer/os") state_is=$(cat "${__object:?}/explorer/state") state_should=$(cat "${__object:?}/parameter/state") +postgres_user=$(cat "${__object:?}/explorer/postgres_user") conf_name=${__object_id:?} @@ -49,19 +49,6 @@ quote() { printf '%s' "$*" } -case ${os} -in - (netbsd) - postgres_user='pgsql' - ;; - (openbsd) - postgres_user='_postgresql' - ;; - (*) - postgres_user='postgres' - ;; -esac - psql_cmd() { printf 'su - %s -c %s\n' "$(quote "${postgres_user}")" "$(quote "$(quote psql "$@")")" @@ -117,7 +104,7 @@ then case $(cat "${__global:?}/explorer/kernel_name") in (FreeBSD) - echo 'service postgresql restart' + echo '/usr/local/etc/rc.d/postgresql restart' ;; (OpenBSD|NetBSD) echo '/etc/rc.d/postgresql restart' From 92b8942a8c37bb985ef42991f3b7aaef0cd8073f Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Thu, 15 Apr 2021 09:00:32 +0200 Subject: [PATCH 15/21] [type/__postgres_conf] Add psql_exec function to state explorer --- cdist/conf/type/__postgres_conf/explorer/state | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cdist/conf/type/__postgres_conf/explorer/state b/cdist/conf/type/__postgres_conf/explorer/state index de6e8aa0..1a58751a 100644 --- a/cdist/conf/type/__postgres_conf/explorer/state +++ b/cdist/conf/type/__postgres_conf/explorer/state @@ -20,21 +20,24 @@ # postgres_user=$("${__type_explorer:?}/postgres_user") - conf_name=${__object_id:?} -su - "${postgres_user}" -c 'psql postgres -c "SELECT 1"' >/dev/null || { +quote() { printf '%s\n' "$*" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/'/"; } +psql_exec() { + su - "${postgres_user}" -c "psql postgres -twAc $(quote "$*")" +} + +psql_exec 'SELECT 1' >/dev/null || { echo 'Connection to PostgreSQL server failed' >&2 exit 1 } -if su - "${postgres_user}" -c "psql postgres -twAc 'SHOW ${conf_name}'" \ - | cmp -s "${__object:?}/parameter/value" - +if psql_exec "SHOW ${conf_name}" | cmp -s "${__object:?}/parameter/value" - then echo present else # NOTE: SHOW/SET are case-insentitive, so this command should also be. - case $(su - "${postgres_user}" -c "psql postgres -tAwc \"SELECT CASE WHEN source = 'default' OR setting = boot_val THEN 'default' ELSE source END FROM pg_settings WHERE lower(name) = lower('${conf_name}')\"") + case $(psql_exec "SELECT CASE WHEN source = 'default' OR setting = boot_val THEN 'default' ELSE source END FROM pg_settings WHERE lower(name) = lower('${conf_name}')") in ('') # invalid configuration parameter From 2ccc03fef1e28c759a7918fa00ffcb45c76dc57a Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Thu, 15 Apr 2021 09:02:40 +0200 Subject: [PATCH 16/21] [type/__postgres_conf] Add psql_conf_cmp function to state explorer --- cdist/conf/type/__postgres_conf/explorer/state | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cdist/conf/type/__postgres_conf/explorer/state b/cdist/conf/type/__postgres_conf/explorer/state index 1a58751a..be881be6 100644 --- a/cdist/conf/type/__postgres_conf/explorer/state +++ b/cdist/conf/type/__postgres_conf/explorer/state @@ -27,12 +27,16 @@ psql_exec() { su - "${postgres_user}" -c "psql postgres -twAc $(quote "$*")" } +psql_conf_cmp() { + test "$(psql_exec "SHOW $1")" = "$2" +} + psql_exec 'SELECT 1' >/dev/null || { echo 'Connection to PostgreSQL server failed' >&2 exit 1 } -if psql_exec "SHOW ${conf_name}" | cmp -s "${__object:?}/parameter/value" - +if psql_conf_cmp "${conf_name}" "$(cat "${__object:?}/parameter/value")" then echo present else From e0416403c4862cb8bc0f41a7c6f8a33d1a8656a5 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Thu, 15 Apr 2021 09:04:07 +0200 Subject: [PATCH 17/21] [type/__postgres_conf] Add psql_conf_source function to state explorer --- cdist/conf/type/__postgres_conf/explorer/state | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cdist/conf/type/__postgres_conf/explorer/state b/cdist/conf/type/__postgres_conf/explorer/state index be881be6..9f54724a 100644 --- a/cdist/conf/type/__postgres_conf/explorer/state +++ b/cdist/conf/type/__postgres_conf/explorer/state @@ -27,6 +27,10 @@ psql_exec() { su - "${postgres_user}" -c "psql postgres -twAc $(quote "$*")" } +psql_conf_source() { + # NOTE: SHOW/SET are case-insentitive, so this command should also be. + psql_exec "SELECT CASE WHEN source = 'default' OR setting = boot_val THEN 'default' ELSE source END FROM pg_settings WHERE lower(name) = lower('$1')" +} psql_conf_cmp() { test "$(psql_exec "SHOW $1")" = "$2" } @@ -40,8 +44,7 @@ if psql_conf_cmp "${conf_name}" "$(cat "${__object:?}/parameter/value")" then echo present else - # NOTE: SHOW/SET are case-insentitive, so this command should also be. - case $(psql_exec "SELECT CASE WHEN source = 'default' OR setting = boot_val THEN 'default' ELSE source END FROM pg_settings WHERE lower(name) = lower('${conf_name}')") + case $(psql_conf_source "${conf_name}") in ('') # invalid configuration parameter From 12c2995494ce582cb3adf1d942b36f6df035370a Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Thu, 15 Apr 2021 14:46:36 +0200 Subject: [PATCH 18/21] [type/__postgres_conf] Implement complex state compare logic --- .../conf/type/__postgres_conf/explorer/state | 166 +++++++++++++++++- 1 file changed, 163 insertions(+), 3 deletions(-) diff --git a/cdist/conf/type/__postgres_conf/explorer/state b/cdist/conf/type/__postgres_conf/explorer/state index 9f54724a..e76540c5 100644 --- a/cdist/conf/type/__postgres_conf/explorer/state +++ b/cdist/conf/type/__postgres_conf/explorer/state @@ -22,6 +22,52 @@ postgres_user=$("${__type_explorer:?}/postgres_user") conf_name=${__object_id:?} +tolower() { printf '%s' "$*" | tr '[:upper:]' '[:lower:]'; } + +tobytes() { + # NOTE: This function treats everything as base 2. + # It is not compatible with SI units. + awk 'BEGIN { FS = "\n" } + /TB$/ { $0 = ($0 * 1024) "GB" } + /GB$/ { $0 = ($0 * 1024) "MB" } + /MB$/ { $0 = ($0 * 1024) "kB" } + /kB$/ { $0 = ($0 * 1024) "B" } + /B?$/ { sub(/ *B?$/, "") } + ($0*1) == $0 # is number + ' <<-EOF + $1 + EOF +} + +tomillisecs() { + awk 'BEGIN { FS = "\n" } + /d$/ { $0 = ($0 * 24) "h" } + /h$/ { $0 = ($0 * 60) "min" } + /min$/ { $0 = ($0 * 60) "s" } + /[^m]s$/ { $0 = ($0 * 1000) "ms" } + /ms$/ { $0 *= 1 } + ($0*1) == $0 # is number + ' <<-EOF + $1 + EOF +} + +tobool() { + # prints either 'on' or 'off' + case $(tolower "$1") + in + (t|true|y|yes|on|1) + echo 'on' ;; + (f|false|n|no|off|0) + echo 'off' ;; + (*) + printf 'Inavlid bool value: %s\n' "$2" >&2 + return 1 + ;; + esac + return 0 +} + quote() { printf '%s\n' "$*" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/'/"; } psql_exec() { su - "${postgres_user}" -c "psql postgres -twAc $(quote "$*")" @@ -31,9 +77,123 @@ psql_conf_source() { # NOTE: SHOW/SET are case-insentitive, so this command should also be. psql_exec "SELECT CASE WHEN source = 'default' OR setting = boot_val THEN 'default' ELSE source END FROM pg_settings WHERE lower(name) = lower('$1')" } -psql_conf_cmp() { - test "$(psql_exec "SHOW $1")" = "$2" -} +psql_conf_cmp() ( + IFS='|' read -r lower_name vartype setting unit <<-EOF + $(psql_exec "SELECT lower(name), vartype, setting, unit FROM pg_settings WHERE lower(name) = lower('$1')") + EOF + + should_value=$2 + is_value=${setting} + + # The following case contains special cases for special settings. + case ${lower_name} + in + (archive_command) + if test "${setting}" = '(disabled)' + then + # DAFUQ PostgreSQL?! + # PostgreSQL returns (disabled) if the feature is inactive. + # We cannot compare the values unless it is enabled, first. + return 0 + fi + ;; + (archive_mode|backslash_quote|constraint_exclusion|force_parallel_mode|huge_pages|synchronous_commit) + # Although only 'on', 'off' are documented, PostgreSQL accepts all + # the "likely" variants of "on" and "off". + case $(tolower "${should_value}") + in + (on|off|true|false|yes|no|1|0) + should_value=$(tobool "${should_value}") + ;; + esac + ;; + esac + + case ${vartype} + in + (bool) + test -z "${unit}" || { + # please fix the explorer if this error occurs. + printf 'units are not supported for vartype: %s\n' "${vartype}" >&2 + exit 1 + } + + should_value=$(tobool "${should_value}") + + test "${is_value}" = "${should_value}" + ;; + (enum) + test -z "${unit}" || { + # please fix the explorer if this error occurs. + printf 'units are not supported with vartype: %s\n' "${vartype}" >&2 + exit 1 + } + + # NOTE: All enums that are currently defined are lower case, but + # PostgreSQL also accepts upper case spelling. + should_value=$(tolower "$2") + + test "${is_value}" = "${should_value}" + ;; + (integer) + # split multiples from unit, first (e.g. 8kB -> 8, kB) + case ${unit} + in + ([0-9]*) + multiple=${unit%%[!0-9]*} + unit=${unit##*[0-9 ]} + ;; + (*) multiple=1 ;; + esac + + is_value=$((setting * multiple))${unit} + + if expr "${should_value}" : '-\{0,1\}[0-9]*$' >/dev/null + then + # default unit + should_value=$((should_value * multiple))${unit} + fi + + # then, do conversion + # NOTE: these conversions work for integers only! + case ${unit} + in + (B|[kMGT]B) + # bytes + is_bytes=$(tobytes "${is_value}") + should_bytes=$(tobytes "${should_value}") + + test $((is_bytes)) -eq $((should_bytes)) + ;; + (ms|s|min|h|d) + # seconds + is_ms=$(tomillisecs "${is_value}") + should_ms=$(tomillisecs "${should_value}") + + test $((is_ms)) -eq $((should_ms)) + ;; + ('') + # no unit + is_int=${is_value} + should_int=${should_value} + + test $((is_int)) -eq $((should_int)) + ;; + esac + ;; + (real|string) + # NOTE: reals could possibly have units, but currently there none. + + test -z "${unit}" || { + # please fix the explorer if this error occurs. + printf 'units are not supported with vartype: %s\n' "${vartype}" >&2 + exit 1 + } + + test "${is_value}" = "${should_value}" + ;; + esac +) psql_exec 'SELECT 1' >/dev/null || { echo 'Connection to PostgreSQL server failed' >&2 From bef1433ba3adb022f8b50eb9df0fbbbf90757d76 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Thu, 15 Apr 2021 14:46:50 +0200 Subject: [PATCH 19/21] [type/__postgres_conf] Accept empty values --- cdist/conf/type/__postgres_conf/gencode-remote | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__postgres_conf/gencode-remote b/cdist/conf/type/__postgres_conf/gencode-remote index d0d247b4..27651600 100755 --- a/cdist/conf/type/__postgres_conf/gencode-remote +++ b/cdist/conf/type/__postgres_conf/gencode-remote @@ -57,7 +57,7 @@ psql_cmd() { case ${state_should} in (present) - test -s "${__object:?}/parameter/value" || { + test -n "${__object:?}/parameter/value" || { echo 'Missing required parameter --value' >&2 exit 1 } From 686e4f0f2d498ee39a69e43f7535171f16f5fcbc Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Thu, 15 Apr 2021 15:01:38 +0200 Subject: [PATCH 20/21] [type/__postgres_conf] Reverse state logic (decide based on source first) --- .../conf/type/__postgres_conf/explorer/state | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/cdist/conf/type/__postgres_conf/explorer/state b/cdist/conf/type/__postgres_conf/explorer/state index e76540c5..4b7b0a43 100644 --- a/cdist/conf/type/__postgres_conf/explorer/state +++ b/cdist/conf/type/__postgres_conf/explorer/state @@ -200,23 +200,24 @@ psql_exec 'SELECT 1' >/dev/null || { exit 1 } -if psql_conf_cmp "${conf_name}" "$(cat "${__object:?}/parameter/value")" -then - echo present -else - case $(psql_conf_source "${conf_name}") - in - ('') - # invalid configuration parameter - # (error message was already printed by SHOW command above. - # Yes, it's a hack) - exit 1 - ;; - (default) - echo absent - ;; - (*) +case $(psql_conf_source "${conf_name}") +in + ('') + printf 'Invalid configuration parameter: %s\n' "${conf_name}" >&2 + exit 1 + ;; + (default) + echo absent + ;; + (*) + if ! test -f "${__object:?}/parameter/value" + then + echo present + elif psql_conf_cmp "${conf_name}" "$(cat "${__object:?}/parameter/value")" + then + echo present + else echo different - ;; - esac -fi + fi + ;; +esac From 19bf37be1a8b0b099a7199d1565b74598010f614 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Thu, 15 Apr 2021 15:55:52 +0200 Subject: [PATCH 21/21] [type/__postgres_conf] Update man.rst --- cdist/conf/type/__postgres_conf/man.rst | 39 ++++++++++++++----------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/cdist/conf/type/__postgres_conf/man.rst b/cdist/conf/type/__postgres_conf/man.rst index 76016c6c..e035f080 100644 --- a/cdist/conf/type/__postgres_conf/man.rst +++ b/cdist/conf/type/__postgres_conf/man.rst @@ -1,29 +1,27 @@ cdist-type__postgres_conf(7) ============================ -Configure a PostgreSQL server. - -NOTE: This type might need to be run multiple times to apply all bits of the -configuration due to ordering requirements. - -SSRQ +NAME +---- +cdist-type__postgres_conf - Alter PostgreSQL configuration DESCRIPTION ----------- -Configure a PostgreSQL server using ALTER SYSTEM. +Configure a running PostgreSQL server using ``ALTER SYSTEM``. REQUIRED PARAMETERS ------------------- value - The value to setup (can be omitted when state is set to "absent"). + The value to set (can be omitted if ``--state`` is set to ``absent``). OPTIONAL PARAMETERS ------------------- state - "present" or "absent". Defaults to "present". + ``present`` or ``absent``. + Defaults to ``present``. BOOLEAN PARAMETERS @@ -36,20 +34,27 @@ EXAMPLES .. code-block:: sh - # set timezone - __postgres_conf timezone --value Europe/Zurich + # set timezone + __postgres_conf timezone --value Europe/Zurich - # reset maximum number of concurrent connections to default (normally 100) - __postgres_conf max_connections --state absent + # reset maximum number of concurrent connections to default (normally 100) + __postgres_conf max_connections --state absent SEE ALSO -------- -- `cdist-type(7) `_ +None. + + +AUTHORS +------- +Beni Ruef (bernhard.ruef--@--ssrq-sds-fds.ch) +Dennis Camera (dennis.camera--@--ssrq-sds-fds.ch) COPYING ------- -Copyright \(C) 2020 SSRQ (www.ssrq-sds-fds.ch). -Free use of this software is granted under the terms -of the GNU General Public License version 3 (GPLv3). +Copyright \(C) 2019-2021 SSRQ (www.ssrq-sds-fds.ch). +You can redistribute it and/or modify it under the terms of the GNU General +Public License as published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version.