-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_command.go
59 lines (52 loc) · 1.25 KB
/
main_command.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
log "github.com/sirupsen/logrus"
"github.com/scaat/kangaroo/container"
"github.com/urfave/cli"
)
var runCommand = cli.Command{
Name: "run",
Usage: `Create a container with namespace and cgroups limit
kangaroo run -ti [command]`,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "ti",
Usage: "enable tty",
},
},
/*
这里是run命令执行的真正函数
1. 判断参数是否包含command
2. 获取用户指定的command
3. 调用 Run function 去准备启动容器
*/
Action: func(context *cli.Context) error {
if len(context.Args()) < 1 {
return fmt.Errorf("missing container command")
}
// cmd := context.Args().Get(0)
var cmdArray []string
for _, arg := range context.Args() {
cmdArray = append(cmdArray, arg)
}
tty := context.Bool("ti")
Run(tty, cmdArray)
return nil
},
}
var initCommand = cli.Command{
Name: "init",
Usage: "Init container process run user's process in container. Do not call it outside",
/*
1. 获取传递过来的 command 参数
2. 执行容器初始化操作
*/
Action: func(context *cli.Context) error {
log.Info("init come on")
cmd := context.Args().Get(0)
log.Infof("command %s", cmd)
err := container.RunContainerInitProcess()
return err
},
}