summaryrefslogtreecommitdiff
path: root/gnu/machine/ssh.scm
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/machine/ssh.scm')
-rw-r--r--gnu/machine/ssh.scm146
1 files changed, 145 insertions, 1 deletions
diff --git a/gnu/machine/ssh.scm b/gnu/machine/ssh.scm
index d1c90b63134..274d56db269 100644
--- a/gnu/machine/ssh.scm
+++ b/gnu/machine/ssh.scm
@@ -20,6 +20,9 @@
20 #:use-module (gnu machine) 20 #:use-module (gnu machine)
21 #:autoload (gnu packages gnupg) (guile-gcrypt) 21 #:autoload (gnu packages gnupg) (guile-gcrypt)
22 #:use-module (gnu system) 22 #:use-module (gnu system)
23 #:use-module (gnu system file-systems)
24 #:use-module (gnu system uuid)
25 #:use-module (guix diagnostics)
23 #:use-module (guix gexp) 26 #:use-module (guix gexp)
24 #:use-module (guix i18n) 27 #:use-module (guix i18n)
25 #:use-module (guix modules) 28 #:use-module (guix modules)
@@ -29,6 +32,7 @@
29 #:use-module (guix scripts system reconfigure) 32 #:use-module (guix scripts system reconfigure)
30 #:use-module (guix ssh) 33 #:use-module (guix ssh)
31 #:use-module (guix store) 34 #:use-module (guix store)
35 #:use-module (guix utils)
32 #:use-module (ice-9 match) 36 #:use-module (ice-9 match)
33 #:use-module (srfi srfi-19) 37 #:use-module (srfi srfi-19)
34 #:use-module (srfi srfi-26) 38 #:use-module (srfi srfi-26)
@@ -100,6 +104,145 @@ an environment type of 'managed-host."
100 104
101 105
102;;; 106;;;
107;;; Safety checks.
108;;;
109
110(define (machine-check-file-system-availability machine)
111 "Raise a '&message' error condition if any of the file-systems specified in
112MACHINE's 'system' declaration do not exist on the machine."
113 (define file-systems
114 (filter (lambda (fs)
115 (and (file-system-mount? fs)
116 (not (member (file-system-type fs)
117 %pseudo-file-system-types))
118 (not (memq 'bind-mount (file-system-flags fs)))))
119 (operating-system-file-systems (machine-operating-system machine))))
120
121 (define (check-literal-file-system fs)
122 (define remote-exp
123 #~(catch 'system-error
124 (lambda ()
125 (stat #$(file-system-device fs))
126 #t)
127 (lambda args
128 (system-error-errno args))))
129
130 (mlet %store-monad ((errno (machine-remote-eval machine remote-exp)))
131 (when (number? errno)
132 (raise (condition
133 (&message
134 (message (format #f (G_ "device '~a' not found: ~a")
135 (file-system-device fs)
136 (strerror errno)))))))
137 (return #t)))
138
139 (define (check-labeled-file-system fs)
140 (define remote-exp
141 (with-imported-modules '((gnu build file-systems))
142 #~(begin
143 (use-modules (gnu build file-systems))
144 (find-partition-by-label #$(file-system-label->string
145 (file-system-device fs))))))
146
147 (mlet %store-monad ((result (machine-remote-eval machine remote-exp)))
148 (unless result
149 (raise (condition
150 (&message
151 (message (format #f (G_ "no file system with label '~a'")
152 (file-system-label->string
153 (file-system-device fs))))))))
154 (return #t)))
155
156 (define (check-uuid-file-system fs)
157 (define remote-exp
158 (with-imported-modules (source-module-closure
159 '((gnu build file-systems)
160 (gnu system uuid)))
161 #~(begin
162 (use-modules (gnu build file-systems)
163 (gnu system uuid))
164
165 (define uuid
166 (string->uuid #$(uuid->string (file-system-device fs))))
167
168 (find-partition-by-uuid uuid))))
169
170 (mlet %store-monad ((result (machine-remote-eval machine remote-exp)))
171 (unless result
172 (raise (condition
173 (&message
174 (message (format #f (G_ "no file system with UUID '~a'")
175 (uuid->string (file-system-device fs))))))))
176 (return #t)))
177
178 (mbegin %store-monad
179 (mapm %store-monad check-literal-file-system
180 (filter (lambda (fs)
181 (string? (file-system-device fs)))
182 file-systems))
183 (mapm %store-monad check-labeled-file-system
184 (filter (lambda (fs)
185 (file-system-label? (file-system-device fs)))
186 file-systems))
187 (mapm %store-monad check-uuid-file-system
188 (filter (lambda (fs)
189 (uuid? (file-system-device fs)))
190 file-systems))))
191
192(define (machine-check-initrd-modules machine)
193 "Raise a '&message' error condition if any of the modules needed by
194'needed-for-boot' file systems in MACHINE are not available in the initrd."
195 (define file-systems
196 (filter file-system-needed-for-boot?
197 (operating-system-file-systems (machine-operating-system machine))))
198
199 (define (missing-modules fs)
200 (define remote-exp
201 (let ((device (file-system-device fs)))
202 (with-imported-modules (source-module-closure
203 '((gnu build file-systems)
204 (gnu build linux-modules)
205 (gnu system uuid)))
206 #~(begin
207 (use-modules (gnu build file-systems)
208 (gnu build linux-modules)
209 (gnu system uuid))
210
211 (define dev
212 #$(cond ((string? device) device)
213 ((uuid? device) #~(find-partition-by-uuid
214 (string->uuid
215 #$(uuid->string device))))
216 ((file-system-label? device)
217 #~(find-partition-by-label
218 (file-system-label->string #$device)))))
219
220 (missing-modules dev '#$(operating-system-initrd-modules
221 (machine-operating-system machine)))))))
222 (mlet %store-monad ((missing (machine-remote-eval machine remote-exp)))
223 (return (list fs missing))))
224
225 (mlet %store-monad ((device (mapm %store-monad missing-modules file-systems)))
226 (for-each (match-lambda
227 ((fs missing)
228 (unless (null? missing)
229 (raise (condition
230 (&message
231 (message (format #f (G_ "~a missing modules ~{ ~a~}~%")
232 (file-system-device fs)
233 missing))))))))
234 device)
235 (return #t)))
236
237(define (check-deployment-sanity machine)
238 "Raise a '&message' error condition if it is clear that deploying MACHINE's
239'system' declaration would fail."
240 (mbegin %store-monad
241 (machine-check-file-system-availability machine)
242 (machine-check-initrd-modules machine)))
243
244
245;;;
103;;; System deployment. 246;;; System deployment.
104;;; 247;;;
105 248
@@ -165,7 +308,8 @@ of MACHINE's system profile, ordered from most recent to oldest."
165 "Internal implementation of 'deploy-machine' for MACHINE instances with an 308 "Internal implementation of 'deploy-machine' for MACHINE instances with an
166environment type of 'managed-host." 309environment type of 'managed-host."
167 (maybe-raise-unsupported-configuration-error machine) 310 (maybe-raise-unsupported-configuration-error machine)
168 (mlet %store-monad ((boot-parameters (machine-boot-parameters machine))) 311 (mlet %store-monad ((_ (check-deployment-sanity machine))
312 (boot-parameters (machine-boot-parameters machine)))
169 (let* ((os (machine-operating-system machine)) 313 (let* ((os (machine-operating-system machine))
170 (eval (cut machine-remote-eval machine <>)) 314 (eval (cut machine-remote-eval machine <>))
171 (menu-entries (map boot-parameters->menu-entry boot-parameters)) 315 (menu-entries (map boot-parameters->menu-entry boot-parameters))