-
Notifications
You must be signed in to change notification settings - Fork 5
/
kill.go
68 lines (57 loc) · 1.37 KB
/
kill.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
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"os"
"strconv"
"syscall"
)
func killFromPidFile(context *cli.Context, pidFile string, signal int) error {
pid, err := readPidFile(context, pidFile)
if err != nil {
// logrus.Warnf("couldn't find pid %d(%s)", pidI, err)
return nil
}
proc, err := os.FindProcess(pid)
if err != nil {
logrus.Infof("couldn't find pid %d(%s)", pid, err)
return err
}
err = proc.Signal(syscall.Signal(signal))
if err != nil {
logrus.Warnf("couldn't signal to pid %d(%s)", pid, err)
return err
}
return nil
}
var killCommand = cli.Command{
Name: "kill",
ArgsUsage: `<container-id>`,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "all",
},
},
Action: func(context *cli.Context) error {
args := context.Args()
if args.Present() == false {
return fmt.Errorf("Missing container ID")
}
container := context.Args().Get(0)
signal, _ := strconv.Atoi(context.Args().Get(1))
// kill 9pfs server
err := killFromPidFile(context, pidFile9p, signal)
if err != nil {
logrus.Warnf("killing 9pfs error %s", err)
}
// kill main process
err = killFromPidFile(context, pidFilePriv, signal)
if err != nil {
return fmt.Errorf("killing main process error %s", err)
}
saveState(specs.StateStopped, container, context)
return nil
},
}