Add exec to example
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
b3ab74fee3
commit
df79231bdf
4 changed files with 50 additions and 6 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
|||
*.exe
|
||||
main
|
||||
/containerd/containerd
|
||||
/containerd-shim/containerd-shim
|
||||
/bin/
|
||||
|
|
|
@ -103,6 +103,7 @@ func (c *Container) NewProcess(spec *specs.Process) (*Process, error) {
|
|||
s: spec,
|
||||
c: c,
|
||||
exec: true,
|
||||
driver: c.driver,
|
||||
}
|
||||
c.processes = append(c.processes, process)
|
||||
return process, nil
|
||||
|
@ -123,8 +124,9 @@ func (c *Container) Pid() int {
|
|||
// Wait will perform a blocking wait on the init process of the container
|
||||
func (c *Container) Wait() (uint32, error) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
return c.init.Wait()
|
||||
proc := c.init
|
||||
c.mu.Unlock()
|
||||
return proc.Wait()
|
||||
}
|
||||
|
||||
// Signal will send the provided signal to the init process of the container
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
@ -65,6 +66,43 @@ func runTest() error {
|
|||
return err
|
||||
}
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
process, err := container.NewProcess(&specs.Process{
|
||||
Args: []string{
|
||||
"echo", fmt.Sprintf("sup from itteration %d", i),
|
||||
},
|
||||
Env: []string{"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"},
|
||||
Terminal: false,
|
||||
Cwd: "/",
|
||||
NoNewPrivileges: true,
|
||||
Capabilities: []string{
|
||||
"CAP_AUDIT_WRITE",
|
||||
"CAP_KILL",
|
||||
"CAP_FOWNER",
|
||||
"CAP_CHOWN",
|
||||
"CAP_MKNOD",
|
||||
"CAP_FSETID",
|
||||
"CAP_DAC_OVERRIDE",
|
||||
"CAP_SETFCAP",
|
||||
"CAP_SETPCAP",
|
||||
"CAP_SETGID",
|
||||
"CAP_SETUID",
|
||||
"CAP_NET_BIND_SERVICE",
|
||||
},
|
||||
})
|
||||
process.Stdin = os.Stdin
|
||||
process.Stdout = os.Stdout
|
||||
process.Stderr = os.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)
|
||||
}
|
||||
|
||||
// wait for it to exit and get the exit status
|
||||
logrus.Info("wait container")
|
||||
status, err := container.Wait()
|
||||
|
|
|
@ -66,8 +66,11 @@ func (r *Runc) Exec(c *containerkit.Container, p *containerkit.Process) (contain
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cmd := r.command("exec", "--process", path, "--pid-file", pidFile, c.ID())
|
||||
cmd := r.command("exec", "--detach", "--process", path, "--pid-file", pidFile, c.ID())
|
||||
cmd.Stdin, cmd.Stdout, cmd.Stderr = p.Stdin, p.Stdout, p.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
data, err := ioutil.ReadFile(pidFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Reference in a new issue