Merge pull request #108 from mlaventure/ctr-new-commands
Add pause, resume, watch command to ctr
This commit is contained in:
		| @@ -48,8 +48,11 @@ var containersCommand = cli.Command{ | |||||||
| 		execCommand, | 		execCommand, | ||||||
| 		killCommand, | 		killCommand, | ||||||
| 		listCommand, | 		listCommand, | ||||||
|  | 		pauseCommand, | ||||||
|  | 		resumeCommand, | ||||||
| 		startCommand, | 		startCommand, | ||||||
| 		statsCommand, | 		statsCommand, | ||||||
|  | 		watchCommand, | ||||||
| 	}, | 	}, | ||||||
| 	Action: listContainers, | 	Action: listContainers, | ||||||
| } | } | ||||||
| @@ -269,6 +272,84 @@ func attachStdio(s stdio) error { | |||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | var watchCommand = cli.Command{ | ||||||
|  | 	Name:  "watch", | ||||||
|  | 	Usage: "print container events", | ||||||
|  | 	Action: func(context *cli.Context) { | ||||||
|  | 		c := getClient(context) | ||||||
|  | 		id := context.Args().First() | ||||||
|  | 		if id != "" { | ||||||
|  | 			resp, err := c.State(netcontext.Background(), &types.StateRequest{Id: id}) | ||||||
|  | 			if err != nil { | ||||||
|  | 				fatal(err.Error(), 1) | ||||||
|  | 			} | ||||||
|  | 			for _, c := range resp.Containers { | ||||||
|  | 				if c.Id == id { | ||||||
|  | 					break | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 			if id == "" { | ||||||
|  | 				fatal("Invalid container id", 1) | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		events, reqErr := c.Events(netcontext.Background(), &types.EventsRequest{}) | ||||||
|  | 		if reqErr != nil { | ||||||
|  | 			fatal(reqErr.Error(), 1) | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		for { | ||||||
|  | 			e, err := events.Recv() | ||||||
|  | 			if err != nil { | ||||||
|  | 				fatal(err.Error(), 1) | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			if id == "" || e.Id == id { | ||||||
|  | 				fmt.Printf("%#v\n", e) | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	}, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | var pauseCommand = cli.Command{ | ||||||
|  | 	Name:  "pause", | ||||||
|  | 	Usage: "pause a container", | ||||||
|  | 	Action: func(context *cli.Context) { | ||||||
|  | 		id := context.Args().First() | ||||||
|  | 		if id == "" { | ||||||
|  | 			fatal("container id cannot be empty", 1) | ||||||
|  | 		} | ||||||
|  | 		c := getClient(context) | ||||||
|  | 		_, err := c.UpdateContainer(netcontext.Background(), &types.UpdateContainerRequest{ | ||||||
|  | 			Id:     id, | ||||||
|  | 			Pid:    "init", | ||||||
|  | 			Status: "paused", | ||||||
|  | 		}) | ||||||
|  | 		if err != nil { | ||||||
|  | 			fatal(err.Error(), 1) | ||||||
|  | 		} | ||||||
|  | 	}, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | var resumeCommand = cli.Command{ | ||||||
|  | 	Name:  "resume", | ||||||
|  | 	Usage: "resume a paused container", | ||||||
|  | 	Action: func(context *cli.Context) { | ||||||
|  | 		id := context.Args().First() | ||||||
|  | 		if id == "" { | ||||||
|  | 			fatal("container id cannot be empty", 1) | ||||||
|  | 		} | ||||||
|  | 		c := getClient(context) | ||||||
|  | 		_, err := c.UpdateContainer(netcontext.Background(), &types.UpdateContainerRequest{ | ||||||
|  | 			Id:     id, | ||||||
|  | 			Pid:    "init", | ||||||
|  | 			Status: "running", | ||||||
|  | 		}) | ||||||
|  | 		if err != nil { | ||||||
|  | 			fatal(err.Error(), 1) | ||||||
|  | 		} | ||||||
|  | 	}, | ||||||
|  | } | ||||||
|  |  | ||||||
| var killCommand = cli.Command{ | var killCommand = cli.Command{ | ||||||
| 	Name:  "kill", | 	Name:  "kill", | ||||||
| 	Usage: "send a signal to a container or its processes", | 	Usage: "send a signal to a container or its processes", | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Michael Crosby
					Michael Crosby