From: Robert Vollmert <rob@vllmrt.net>
To: 36451@debbugs.gnu.org
Cc: Robert Vollmert <rob@vllmrt.net>
Subject: [bug#36451] [PATCH] gnu: services: postgresql: Don't initdb when directory exists
Date: Sun, 30 Jun 2019 22:56:42 +0200 [thread overview]
Message-ID: <20190630205642.54866-1-rob@vllmrt.net> (raw)
* 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)
next reply other threads:[~2019-06-30 20:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-30 20:56 Robert Vollmert [this message]
2024-03-08 11:51 ` [bug#36451] [PATCH v2] gnu: services: postgresql: Don't initdb when directory exists 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190630205642.54866-1-rob@vllmrt.net \
--to=rob@vllmrt.net \
--cc=36451@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).