Patchwork [1/2] services: postgresql: Add port to configuration

login
register
mail settings
Submitter Christopher Baines
Date Dec. 11, 2016, 9:13 p.m.
Message ID <20161211211301.28403-1-mail@cbaines.net>
Download mbox | patch
Permalink /patch/18376/
State New
Headers show

Comments

Christopher Baines - Dec. 11, 2016, 9:13 p.m.
* gnu/services/postgresql.scm (<postgresql-configuration>): Add port
  field.
  (postgresql-shepherd-service): Pass port to postgres.
  (postgresql-service): Add port default.
---
 gnu/services/databases.scm | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)
Ludovic Courtès - Dec. 11, 2016, 11:02 p.m.
Hi!

Christopher Baines <mail@cbaines.net> skribis:

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

[...]

> --- a/gnu/services/databases.scm
> +++ b/gnu/services/databases.scm
> @@ -48,6 +48,8 @@
>    postgresql-configuration?
>    (postgresql     postgresql-configuration-postgresql ;<package>
>                    (default postgresql))
> +  (port           postgresql-configuration-port
> +                  (default 5432))

Could you update guix.texi to reflect these changes?

> +    (($ <postgresql-configuration> postgresql port config-file data-directory)
> +     (let* ((string-port (number->string port))
> +            (start-script
> +             ;; Wrapper script that switches to the 'postgres' user before
> +             ;; launching daemon.
> +             (program-file "start-postgres"
> +                           #~(let ((user (getpwnam "postgres"))
> +                                   (postgres (string-append #$postgresql
> +                                                            "/bin/postgres")))
> +                               (setgid (passwd:gid user))
> +                               (setuid (passwd:uid user))
> +                               (system* postgres
> +                                        (string-append "--config-file="
> +                                                       #$config-file)
> +                                        "-p" #$string-port

I think you can omit the ‘string-port’ variable (confusing name IMO :-))
and directly write:

  "-p" #$(number->string port)

Could you send an updated patch?

Thanks!

Ludo’.

Patch

diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm
index 1eed85542..3850ba502 100644
--- a/gnu/services/databases.scm
+++ b/gnu/services/databases.scm
@@ -48,6 +48,8 @@ 
   postgresql-configuration?
   (postgresql     postgresql-configuration-postgresql ;<package>
                   (default postgresql))
+  (port           postgresql-configuration-port
+                  (default 5432))
   (config-file    postgresql-configuration-file)
   (data-directory postgresql-configuration-data-directory))
 
@@ -80,7 +82,7 @@  host	all	all	::1/128 	trust"))
 
 (define postgresql-activation
   (match-lambda
-    (($ <postgresql-configuration> postgresql config-file data-directory)
+    (($ <postgresql-configuration> postgresql port config-file data-directory)
      #~(begin
          (use-modules (guix build utils)
                       (ice-9 match))
@@ -108,20 +110,22 @@  host	all	all	::1/128 	trust"))
 
 (define postgresql-shepherd-service
   (match-lambda
-    (($ <postgresql-configuration> postgresql config-file data-directory)
-     (let ((start-script
-            ;; Wrapper script that switches to the 'postgres' user before
-            ;; launching daemon.
-            (program-file "start-postgres"
-                          #~(let ((user (getpwnam "postgres"))
-                                  (postgres (string-append #$postgresql
-                                                           "/bin/postgres")))
-                              (setgid (passwd:gid user))
-                              (setuid (passwd:uid user))
-                              (system* postgres
-                                       (string-append "--config-file="
-                                                      #$config-file)
-                                       "-D" #$data-directory)))))
+    (($ <postgresql-configuration> postgresql port config-file data-directory)
+     (let* ((string-port (number->string port))
+            (start-script
+             ;; Wrapper script that switches to the 'postgres' user before
+             ;; launching daemon.
+             (program-file "start-postgres"
+                           #~(let ((user (getpwnam "postgres"))
+                                   (postgres (string-append #$postgresql
+                                                            "/bin/postgres")))
+                               (setgid (passwd:gid user))
+                               (setuid (passwd:uid user))
+                               (system* postgres
+                                        (string-append "--config-file="
+                                                       #$config-file)
+                                        "-p" #$string-port
+                                        "-D" #$data-directory)))))
        (list (shepherd-service
               (provision '(postgres))
               (documentation "Run the PostgreSQL daemon.")
@@ -140,6 +144,7 @@  host	all	all	::1/128 	trust"))
                                           (const %postgresql-accounts))))))
 
 (define* (postgresql-service #:key (postgresql postgresql)
+                             (port 5432)
                              (config-file %default-postgres-config)
                              (data-directory "/var/lib/postgresql/data"))
   "Return a service that runs @var{postgresql}, the PostgreSQL database server.
@@ -149,6 +154,7 @@  and stores the database cluster in @var{data-directory}."
   (service postgresql-service-type
            (postgresql-configuration
             (postgresql postgresql)
+            (port port)
             (config-file config-file)
             (data-directory data-directory))))