services: postgresql: Use pg_ctl to start and stop postgres.

Fixes <https://bugs.gnu.org/29992>.

* gnu/services/databases.scm (postgresql-shepherd-service): Replace
make-forkexec-constructor and make-kill-destructor with pg_ctl.
This commit is contained in:
Clément Lassieur 2018-01-15 09:35:59 +01:00
parent 45b486984d
commit 5ee4cd69c4
No known key found for this signature in database
GPG Key ID: 89F96D4808F359C7
1 changed files with 24 additions and 16 deletions

View File

@ -3,6 +3,7 @@
;;; Copyright © 2015, 2016 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2015, 2016 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2016 Leo Famulari <leo@famulari.name> ;;; Copyright © 2016 Leo Famulari <leo@famulari.name>
;;; Copyright © 2017 Christopher Baines <mail@cbaines.net> ;;; Copyright © 2017 Christopher Baines <mail@cbaines.net>
;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -147,26 +148,33 @@ host all all ::1/128 trust"))
(define postgresql-shepherd-service (define postgresql-shepherd-service
(match-lambda (match-lambda
(($ <postgresql-configuration> postgresql port locale config-file data-directory) (($ <postgresql-configuration> postgresql port locale config-file data-directory)
(let ((start-script (let* ((pg_ctl-wrapper
;; Wrapper script that switches to the 'postgres' user before ;; Wrapper script that switches to the 'postgres' user before
;; launching daemon. ;; launching daemon.
(program-file "start-postgres" (program-file
#~(let ((user (getpwnam "postgres")) "pg_ctl-wrapper"
(postgres (string-append #$postgresql #~(begin
"/bin/postgres"))) (use-modules (ice-9 match)
(ice-9 format))
(match (command-line)
((_ mode)
(let ((user (getpwnam "postgres"))
(pg_ctl #$(file-append postgresql "/bin/pg_ctl"))
(options (format #f "--config-file=~a -p ~d"
#$config-file #$port)))
(setgid (passwd:gid user)) (setgid (passwd:gid user))
(setuid (passwd:uid user)) (setuid (passwd:uid user))
(system* postgres (execl pg_ctl pg_ctl "-D" #$data-directory "-o" options
(string-append "--config-file=" mode)))))))
#$config-file) (action (lambda args
"-p" (number->string #$port) #~(lambda _
"-D" #$data-directory))))) (invoke #$pg_ctl-wrapper #$@args)))))
(list (shepherd-service (list (shepherd-service
(provision '(postgres)) (provision '(postgres))
(documentation "Run the PostgreSQL daemon.") (documentation "Run the PostgreSQL daemon.")
(requirement '(user-processes loopback syslogd)) (requirement '(user-processes loopback syslogd))
(start #~(make-forkexec-constructor #$start-script)) (start (action "start"))
(stop #~(make-kill-destructor)))))))) (stop (action "stop"))))))))
(define postgresql-service-type (define postgresql-service-type
(service-type (name 'postgresql) (service-type (name 'postgresql)