GNU bug report logs - #36451
[PATCH] gnu: services: postgresql: Don't initdb when directory exists

Previous Next

Package: guix-patches;

Reported by: Robert Vollmert <rob <at> vllmrt.net>

Date: Sun, 30 Jun 2019 20:57:03 UTC

Severity: normal

Tags: patch

Merged with 69633

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 36451 in the body.
You can then email your comments to 36451 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#36451; Package guix-patches. (Sun, 30 Jun 2019 20:57:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Robert Vollmert <rob <at> vllmrt.net>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Sun, 30 Jun 2019 20:57:05 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Robert Vollmert <rob <at> vllmrt.net>
To: guix-patches <at> gnu.org
Cc: Robert Vollmert <rob <at> vllmrt.net>
Subject: [PATCH] gnu: services: postgresql: Don't initdb when directory exists
Date: Sun, 30 Jun 2019 22:56:42 +0200
* gnu/services/databases.scm (postgresql-activation): Check if
directory exists.
---
 gnu/services/databases.scm | 63 +++++++++++++++++++-------------------
 1 file changed, 32 insertions(+), 31 deletions(-)

diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm
index ec31489d48..6b04ae0a0f 100644
--- a/gnu/services/databases.scm
+++ b/gnu/services/databases.scm
@@ -196,37 +196,38 @@ host	all	all	::1/128 	md5"))
          (use-modules (guix build utils)
                       (ice-9 match))
 
-         (let ((user (getpwnam "postgres"))
-               (initdb (string-append #$(final-postgresql postgresql extension-packages)
-                                      "/bin/initdb"))
-               (initdb-args
-                (append
-                 (if #$locale
-                     (list (string-append "--locale=" #$locale))
-                     '()))))
-           ;; Create db state directory.
-           (mkdir-p #$data-directory)
-           (chown #$data-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)
-             (0
-              ;; Exit with a non-zero status code if an exception is thrown.
-              (dynamic-wind
-                (const #t)
-                (lambda ()
-                  (setgid (passwd:gid user))
-                  (setuid (passwd:uid user))
-                  (primitive-exit
-                   (apply system*
-                          initdb
-                          "-D"
-                          #$data-directory
-                          initdb-args)))
-                (lambda ()
-                  (primitive-exit 1))))
-             (pid (waitpid pid))))))))
+         (when (not (file-exists? #$data-directory))
+           (let ((user (getpwnam "postgres"))
+                 (initdb (string-append #$(final-postgresql postgresql extension-packages)
+                                        "/bin/initdb"))
+                 (initdb-args
+                  (append
+                   (if #$locale
+                       (list (string-append "--locale=" #$locale))
+                       '()))))
+             ;; Create db state directory.
+             (mkdir-p #$data-directory)
+             (chown #$data-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)
+               (0
+                ;; Exit with a non-zero status code if an exception is thrown.
+                (dynamic-wind
+                  (const #t)
+                  (lambda ()
+                    (setgid (passwd:gid user))
+                    (setuid (passwd:uid user))
+                    (primitive-exit
+                     (apply system*
+                            initdb
+                            "-D"
+                            #$data-directory
+                            initdb-args)))
+                  (lambda ()
+                    (primitive-exit 1))))
+               (pid (waitpid pid)))))))))
 
 (define postgresql-shepherd-service
   (match-lambda
-- 
2.20.1 (Apple Git-117)





Information forwarded to guix-patches <at> gnu.org:
bug#36451; Package guix-patches. (Fri, 08 Mar 2024 11:52:02 GMT) Full text and rfc822 format available.

Message #8 received at 36451 <at> debbugs.gnu.org (full text, mbox):

From: Dale Mellor <guix-devel-0brg6b <at> rdmp.org>
To: 36451 <at> debbugs.gnu.org
Cc: Dale Mellor <guix-devel-0brg6b <at> rdmp.org>, guix-patches <at> gnu.org,
 Robert Vollmert <rob <at> vllmrt.net>
Subject: [PATCH v2] gnu: services: postgresql: Don't initdb when directory
 exists
Date: Fri,  8 Mar 2024 11:51:01 +0000
From: Robert Vollmert <rob <at> vllmrt.net>

* gnu/services/databases.scm (postgresql-activation): Check if
directory exists.

--------------
Dale Mellor:

     - Modified to make patch apply to head of current master branch.
     - Verified working, does not break an existing system.
     - Code change is clean.

Reviewed-by: Dale Mellor <guix-devel-0brg6b <at> rdmp.org>
---
 gnu/services/databases.scm | 68 ++++++++++++++++++++------------------
 1 file changed, 35 insertions(+), 33 deletions(-)

diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm
index 580031cb423..cb85d18e214 100644
--- a/gnu/services/databases.scm
+++ b/gnu/services/databases.scm
@@ -235,20 +235,7 @@ (define postgresql-activation
          (use-modules (guix build utils)
                       (ice-9 match))
 
-         (let ((user (getpwnam "postgres"))
-               (initdb (string-append
-                        #$(final-postgresql postgresql
-                                            extension-packages)
-                        "/bin/initdb"))
-               (initdb-args
-                (append
-                 (if #$locale
-                     (list (string-append "--locale=" #$locale))
-                     '()))))
-           ;; Create db state directory.
-           (mkdir-p #$data-directory)
-           (chown #$data-directory (passwd:uid user) (passwd:gid user))
-
+         (let ((user (getpwnam "postgres")))
            ;; Create the socket directory.
            (let ((socket-directory
                   #$(postgresql-config-file-socket-directory config-file)))
@@ -261,25 +248,40 @@ (define postgresql-activation
              (mkdir-p #$log-directory)
              (chown #$log-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)
-             (0
-              ;; Exit with a non-zero status code if an exception is thrown.
-              (dynamic-wind
-                (const #t)
-                (lambda ()
-                  (setgid (passwd:gid user))
-                  (setuid (passwd:uid user))
-                  (primitive-exit
-                   (apply system*
-                          initdb
-                          "-D"
-                          #$data-directory
-                          initdb-args)))
-                (lambda ()
-                  (primitive-exit 1))))
-             (pid (waitpid pid))))))))
+           (unless (file-exists? #$data-directory)
+             (let ((initdb (string-append
+                            #$(final-postgresql postgresql
+                                                extension-packages)
+                            "/bin/initdb"))
+                   (initdb-args
+                    (append
+                     (if #$locale
+                         (list (string-append "--locale=" #$locale))
+                         '()))))
+               ;; Create db state directory.
+               (mkdir-p #$data-directory)
+               (chown #$data-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)
+                 (0
+                  ;; Exit with a non-zero status code if an exception is
+                  ;; thrown.
+                  (dynamic-wind
+                      (const #t)
+                      (lambda ()
+                        (setgid (passwd:gid user))
+                        (setuid (passwd:uid user))
+                        (primitive-exit
+                         (apply system*
+                                initdb
+                                "-D"
+                                #$data-directory
+                                initdb-args)))
+                      (lambda ()
+                        (primitive-exit 1))))
+                 (pid (waitpid pid))))))))))
 
 (define postgresql-shepherd-service
   (match-lambda
-- 
2.41.0





Merged 36451 69633. Request was from Dale Mellor <guix-devel-0brg6b <at> rdmp.org> to control <at> debbugs.gnu.org. (Fri, 08 Mar 2024 11:58:02 GMT) Full text and rfc822 format available.

Information forwarded to guix-patches <at> gnu.org:
bug#36451; Package guix-patches. (Wed, 13 Mar 2024 11:05:02 GMT) Full text and rfc822 format available.

Message #13 received at 36451 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Baines <mail <at> cbaines.net>
To: Dale Mellor <guix-devel-0brg6b <at> rdmp.org>
Cc: 36451 <at> debbugs.gnu.org, guix-patches <at> gnu.org, 69633 <at> debbugs.gnu.org,
 rob <at> vllmrt.net
Subject: Re: [bug#69633] [PATCH v2] gnu: services: postgresql: Don't initdb
 when directory exists
Date: Wed, 13 Mar 2024 11:01:03 +0000
[Message part 1 (text/plain, inline)]
Dale Mellor <guix-devel-0brg6b <at> rdmp.org> writes:

> From: Robert Vollmert <rob <at> vllmrt.net>
>
> * gnu/services/databases.scm (postgresql-activation): Check if
> directory exists.
>
> --------------
> Dale Mellor:
>
>      - Modified to make patch apply to head of current master branch.
>      - Verified working, does not break an existing system.
>      - Code change is clean.

I think what I'm missing here is why this change is being made? I think
the PostgreSQL service works at the moment, so what does this change
mean?
[signature.asc (application/pgp-signature, inline)]

Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Fri, 29 Mar 2024 22:16:02 GMT) Full text and rfc822 format available.

Notification sent to Robert Vollmert <rob <at> vllmrt.net>:
bug acknowledged by developer. (Fri, 29 Mar 2024 22:16:02 GMT) Full text and rfc822 format available.

Message #18 received at 36451-done <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Dale Mellor <guix-devel-0brg6b <at> rdmp.org>
Cc: 36451-done <at> debbugs.gnu.org, 69633-done <at> debbugs.gnu.org, rob <at> vllmrt.net
Subject: Re: bug#69633: [PATCH v2] gnu: services: postgresql: Don't initdb
 when directory exists
Date: Fri, 29 Mar 2024 23:15:27 +0100
Hi,

Dale Mellor <guix-devel-0brg6b <at> rdmp.org> skribis:

> From: Robert Vollmert <rob <at> vllmrt.net>
>
> * gnu/services/databases.scm (postgresql-activation): Check if
> directory exists.

Finally applied, thank you!

Ludo’.




Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Fri, 29 Mar 2024 22:16:02 GMT) Full text and rfc822 format available.

Notification sent to Dale Mellor <guix-devel-0brg6b <at> rdmp.org>:
bug acknowledged by developer. (Fri, 29 Mar 2024 22:16:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 27 Apr 2024 11:24:34 GMT) Full text and rfc822 format available.

This bug report was last modified 6 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.