Skip to content
This repository has been archived by the owner on Feb 8, 2021. It is now read-only.

Commit

Permalink
Merge pull request #491 from gao-feng/process
Browse files Browse the repository at this point in the history
introduce api.Process
  • Loading branch information
gao-feng authored Apr 25, 2017
2 parents 078f160 + 6dfc45c commit 73016ca
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 75 deletions.
145 changes: 85 additions & 60 deletions api/descriptions.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions api/descriptions.proto
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,16 @@ message Rlimit {
string type = 1;
uint64 hard = 2;
uint64 soft = 3;
}

message Process {
string Container = 1;
string Id = 2;
string User = 3;
string Group = 4;
repeated string AdditionalGroup = 5;
bool Terminal = 6;
repeated string Args = 7;
repeated string Envs = 8;
string Workdir = 9;
}
48 changes: 34 additions & 14 deletions hypervisor/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,13 @@ func (vm *Vm) HyperstartExecSync(cmd []string, stdin []byte) (stdout, stderr []b
return nil, nil, err
}

err = vm.AddProcess(hyperstartapi.HYPERSTART_EXEC_CONTAINER, execId, false, cmd, []string{}, "/", tty)
err = vm.AddProcess(&api.Process{
Container: hyperstartapi.HYPERSTART_EXEC_CONTAINER,
Id: execId,
Terminal: false,
Args: cmd,
Envs: []string{},
Workdir: "/"}, tty)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -435,7 +441,13 @@ func (vm *Vm) HyperstartExec(cmd string, tty *TtyIO) (int, error) {
return -1, err
}

err := vm.AddProcess(hyperstartapi.HYPERSTART_EXEC_CONTAINER, execID, false, command, []string{}, "/", tty)
err := vm.AddProcess(&api.Process{
Container: hyperstartapi.HYPERSTART_EXEC_CONTAINER,
Id: execID,
Terminal: false,
Args: command,
Envs: []string{},
Workdir: "/"}, tty)
if err != nil {
return -1, err
}
Expand All @@ -461,17 +473,23 @@ func (vm *Vm) Exec(container, execId, cmd string, terminal bool, tty *TtyIO) err
if err := json.Unmarshal([]byte(cmd), &command); err != nil {
return err
}
return vm.AddProcess(container, execId, terminal, command, []string{}, "/", tty)
return vm.AddProcess(&api.Process{
Container: container,
Id: execId,
Terminal: terminal,
Args: command,
Envs: []string{},
Workdir: "/"}, tty)
}

func (vm *Vm) AddProcess(container, execId string, terminal bool, args []string, env []string, workdir string, tty *TtyIO) error {
func (vm *Vm) AddProcess(process *api.Process, tty *TtyIO) error {
if !vm.ctx.IsRunning() {
return NewNotReadyError(vm.Id)
}

envs := []hyperstartapi.EnvironmentVar{}

for _, v := range env {
for _, v := range process.Envs {
if eqlIndex := strings.Index(v, "="); eqlIndex > 0 {
envs = append(envs, hyperstartapi.EnvironmentVar{
Env: v[:eqlIndex],
Expand All @@ -480,24 +498,26 @@ func (vm *Vm) AddProcess(container, execId string, terminal bool, args []string,
}
}

stdinPipe, stdoutPipe, stderrPipe, err := vm.ctx.hyperstart.AddProcess(container, &hyperstartapi.Process{
Id: execId,
Terminal: terminal,
Args: args,
stdinPipe, stdoutPipe, stderrPipe, err := vm.ctx.hyperstart.AddProcess(process.Container, &hyperstartapi.Process{
Id: process.Id,
Terminal: process.Terminal,
Args: process.Args,
Envs: envs,
Workdir: workdir,
Workdir: process.Workdir,
User: process.User,
Group: process.Group,
})

if err != nil {
return fmt.Errorf("exec command %v failed: %v", args, err)
return fmt.Errorf("exec command %v failed: %v", process.Args, err)
}

go streamCopy(tty, stdinPipe, stdoutPipe, stderrPipe)
go func() {
status := vm.ctx.hyperstart.WaitProcess(container, execId)
vm.ctx.DeleteExec(execId)
status := vm.ctx.hyperstart.WaitProcess(process.Container, process.Id)
vm.ctx.DeleteExec(process.Id)
vm.ctx.reportProcessFinished(types.E_EXEC_FINISHED, &types.ProcessFinished{
Id: execId, Code: uint8(status), Ack: make(chan bool, 1),
Id: process.Id, Code: uint8(status), Ack: make(chan bool, 1),
})
}()
return nil
Expand Down
9 changes: 8 additions & 1 deletion supervisor/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,14 @@ func (c *Container) addProcess(processId, stdin, stdout, stderr string, spec *sp
)
reschan := c.ownerPod.vm.WaitProcess(false, []string{processId}, -1)

err := c.ownerPod.vm.AddProcess(c.Id, processId, spec.Terminal, spec.Args, spec.Env, spec.Cwd, p.stdio)
err := c.ownerPod.vm.AddProcess(&api.Process{
Container: c.Id,
Id: processId,
Terminal: spec.Terminal,
Args: spec.Args,
Envs: spec.Env,
Workdir: spec.Cwd}, p.stdio)

if err != nil {
glog.V(1).Infof("add process to container failed: %v\n", err)
} else {
Expand Down

0 comments on commit 73016ca

Please sign in to comment.