@@ -347,6 +347,57 @@ func CreateControllerContainer(ctx context.Context, dockerClient *client.Client,
347347 return nil
348348}
349349
350+ // StartControllerContainer starts the model runner controller container.
351+ func StartControllerContainer (ctx context.Context , dockerClient client.ContainerAPIClient , printer StatusPrinter ) error {
352+ // Find the controller container.
353+ containerID , containerName , _ , err := FindControllerContainer (ctx , dockerClient )
354+ if err != nil {
355+ return fmt .Errorf ("unable to find model runner container: %w" , err )
356+ }
357+ if containerID == "" {
358+ return errors .New ("model runner container not found" )
359+ }
360+
361+ // Start the container.
362+ if containerName != "" {
363+ printer .Printf ("Starting model runner container %s (%s)...\n " , containerName , containerID [:12 ])
364+ } else {
365+ printer .Printf ("Starting model runner container %s...\n " , containerID [:12 ])
366+ }
367+ if err := ensureContainerStarted (ctx , dockerClient , containerID ); err != nil {
368+ return fmt .Errorf ("failed to start container: %w" , err )
369+ }
370+
371+ printer .Printf ("Model runner container started successfully\n " )
372+ return nil
373+ }
374+
375+ // StopControllerContainer stops the model runner controller container.
376+ func StopControllerContainer (ctx context.Context , dockerClient client.ContainerAPIClient , printer StatusPrinter ) error {
377+ // Find the controller container.
378+ containerID , containerName , _ , err := FindControllerContainer (ctx , dockerClient )
379+ if err != nil {
380+ return fmt .Errorf ("unable to find model runner container: %w" , err )
381+ }
382+ if containerID == "" {
383+ return errors .New ("model runner container not found" )
384+ }
385+
386+ // Stop the container.
387+ if containerName != "" {
388+ printer .Printf ("Stopping model runner container %s (%s)...\n " , containerName , containerID [:12 ])
389+ } else {
390+ printer .Printf ("Stopping model runner container %s...\n " , containerID [:12 ])
391+ }
392+ stopTimeout := 10 // seconds
393+ if err := dockerClient .ContainerStop (ctx , containerID , container.StopOptions {Timeout : & stopTimeout }); err != nil {
394+ return fmt .Errorf ("failed to stop container: %w" , err )
395+ }
396+
397+ printer .Printf ("Model runner container stopped successfully\n " )
398+ return nil
399+ }
400+
350401// PruneControllerContainers stops and removes any model runner controller
351402// containers.
352403func PruneControllerContainers (ctx context.Context , dockerClient client.ContainerAPIClient , skipRunning bool , printer StatusPrinter ) error {
0 commit comments