@@ -113,6 +113,16 @@ mod error {
113
113
name : String ,
114
114
source : std:: io:: Error ,
115
115
} ,
116
+
117
+ #[ snafu( display(
118
+ "Failed to serialize container entrypoint command {:?}: {}" ,
119
+ command,
120
+ source
121
+ ) ) ]
122
+ SerializeContainerCommand {
123
+ command : Vec < String > ,
124
+ source : serde_json:: Error ,
125
+ } ,
116
126
}
117
127
}
118
128
@@ -233,10 +243,17 @@ where
233
243
}
234
244
235
245
/// Write out the EnvironmentFile that systemd uses to fill in arguments to host-ctr
236
- fn write_env_file < S1 , S2 > ( name : S1 , source : S2 , enabled : bool , superpowered : bool ) -> Result < ( ) >
246
+ fn write_env_file < S1 , S2 , S3 > (
247
+ name : S1 ,
248
+ source : S2 ,
249
+ enabled : bool ,
250
+ superpowered : bool ,
251
+ command : S3 ,
252
+ ) -> Result < ( ) >
237
253
where
238
254
S1 : AsRef < str > ,
239
255
S2 : AsRef < str > ,
256
+ S3 : AsRef < str > ,
240
257
{
241
258
let name = name. as_ref ( ) ;
242
259
let filename = format ! ( "{name}.env" ) ;
@@ -247,6 +264,8 @@ where
247
264
. context ( error:: EnvFileBuildFailedSnafu { name } ) ?;
248
265
writeln ! ( output, "CTR_SOURCE={}" , source. as_ref( ) )
249
266
. context ( error:: EnvFileBuildFailedSnafu { name } ) ?;
267
+ writeln ! ( output, "CTR_COMMAND={}" , command. as_ref( ) )
268
+ . context ( error:: EnvFileBuildFailedSnafu { name } ) ?;
250
269
251
270
writeln ! (
252
271
output,
@@ -336,10 +355,15 @@ where
336
355
} ) ?;
337
356
let enabled = image_details. enabled . unwrap_or ( false ) ;
338
357
let superpowered = image_details. superpowered . unwrap_or ( false ) ;
358
+ let command = serde_json:: to_string ( & image_details. command ) . context (
359
+ error:: SerializeContainerCommandSnafu {
360
+ command : image_details. command . clone ( ) ,
361
+ } ,
362
+ ) ?;
339
363
340
364
info ! (
341
- "Host container '{}' is enabled: {}, superpowered: {}, with source: {}" ,
342
- name, enabled, superpowered, source
365
+ "Host container '{}' is enabled: {}, superpowered: {}, with source: {}, entrypoint command: {} " ,
366
+ name, enabled, superpowered, source, command
343
367
) ;
344
368
345
369
// Create the directory regardless if user data was provided for the container
@@ -360,7 +384,7 @@ where
360
384
361
385
// Write the environment file needed for the systemd service to have details about this
362
386
// specific host container
363
- write_env_file ( name, source, enabled, superpowered) ?;
387
+ write_env_file ( name, source, enabled, superpowered, command ) ?;
364
388
365
389
// Now start/stop the container according to the 'enabled' setting
366
390
let unit_name = format ! ( "host-containers@{name}.service" ) ;
@@ -376,13 +400,13 @@ where
376
400
// We want to ensure the host container is running with its most recent configuration.
377
401
if host_containerd_unit. is_active ( ) ? {
378
402
debug ! ( "Cleaning up host container: '{}'" , unit_name) ;
379
- command (
403
+ crate :: command (
380
404
constants:: HOST_CTR_BIN ,
381
405
[ "clean-up" , "--container-id" , name] ,
382
406
) ?;
383
407
}
384
408
385
- let systemd_target = command ( constants:: SYSTEMCTL_BIN , [ "get-default" ] ) ?;
409
+ let systemd_target = crate :: command ( constants:: SYSTEMCTL_BIN , [ "get-default" ] ) ?;
386
410
387
411
// What happens next depends on whether the system has finished booting, and whether the
388
412
// host container is enabled.
@@ -501,6 +525,7 @@ mod test {
501
525
enabled = true
502
526
superpowered = true
503
527
user-data = "Zm9vCg=="
528
+ command = ["sh", "-c", "echo hello"]
504
529
"# ;
505
530
506
531
let temp_dir = tempfile:: TempDir :: new ( ) . unwrap ( ) ;
@@ -517,6 +542,7 @@ mod test {
517
542
enabled : Some ( true ) ,
518
543
superpowered : Some ( true ) ,
519
544
user_data : Some ( ValidBase64 :: try_from ( "Zm9vCg==" ) . unwrap ( ) ) ,
545
+ command : [ "sh" , "-c" , "echo hello" ] . map ( String :: from) . into ( ) ,
520
546
} ,
521
547
) ;
522
548
0 commit comments