services: mysql-upgrade: Support custom datadir.

* gnu/services/databases.scm (mysql-upgrade-wrapper): Take service
configuration as argument, and pass the config file to mysql_upgrade.
(mysql-upgrade-shepherd-service): Pass CONFIG instead of just socket and
executable to MYSQL-UPGRADE-WRAPPER.
This commit is contained in:
Marius Bakke 2022-10-29 18:18:43 +02:00
parent c7b266fdf2
commit 6ac97bb503
No known key found for this signature in database
GPG key ID: A2A06DF2A33A54FA

View file

@ -6,7 +6,7 @@
;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org> ;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
;;; Copyright © 2018 Julien Lepiller <julien@lepiller.eu> ;;; Copyright © 2018 Julien Lepiller <julien@lepiller.eu>
;;; Copyright © 2019 Robert Vollmert <rob@vllmrt.net> ;;; Copyright © 2019 Robert Vollmert <rob@vllmrt.net>
;;; Copyright © 2020 Marius Bakke <marius@gnu.org> ;;; Copyright © 2020, 2022 Marius Bakke <marius@gnu.org>
;;; Copyright © 2021 David Larsson <david.larsson@selfhosted.xyz> ;;; Copyright © 2021 David Larsson <david.larsson@selfhosted.xyz>
;;; Copyright © 2021 Aljosha Papsch <ep@stern-data.com> ;;; Copyright © 2021 Aljosha Papsch <ep@stern-data.com>
;;; ;;;
@ -678,33 +678,36 @@ (define (mysql-install-shepherd-service config)
(list #$(mysql-install config)) (list #$(mysql-install config))
#:log-file "/var/log/mysqld-install.log"))))) #:log-file "/var/log/mysqld-install.log")))))
(define (mysql-upgrade-wrapper mysql socket-file) (define (mysql-upgrade-wrapper config)
;; The MySQL socket and PID file may appear before the server is ready to ;; The MySQL socket and PID file may appear before the server is ready to
;; accept connections. Ensure the socket is responsive before attempting ;; accept connections. Ensure the socket is responsive before attempting
;; to run the upgrade script. ;; to run the upgrade script.
(program-file (let ((mysql (mysql-configuration-mysql config))
"mysql-upgrade-wrapper" (socket-file (mysql-configuration-socket config))
#~(begin (config-file (mysql-configuration-file config)))
(let ((mysql-upgrade #$(file-append mysql "/bin/mysql_upgrade")) (program-file
(timeout 20)) "mysql-upgrade-wrapper"
(begin #~(begin
(let loop ((i 0)) (let ((mysql-upgrade #$(file-append mysql "/bin/mysql_upgrade"))
(catch 'system-error (timeout 20))
(lambda () (begin
(let ((sock (socket PF_UNIX SOCK_STREAM 0))) (let loop ((i 0))
(connect sock AF_UNIX #$socket-file) (catch 'system-error
(close-port sock) (lambda ()
;; The socket is ready! (let ((sock (socket PF_UNIX SOCK_STREAM 0)))
(execl mysql-upgrade mysql-upgrade (connect sock AF_UNIX #$socket-file)
(string-append "--socket=" #$socket-file)))) (close-port sock)
(lambda args ;; The socket is ready!
(if (< i timeout) (execl mysql-upgrade mysql-upgrade
(begin (string-append "--defaults-file=" #$config-file))))
(sleep 1) (lambda args
(loop (+ 1 i))) (if (< i timeout)
;; No luck, give up. (begin
(throw 'timeout-error (sleep 1)
"MySQL server did not appear in time!")))))))))) (loop (+ 1 i)))
;; No luck, give up.
(throw 'timeout-error
"MySQL server did not appear in time!")))))))))))
(define (mysql-upgrade-shepherd-service config) (define (mysql-upgrade-shepherd-service config)
(list (shepherd-service (list (shepherd-service
@ -712,11 +715,9 @@ (define (mysql-upgrade-shepherd-service config)
(requirement '(mysql)) (requirement '(mysql))
(one-shot? #t) (one-shot? #t)
(documentation "Upgrade MySQL database schemas.") (documentation "Upgrade MySQL database schemas.")
(start (let ((mysql (mysql-configuration-mysql config)) (start #~(make-forkexec-constructor
(socket (mysql-configuration-socket config))) (list #$(mysql-upgrade-wrapper config))
#~(make-forkexec-constructor #:user "mysql" #:group "mysql")))))
(list #$(mysql-upgrade-wrapper mysql socket))
#:user "mysql" #:group "mysql"))))))
(define (mysql-shepherd-services config) (define (mysql-shepherd-services config)