From 6c0679215f4ffa534c1eb2e8c8a6e043a0c993fe Mon Sep 17 00:00:00 2001 From: Mathieu Othacehe Date: Mon, 18 Jan 2021 10:35:29 +0100 Subject: services: postgresql: Add socket directory support. * gnu/services/databases.scm (postgresql-config-file-socket-directory): New procedure. ()[socket-directory]: New field. (postgresql-config-file-compiler): Honor it. (postgresql-activation): Create the socket directory if needed. * doc/guix.texi (Database Services): Document it. * gnu/tests/guix.scm (%guix-data-service-os): Adapt it. * gnu/tests/monitoring.scm (%zabbix-os): Ditto. * gnu/tests/web.scm (patchwork-os): Ditto. Signed-off-by: Mathieu Othacehe --- gnu/services/databases.scm | 32 +++++++++++++++++++++++--------- gnu/tests/guix.scm | 5 ++++- gnu/tests/monitoring.scm | 7 ++++++- gnu/tests/web.scm | 7 ++++++- 4 files changed, 39 insertions(+), 12 deletions(-) (limited to 'gnu') diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm index bb0e40632e..83dee52cf3 100644 --- a/gnu/services/databases.scm +++ b/gnu/services/databases.scm @@ -43,6 +43,7 @@ (define-module (gnu services databases) postgresql-config-file-log-destination postgresql-config-file-hba-file postgresql-config-file-ident-file + postgresql-config-file-socket-directory postgresql-config-file-extra-config postgresql-configuration @@ -101,20 +102,23 @@ (define %default-postgres-ident (define-record-type* postgresql-config-file make-postgresql-config-file postgresql-config-file? - (log-destination postgresql-config-file-log-destination - (default "syslog")) - (hba-file postgresql-config-file-hba-file - (default %default-postgres-hba)) - (ident-file postgresql-config-file-ident-file - (default %default-postgres-ident)) - (extra-config postgresql-config-file-extra-config - (default '()))) + (log-destination postgresql-config-file-log-destination + (default "syslog")) + (hba-file postgresql-config-file-hba-file + (default %default-postgres-hba)) + (ident-file postgresql-config-file-ident-file + (default %default-postgres-ident)) + (socket-directory postgresql-config-file-socket-directory + (default "/var/run/postgresql")) + (extra-config postgresql-config-file-extra-config + (default '()))) (define-gexp-compiler (postgresql-config-file-compiler (file ) system target) (match file (($ log-destination hba-file - ident-file extra-config) + ident-file socket-directory + extra-config) ;; See: https://www.postgresql.org/docs/current/config-setting.html. (define (format-value value) (cond @@ -136,6 +140,9 @@ (define contents `(("log_destination" ,log-destination) ("hba_file" ,hba-file) ("ident_file" ,ident-file) + ,@(if socket-directory + `(("unix_socket_directories" ,socket-directory)) + '()) ,@extra-config))) (gexp->derivation @@ -211,6 +218,13 @@ (define postgresql-activation (mkdir-p #$data-directory) (chown #$data-directory (passwd:uid user) (passwd:gid user)) + ;; Create the socket directory. + (let ((socket-directory + #$(postgresql-config-file-socket-directory config-file))) + (when (string? socket-directory) + (mkdir-p socket-directory) + (chown socket-directory (passwd:uid user) (passwd:gid user)))) + ;; Drop privileges and init state directory in a new ;; process. Wait for it to finish before proceeding. (match (primitive-fork) diff --git a/gnu/tests/guix.scm b/gnu/tests/guix.scm index af7d8f0b21..219b8b482f 100644 --- a/gnu/tests/guix.scm +++ b/gnu/tests/guix.scm @@ -164,7 +164,10 @@ (define %guix-data-service-os " local all all trust host all all 127.0.0.1/32 trust -host all all ::1/128 trust")))))) +host all all ::1/128 trust")) + ;; XXX: Remove when postgresql default socket directory is + ;; changed to /var/run/postgresql. + (socket-directory #f))))) (service guix-data-service-type (guix-data-service-configuration (host "0.0.0.0"))) diff --git a/gnu/tests/monitoring.scm b/gnu/tests/monitoring.scm index 7371b02fe1..c21bb1e63d 100644 --- a/gnu/tests/monitoring.scm +++ b/gnu/tests/monitoring.scm @@ -309,7 +309,12 @@ (define %zabbix-os (service dhcp-client-service-type) (service postgresql-service-type (postgresql-configuration - (postgresql postgresql-10))) + (postgresql postgresql-10) + ;; XXX: Remove when postgresql default socket directory is + ;; changed to /var/run/postgresql. + (config-file + (postgresql-config-file + (socket-directory #f))))) (service zabbix-front-end-service-type (zabbix-front-end-configuration (db-password "zabbix"))) diff --git a/gnu/tests/web.scm b/gnu/tests/web.scm index 7f4518acd2..cc0e79c8b2 100644 --- a/gnu/tests/web.scm +++ b/gnu/tests/web.scm @@ -569,7 +569,12 @@ (define (patchwork-os patchwork) (listen '("8080")))))) (service postgresql-service-type (postgresql-configuration - (postgresql postgresql-10))) + (postgresql postgresql-10) + ;; XXX: Remove when postgresql default socket directory is + ;; changed to /var/run/postgresql. + (config-file + (postgresql-config-file + (socket-directory #f))))) (service patchwork-service-type (patchwork-configuration (patchwork patchwork) -- cgit v1.2.3