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
|
*.exe
|
||||||
|
main
|
||||||
/containerd/containerd
|
/containerd/containerd
|
||||||
/containerd-shim/containerd-shim
|
/containerd-shim/containerd-shim
|
||||||
/bin/
|
/bin/
|
||||||
|
|
12
container.go
12
container.go
|
@ -100,9 +100,10 @@ func (c *Container) NewProcess(spec *specs.Process) (*Process, error) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
process := &Process{
|
process := &Process{
|
||||||
s: spec,
|
s: spec,
|
||||||
c: c,
|
c: c,
|
||||||
exec: true,
|
exec: true,
|
||||||
|
driver: c.driver,
|
||||||
}
|
}
|
||||||
c.processes = append(c.processes, process)
|
c.processes = append(c.processes, process)
|
||||||
return process, nil
|
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
|
// Wait will perform a blocking wait on the init process of the container
|
||||||
func (c *Container) Wait() (uint32, error) {
|
func (c *Container) Wait() (uint32, error) {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
proc := c.init
|
||||||
return c.init.Wait()
|
c.mu.Unlock()
|
||||||
|
return proc.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signal will send the provided signal to the init process of the container
|
// Signal will send the provided signal to the init process of the container
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -65,6 +66,43 @@ func runTest() error {
|
||||||
return err
|
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
|
// wait for it to exit and get the exit status
|
||||||
logrus.Info("wait container")
|
logrus.Info("wait container")
|
||||||
status, err := container.Wait()
|
status, err := container.Wait()
|
||||||
|
|
|
@ -66,8 +66,11 @@ func (r *Runc) Exec(c *containerkit.Container, p *containerkit.Process) (contain
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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
|
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)
|
data, err := ioutil.ReadFile(pidFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in a new issue