Fix monitor with process events
Monitor was receiving multiple events for the process Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
1911191f94
commit
a861ae9d18
6 changed files with 172 additions and 84 deletions
|
@ -3,7 +3,9 @@ package main
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
|
@ -33,9 +35,9 @@ func runContainer() error {
|
|||
return err
|
||||
}
|
||||
// setup some stdio for our container
|
||||
container.Stdin = Stdin()
|
||||
container.Stdout = Stdout()
|
||||
container.Stderr = Stderr()
|
||||
container.Stdin = Stdin("")
|
||||
container.Stdout = Stdout("")
|
||||
container.Stderr = Stderr("")
|
||||
|
||||
// go ahead and set the container in the create state and have it ready to start
|
||||
logrus.Info("create container")
|
||||
|
@ -49,33 +51,36 @@ func runContainer() error {
|
|||
return err
|
||||
}
|
||||
|
||||
if exec {
|
||||
// start 10 exec processes giving the go var i to exec to stdout
|
||||
for i := 0; i < 10; i++ {
|
||||
process, err := container.NewProcess(&specs.Process{
|
||||
Args: []string{
|
||||
"echo", fmt.Sprintf("sup from itteration %d", i),
|
||||
},
|
||||
Env: env,
|
||||
Terminal: false,
|
||||
Cwd: "/",
|
||||
NoNewPrivileges: true,
|
||||
Capabilities: caps,
|
||||
})
|
||||
for i := 0; i < exec; i++ {
|
||||
process, err := container.NewProcess(&specs.Process{
|
||||
Args: []string{
|
||||
"sh", "-c",
|
||||
"echo " + fmt.Sprintf("sup from itteration %d", i),
|
||||
},
|
||||
Env: env,
|
||||
Terminal: false,
|
||||
Cwd: "/",
|
||||
NoNewPrivileges: true,
|
||||
Capabilities: caps,
|
||||
})
|
||||
|
||||
process.Stdin = os.Stdin
|
||||
process.Stdout = os.Stdout
|
||||
process.Stderr = os.Stderr
|
||||
process.Stdin = Stdin(strconv.Itoa(i))
|
||||
stdout := Stdout(strconv.Itoa(i))
|
||||
|
||||
if err := process.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
procStatus, err := process.Wait()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Infof("process %d returned with %d", i, procStatus)
|
||||
stderr := Stderr(strconv.Itoa(i))
|
||||
go io.Copy(os.Stdout, stdout)
|
||||
go io.Copy(os.Stdout, stderr)
|
||||
process.Stdout = stdout
|
||||
process.Stderr = stderr
|
||||
|
||||
if err := process.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
procStatus, err := process.Wait()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Infof("process %d returned with %d", i, procStatus)
|
||||
}
|
||||
|
||||
if load {
|
||||
|
@ -101,13 +106,13 @@ func runContainer() error {
|
|||
}
|
||||
|
||||
var (
|
||||
exec bool
|
||||
exec int
|
||||
load bool
|
||||
)
|
||||
|
||||
// "Hooks do optional work. Drivers do mandatory work"
|
||||
func main() {
|
||||
flag.BoolVar(&exec, "exec", false, "run the execs")
|
||||
flag.IntVar(&exec, "exec", 0, "run n number of execs")
|
||||
flag.BoolVar(&load, "load", false, "reload the container")
|
||||
flag.Parse()
|
||||
if err := osutils.SetSubreaper(1); err != nil {
|
||||
|
|
|
@ -182,8 +182,8 @@ func (t *testConfig) Spec(m *containerkit.Mount) (*specs.Spec, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func Stdin() *os.File {
|
||||
abs, err := filepath.Abs("stdin")
|
||||
func Stdin(n string) *os.File {
|
||||
abs, err := filepath.Abs("stdin" + n)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -197,8 +197,8 @@ func Stdin() *os.File {
|
|||
return f
|
||||
}
|
||||
|
||||
func Stdout() *os.File {
|
||||
abs, err := filepath.Abs("stdout")
|
||||
func Stdout(n string) *os.File {
|
||||
abs, err := filepath.Abs("stdout" + n)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -212,8 +212,8 @@ func Stdout() *os.File {
|
|||
return f
|
||||
}
|
||||
|
||||
func Stderr() *os.File {
|
||||
abs, err := filepath.Abs("stderr")
|
||||
func Stderr(n string) *os.File {
|
||||
abs, err := filepath.Abs("stderr" + n)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue