Skip to content
Snippets Groups Projects
Unverified Commit 6c067921 authored by Mathieu Othacehe's avatar Mathieu Othacehe
Browse files

services: postgresql: Add socket directory support.


* gnu/services/databases.scm (postgresql-config-file-socket-directory): New
procedure.
(<postgresql-config-file>)[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: default avatarMathieu Othacehe <othacehe@gnu.org>
parent a38d0b01
No related branches found
No related tags found
No related merge requests found
...@@ -19430,6 +19430,12 @@ configuration. ...@@ -19430,6 +19430,12 @@ configuration.
@item @code{ident-file} (default: @code{%default-postgres-ident}) @item @code{ident-file} (default: @code{%default-postgres-ident})
Filename or G-expression for the user name mapping configuration. Filename or G-expression for the user name mapping configuration.
   
@item @code{socket-directory} (default: @code{"/var/lib/postgresql"})
Specifies the directory of the Unix-domain socket(s) on which PostgreSQL
is to listen for connections from client applications. If set to
@code{#false} PostgreSQL does not listen on any Unix-domain sockets, in
which case only TCP/IP sockets can be used to connect to the server.
@item @code{extra-config} (default: @code{'()}) @item @code{extra-config} (default: @code{'()})
List of additional keys and values to include in the PostgreSQL config List of additional keys and values to include in the PostgreSQL config
file. Each entry in the list should be a list where the first element file. Each entry in the list should be a list where the first element
...@@ -43,6 +43,7 @@ (define-module (gnu services databases) ...@@ -43,6 +43,7 @@ (define-module (gnu services databases)
postgresql-config-file-log-destination postgresql-config-file-log-destination
postgresql-config-file-hba-file postgresql-config-file-hba-file
postgresql-config-file-ident-file postgresql-config-file-ident-file
postgresql-config-file-socket-directory
postgresql-config-file-extra-config postgresql-config-file-extra-config
postgresql-configuration postgresql-configuration
...@@ -101,20 +102,23 @@ (define %default-postgres-ident ...@@ -101,20 +102,23 @@ (define %default-postgres-ident
(define-record-type* <postgresql-config-file> (define-record-type* <postgresql-config-file>
postgresql-config-file make-postgresql-config-file postgresql-config-file make-postgresql-config-file
postgresql-config-file? postgresql-config-file?
(log-destination postgresql-config-file-log-destination (log-destination postgresql-config-file-log-destination
(default "syslog")) (default "syslog"))
(hba-file postgresql-config-file-hba-file (hba-file postgresql-config-file-hba-file
(default %default-postgres-hba)) (default %default-postgres-hba))
(ident-file postgresql-config-file-ident-file (ident-file postgresql-config-file-ident-file
(default %default-postgres-ident)) (default %default-postgres-ident))
(extra-config postgresql-config-file-extra-config (socket-directory postgresql-config-file-socket-directory
(default '()))) (default "/var/run/postgresql"))
(extra-config postgresql-config-file-extra-config
(default '())))
(define-gexp-compiler (postgresql-config-file-compiler (define-gexp-compiler (postgresql-config-file-compiler
(file <postgresql-config-file>) system target) (file <postgresql-config-file>) system target)
(match file (match file
(($ <postgresql-config-file> log-destination hba-file (($ <postgresql-config-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. ;; See: https://www.postgresql.org/docs/current/config-setting.html.
(define (format-value value) (define (format-value value)
(cond (cond
...@@ -136,6 +140,9 @@ (define contents ...@@ -136,6 +140,9 @@ (define contents
`(("log_destination" ,log-destination) `(("log_destination" ,log-destination)
("hba_file" ,hba-file) ("hba_file" ,hba-file)
("ident_file" ,ident-file) ("ident_file" ,ident-file)
,@(if socket-directory
`(("unix_socket_directories" ,socket-directory))
'())
,@extra-config))) ,@extra-config)))
(gexp->derivation (gexp->derivation
...@@ -211,6 +218,13 @@ (define postgresql-activation ...@@ -211,6 +218,13 @@ (define postgresql-activation
(mkdir-p #$data-directory) (mkdir-p #$data-directory)
(chown #$data-directory (passwd:uid user) (passwd:gid user)) (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 ;; Drop privileges and init state directory in a new
;; process. Wait for it to finish before proceeding. ;; process. Wait for it to finish before proceeding.
(match (primitive-fork) (match (primitive-fork)
......
...@@ -164,7 +164,10 @@ (define %guix-data-service-os ...@@ -164,7 +164,10 @@ (define %guix-data-service-os
" "
local all all trust local all all trust
host all all 127.0.0.1/32 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 (service guix-data-service-type
(guix-data-service-configuration (guix-data-service-configuration
(host "0.0.0.0"))) (host "0.0.0.0")))
......
...@@ -309,7 +309,12 @@ (define %zabbix-os ...@@ -309,7 +309,12 @@ (define %zabbix-os
(service dhcp-client-service-type) (service dhcp-client-service-type)
(service postgresql-service-type (service postgresql-service-type
(postgresql-configuration (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 (service zabbix-front-end-service-type
(zabbix-front-end-configuration (zabbix-front-end-configuration
(db-password "zabbix"))) (db-password "zabbix")))
......
...@@ -569,7 +569,12 @@ (define (patchwork-os patchwork) ...@@ -569,7 +569,12 @@ (define (patchwork-os patchwork)
(listen '("8080")))))) (listen '("8080"))))))
(service postgresql-service-type (service postgresql-service-type
(postgresql-configuration (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 (service patchwork-service-type
(patchwork-configuration (patchwork-configuration
(patchwork patchwork) (patchwork patchwork)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment