mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-11-07 07:26:13 -05:00
services: postgresql: Don't initdb when directory exists.
* gnu/services/databases.scm (postgresql-activation): Check if directory exists. Reviewed-by: Dale Mellor <guix-devel-0brg6b@rdmp.org> Signed-off-by: Ludovic Courtès <ludo@gnu.org> Change-Id: Id563a3e8df2cb5b805e64cd8319303c65d308c69
This commit is contained in:
parent
b0a37d8b1a
commit
ed03a0aa9b
1 changed files with 35 additions and 33 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue