[PATCH v2] gnu: services: postgresql: Don't initdb when directory exists

  • Done
  • quality assurance status badge
Details
3 participants
  • Dale Mellor
  • Ludovic Courtès
  • Christopher Baines
Owner
unassigned
Submitted by
Dale Mellor
Severity
normal
Merged with

Debbugs page

D
D
Dale Mellor wrote on 8 Mar 03:51 -0800
(address . 36451@debbugs.gnu.org)
20240308115101.2047407-1-guix-devel-0brg6b@rdmp.org
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(-)

Toggle diff (88 lines)
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
D
D
Dale Mellor wrote on 8 Mar 03:56 -0800
(name . control)(address . control@debbugs.gnu.org)
2e13b61ee89235a8d3b28d5b3d04763eb0868fc0.camel@rdmp.org
merge 36451 69633
C
C
Christopher Baines wrote on 13 Mar 04:01 -0700
(name . Dale Mellor)(address . guix-devel-0brg6b@rdmp.org)
8734suwg0x.fsf@cbaines.net
Dale Mellor <guix-devel-0brg6b@rdmp.org> writes:

Toggle quote (12 lines)
> 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?
-----BEGIN PGP SIGNATURE-----

iQKlBAEBCgCPFiEEPonu50WOcg2XVOCyXiijOwuE9XcFAmXxh95fFIAAAAAALgAo
aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNF
ODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcRHG1haWxAY2Jh
aW5lcy5uZXQACgkQXiijOwuE9Xe6TQ/9E3ToIgx8OI6xX1GUWo+bjaV+uEnyCEEu
ZekVIba7Sj+mSNI0T9/8BXhboHVQMfyLeG+Z34KO4JxHIZ5XtC2E2r2iYRAQibln
vfc0pV1rw/15CBPRVqLcgVS2HnOn7gPqVh0zEPA6QMc7DFqvpGVd2V8D444TPtWf
j+9kTIh95cyJ7t99n2aJe4CEyef3hJVo2e+8iLJu8nVJyWwXSgjBA0X+AdDx/Gev
XWeAMxlyORrBBdF6FB7U+9xbKRGHkqNznM08mDoVGsc2RxZYKNNrb5vR2XiLiDJ2
quOlrsdgG/eT//szvhZB4MKdoEMvI/9g7ExiHdxCRJCK9RpjeSgtK7nZaEWmL4ub
KlI7AiO1rwFC/8q1RXvwT+IlURSRrQ+iGmupik0Gud09jyc1X5c1HAmyKMKSxXDY
I53CPsibPZHO2lywtznMHf7aXgYS8Zvs+GX/jjbW+E/mawFA3acyVYxA8CYwMSzV
klFz246WTeWE4mLY5pS8pPCq7+SQiUYx77By5fNCns4oQ4+Dg0FOkXFWMRCWyG48
xephCF5JG7oi9uCGjk17th2zywbriUDkD1xuYDahZy+Dcqz+uXwkIMGuFE8Mh1uH
tfLgviqpC9fzif75Nv4b4vEIXb2Is5nCvSopmE+chNK+aF+M2kpH70hjhZ92bwvl
eXM8jCR9F80=
=eh2h
-----END PGP SIGNATURE-----

L
L
Ludovic Courtès wrote on 29 Mar 15:15 -0700
Re: bug#69633: [PATCH v2] gnu: services: postgresql: Don't initdb when directory exists
(name . Dale Mellor)(address . guix-devel-0brg6b@rdmp.org)
87wmpkfzwg.fsf_-_@gnu.org
Hi,

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

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

Finally applied, thank you!

Ludo’.
Closed
?
Your comment

This issue is archived.

To comment on this conversation send an email to 69633@patchwise.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 69633
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch