unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#36451] [PATCH] gnu: services: postgresql: Don't initdb when directory exists
@ 2019-06-30 20:56 Robert Vollmert
  2024-03-08 11:51 ` [bug#36451] [PATCH v2] " Dale Mellor
  0 siblings, 1 reply; 4+ messages in thread
From: Robert Vollmert @ 2019-06-30 20:56 UTC (permalink / raw)
  To: 36451; +Cc: Robert Vollmert

* 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)

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [bug#36451] [PATCH v2] gnu: services: postgresql: Don't initdb when directory exists
  2019-06-30 20:56 [bug#36451] [PATCH] gnu: services: postgresql: Don't initdb when directory exists Robert Vollmert
@ 2024-03-08 11:51 ` Dale Mellor
  2024-03-13 11:01   ` [bug#36451] [bug#69633] " Christopher Baines
  2024-03-29 22:15   ` bug#36451: bug#69633: " Ludovic Courtès
  0 siblings, 2 replies; 4+ messages in thread
From: Dale Mellor @ 2024-03-08 11:51 UTC (permalink / raw)
  To: 36451; +Cc: guix-devel-0brg6b, rob

From: Robert Vollmert <rob@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@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





^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [bug#36451] [bug#69633] [PATCH v2] gnu: services: postgresql: Don't initdb when directory exists
  2024-03-08 11:51 ` [bug#36451] [PATCH v2] " Dale Mellor
@ 2024-03-13 11:01   ` Christopher Baines
  2024-03-29 22:15   ` bug#36451: bug#69633: " Ludovic Courtès
  1 sibling, 0 replies; 4+ messages in thread
From: Christopher Baines @ 2024-03-13 11:01 UTC (permalink / raw)
  To: Dale Mellor; +Cc: 36451, 69633, rob

[-- Attachment #1: Type: text/plain, Size: 528 bytes --]


Dale Mellor <guix-devel-0brg6b@rdmp.org> writes:

> From: Robert Vollmert <rob@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?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 987 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#36451: bug#69633: [PATCH v2] gnu: services: postgresql: Don't initdb when directory exists
  2024-03-08 11:51 ` [bug#36451] [PATCH v2] " Dale Mellor
  2024-03-13 11:01   ` [bug#36451] [bug#69633] " Christopher Baines
@ 2024-03-29 22:15   ` Ludovic Courtès
  1 sibling, 0 replies; 4+ messages in thread
From: Ludovic Courtès @ 2024-03-29 22:15 UTC (permalink / raw)
  To: Dale Mellor; +Cc: 36451-done, 69633-done, rob

Hi,

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

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

Finally applied, thank you!

Ludo’.




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-29 22:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-30 20:56 [bug#36451] [PATCH] gnu: services: postgresql: Don't initdb when directory exists Robert Vollmert
2024-03-08 11:51 ` [bug#36451] [PATCH v2] " Dale Mellor
2024-03-13 11:01   ` [bug#36451] [bug#69633] " Christopher Baines
2024-03-29 22:15   ` bug#36451: bug#69633: " Ludovic Courtès

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).