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.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#36451: closed ([PATCH] gnu: services: postgresql: Don't
 initdb when directory exists)
Date: Fri, 29 Mar 2024 22:16:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Fri, 29 Mar 2024 23:15:27 +0100
with message-id <87wmpkfzwg.fsf_-_ <at> gnu.org>
and subject line Re: bug#69633: [PATCH v2] gnu: services: postgresql: Don't initdb when directory exists
has caused the debbugs.gnu.org bug report #36451,
regarding [PATCH] gnu: services: postgresql: Don't initdb when directory exists
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
36451: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=36451
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
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)



[Message part 3 (message/rfc822, inline)]
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’.


This bug report was last modified 250 days ago.

Previous Next


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