mirror of
				https://github.com/opencontainers/runc.git
				synced 2025-10-31 19:13:12 +08:00 
			
		
		
		
	 1545ea69b7
			
		
	
	1545ea69b7
	
	
	
		
			
			Error messages should not usually contain newlines. Testing shows that the error runc delete prints is the same before and after this commit: [kir@kir-rhat runc-tst]$ sudo ../runc/runc delete xx3 ERRO[0000] cannot delete container xx3 that is not stopped: running [kir@kir-rhat runc-tst]$ Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
		
			
				
	
	
		
			55 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package main
 | |
| 
 | |
| import (
 | |
| 	"errors"
 | |
| 	"fmt"
 | |
| 	"os"
 | |
| 
 | |
| 	"github.com/opencontainers/runc/libcontainer"
 | |
| 	"github.com/urfave/cli"
 | |
| )
 | |
| 
 | |
| var startCommand = cli.Command{
 | |
| 	Name:  "start",
 | |
| 	Usage: "executes the user defined process in a created container",
 | |
| 	ArgsUsage: `<container-id>
 | |
| 
 | |
| Where "<container-id>" is your name for the instance of the container that you
 | |
| are starting. The name you provide for the container instance must be unique on
 | |
| your host.`,
 | |
| 	Description: `The start command executes the user defined process in a created container.`,
 | |
| 	Action: func(context *cli.Context) error {
 | |
| 		if err := checkArgs(context, 1, exactArgs); err != nil {
 | |
| 			return err
 | |
| 		}
 | |
| 		container, err := getContainer(context)
 | |
| 		if err != nil {
 | |
| 			return err
 | |
| 		}
 | |
| 		status, err := container.Status()
 | |
| 		if err != nil {
 | |
| 			return err
 | |
| 		}
 | |
| 		switch status {
 | |
| 		case libcontainer.Created:
 | |
| 			notifySocket, err := notifySocketStart(context, os.Getenv("NOTIFY_SOCKET"), container.ID())
 | |
| 			if err != nil {
 | |
| 				return err
 | |
| 			}
 | |
| 			if err := container.Exec(); err != nil {
 | |
| 				return err
 | |
| 			}
 | |
| 			if notifySocket != nil {
 | |
| 				return notifySocket.waitForContainer(container)
 | |
| 			}
 | |
| 			return nil
 | |
| 		case libcontainer.Stopped:
 | |
| 			return errors.New("cannot start a container that has stopped")
 | |
| 		case libcontainer.Running:
 | |
| 			return errors.New("cannot start an already running container")
 | |
| 		default:
 | |
| 			return fmt.Errorf("cannot start a container in the %s state", status)
 | |
| 		}
 | |
| 	},
 | |
| }
 |