installer: final: Stop guix-daemon before accessing store database.

As part of fixing <https://issues.guix.gnu.org/59784>, make sure
/var/guix/db.sqlite is only copied while guix-daemon is stopped.

* gnu/installer/final.scm (call-with-mnt-container): Add FIXME comment.
(install-system): Copy DATABASE-FILE and SAVED-DATABASE only when
'guix-daemon' is stopped.  Add logging lines.
This commit is contained in:
Ludovic Courtès 2022-12-17 23:36:02 +01:00
parent a8f9579348
commit 9b6703eabe
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5

View File

@ -1,6 +1,6 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018, 2020 Mathieu Othacehe <m.othacehe@gmail.com> ;;; Copyright © 2018, 2020 Mathieu Othacehe <m.othacehe@gmail.com>
;;; Copyright © 2019, 2020 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2019, 2020, 2022 Ludovic Courtès <ludo@gnu.org>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -114,6 +114,8 @@ it can interact with the rest of the system."
;; Catch SIGINT and kill the container process. ;; Catch SIGINT and kill the container process.
(sigaction SIGINT (sigaction SIGINT
(lambda (signum) (lambda (signum)
;: FIXME: Use of SIGKILL prevents the dynamic-wind exit handler of
;; THUNK to run.
(false-if-exception (false-if-exception
(kill pid SIGKILL)))) (kill pid SIGKILL))))
@ -196,14 +198,16 @@ or #f. Return #t on success and #f on failure."
;; the loaded cow-store locale files will prevent umounting. ;; the loaded cow-store locale files will prevent umounting.
(install-locale locale) (install-locale locale)
;; Save the database, so that it can be restored once the ;; Stop the daemon and save the database, so that it can be
;; cow-store is umounted. ;; restored once the cow-store is umounted.
(stop-service 'guix-daemon)
(copy-file database-file saved-database) (copy-file database-file saved-database)
(installer-log-line "mounting copy-on-write store")
(mount-cow-store (%installer-target-dir) backing-directory)) (mount-cow-store (%installer-target-dir) backing-directory))
(lambda () (lambda ()
;; We need to drag the guix-daemon to the container MNT ;; We need to drag the guix-daemon to the container MNT
;; namespace, so that it can operate on the cow-store. ;; namespace, so that it can operate on the cow-store.
(stop-service 'guix-daemon)
(start-service 'guix-daemon (list (number->string (getpid)))) (start-service 'guix-daemon (list (number->string (getpid))))
(setvbuf (current-output-port) 'none) (setvbuf (current-output-port) 'none)
@ -213,11 +217,17 @@ or #f. Return #t on success and #f on failure."
(set! ret (run-command install-command #:tty? #t))) (set! ret (run-command install-command #:tty? #t)))
(lambda () (lambda ()
;; Restart guix-daemon so that it does no keep the MNT namespace ;; Stop guix-daemon so that it does no keep the MNT namespace
;; alive. ;; alive.
(restart-service 'guix-daemon) (stop-service 'guix-daemon)
;; Restore the database and restart it.
(installer-log-line "restoring store database from '~a'"
saved-database)
(copy-file saved-database database-file) (copy-file saved-database database-file)
(start-service 'guix-daemon)
;; Finally umount the cow-store and exit the container. ;; Finally umount the cow-store and exit the container.
(installer-log-line "unmounting copy-on-write store")
(unmount-cow-store (%installer-target-dir) backing-directory) (unmount-cow-store (%installer-target-dir) backing-directory)
(assert-exit ret)))))))) (assert-exit ret))))))))