services: postgresql: Add port to configuration

* gnu/services/databases.scm (<postgresql-configuration>): Add port
  field.
  (postgresql-shepherd-service): Pass port to postgres.
  (postgresql-service): Add port default.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
Christopher Baines 2016-12-14 08:35:48 +00:00 committed by Ludovic Courtès
parent eee7878f4e
commit 2d3d5cc5ea
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
2 changed files with 11 additions and 5 deletions

View File

@ -10166,13 +10166,14 @@ Users need to be in the @code{lp} group to access the D-Bus service.
The @code{(gnu services databases)} module provides the following services. The @code{(gnu services databases)} module provides the following services.
@deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @ @deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @
[#:config-file] [#:data-directory ``/var/lib/postgresql/data''] [#:config-file] [#:data-directory ``/var/lib/postgresql/data''] @
[#:port 5432]
Return a service that runs @var{postgresql}, the PostgreSQL database Return a service that runs @var{postgresql}, the PostgreSQL database
server. server.
The PostgreSQL daemon loads its runtime configuration from The PostgreSQL daemon loads its runtime configuration from
@var{config-file} and stores the database cluster in @var{config-file}, stores the database cluster in @var{data-directory} and
@var{data-directory}. listens on @var{port}.
@end deffn @end deffn
@deffn {Scheme Procedure} mysql-service [#:config (mysql-configuration)] @deffn {Scheme Procedure} mysql-service [#:config (mysql-configuration)]

View File

@ -48,6 +48,8 @@
postgresql-configuration? postgresql-configuration?
(postgresql postgresql-configuration-postgresql ;<package> (postgresql postgresql-configuration-postgresql ;<package>
(default postgresql)) (default postgresql))
(port postgresql-configuration-port
(default 5432))
(config-file postgresql-configuration-file) (config-file postgresql-configuration-file)
(data-directory postgresql-configuration-data-directory)) (data-directory postgresql-configuration-data-directory))
@ -80,7 +82,7 @@ host all all ::1/128 trust"))
(define postgresql-activation (define postgresql-activation
(match-lambda (match-lambda
(($ <postgresql-configuration> postgresql config-file data-directory) (($ <postgresql-configuration> postgresql port config-file data-directory)
#~(begin #~(begin
(use-modules (guix build utils) (use-modules (guix build utils)
(ice-9 match)) (ice-9 match))
@ -108,7 +110,7 @@ host all all ::1/128 trust"))
(define postgresql-shepherd-service (define postgresql-shepherd-service
(match-lambda (match-lambda
(($ <postgresql-configuration> postgresql config-file data-directory) (($ <postgresql-configuration> postgresql port config-file data-directory)
(let ((start-script (let ((start-script
;; Wrapper script that switches to the 'postgres' user before ;; Wrapper script that switches to the 'postgres' user before
;; launching daemon. ;; launching daemon.
@ -121,6 +123,7 @@ host all all ::1/128 trust"))
(system* postgres (system* postgres
(string-append "--config-file=" (string-append "--config-file="
#$config-file) #$config-file)
"-p" (number->string #$port)
"-D" #$data-directory))))) "-D" #$data-directory)))))
(list (shepherd-service (list (shepherd-service
(provision '(postgres)) (provision '(postgres))
@ -140,6 +143,7 @@ host all all ::1/128 trust"))
(const %postgresql-accounts)))))) (const %postgresql-accounts))))))
(define* (postgresql-service #:key (postgresql postgresql) (define* (postgresql-service #:key (postgresql postgresql)
(port 5432)
(config-file %default-postgres-config) (config-file %default-postgres-config)
(data-directory "/var/lib/postgresql/data")) (data-directory "/var/lib/postgresql/data"))
"Return a service that runs @var{postgresql}, the PostgreSQL database server. "Return a service that runs @var{postgresql}, the PostgreSQL database server.
@ -149,6 +153,7 @@ and stores the database cluster in @var{data-directory}."
(service postgresql-service-type (service postgresql-service-type
(postgresql-configuration (postgresql-configuration
(postgresql postgresql) (postgresql postgresql)
(port port)
(config-file config-file) (config-file config-file)
(data-directory data-directory)))) (data-directory data-directory))))