@@ -113,6 +113,16 @@ mod error {
113113 name : String ,
114114 source : std:: io:: Error ,
115115 } ,
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+ } ,
116126 }
117127}
118128
@@ -233,10 +243,17 @@ where
233243}
234244
235245/// 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 < ( ) >
237253where
238254 S1 : AsRef < str > ,
239255 S2 : AsRef < str > ,
256+ S3 : AsRef < str > ,
240257{
241258 let name = name. as_ref ( ) ;
242259 let filename = format ! ( "{name}.env" ) ;
@@ -247,6 +264,8 @@ where
247264 . context ( error:: EnvFileBuildFailedSnafu { name } ) ?;
248265 writeln ! ( output, "CTR_SOURCE={}" , source. as_ref( ) )
249266 . context ( error:: EnvFileBuildFailedSnafu { name } ) ?;
267+ writeln ! ( output, "CTR_COMMAND={}" , command. as_ref( ) )
268+ . context ( error:: EnvFileBuildFailedSnafu { name } ) ?;
250269
251270 writeln ! (
252271 output,
@@ -336,10 +355,15 @@ where
336355 } ) ?;
337356 let enabled = image_details. enabled . unwrap_or ( false ) ;
338357 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+ ) ?;
339363
340364 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
343367 ) ;
344368
345369 // Create the directory regardless if user data was provided for the container
@@ -360,7 +384,7 @@ where
360384
361385 // Write the environment file needed for the systemd service to have details about this
362386 // specific host container
363- write_env_file ( name, source, enabled, superpowered) ?;
387+ write_env_file ( name, source, enabled, superpowered, command ) ?;
364388
365389 // Now start/stop the container according to the 'enabled' setting
366390 let unit_name = format ! ( "host-containers@{name}.service" ) ;
@@ -376,13 +400,13 @@ where
376400 // We want to ensure the host container is running with its most recent configuration.
377401 if host_containerd_unit. is_active ( ) ? {
378402 debug ! ( "Cleaning up host container: '{}'" , unit_name) ;
379- command (
403+ crate :: command (
380404 constants:: HOST_CTR_BIN ,
381405 [ "clean-up" , "--container-id" , name] ,
382406 ) ?;
383407 }
384408
385- let systemd_target = command ( constants:: SYSTEMCTL_BIN , [ "get-default" ] ) ?;
409+ let systemd_target = crate :: command ( constants:: SYSTEMCTL_BIN , [ "get-default" ] ) ?;
386410
387411 // What happens next depends on whether the system has finished booting, and whether the
388412 // host container is enabled.
@@ -501,6 +525,7 @@ mod test {
501525 enabled = true
502526 superpowered = true
503527 user-data = "Zm9vCg=="
528+ command = ["sh", "-c", "echo hello"]
504529 "# ;
505530
506531 let temp_dir = tempfile:: TempDir :: new ( ) . unwrap ( ) ;
@@ -517,6 +542,7 @@ mod test {
517542 enabled : Some ( true ) ,
518543 superpowered : Some ( true ) ,
519544 user_data : Some ( ValidBase64 :: try_from ( "Zm9vCg==" ) . unwrap ( ) ) ,
545+ command : [ "sh" , "-c" , "echo hello" ] . map ( String :: from) . into ( ) ,
520546 } ,
521547 ) ;
522548
0 commit comments