This repository was archived by the owner on Dec 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 315
Prepare ground for moving on new API #299
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b608f5d
nsinit: Add Makefile
avagin 159db89
nsinit: use the new API for executing processes
avagin bce773a
linux_container: ct.Destroy() returns error if CT isn't stopped
avagin 2441bab
linux_factory: add StartInitialization()
avagin 8e9a6d2
linux_container: execute an init process in a new CT
avagin 44024d0
Makefile: get the glog package
avagin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,13 @@ | |
| package libcontainer | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "syscall" | ||
|
|
||
| "github.com/docker/libcontainer/network" | ||
| "github.com/golang/glog" | ||
| ) | ||
|
|
@@ -13,6 +20,7 @@ type linuxContainer struct { | |
| config *Config | ||
| state *State | ||
| cgroupManager CgroupManager | ||
| initArgs []string | ||
| } | ||
|
|
||
| func (c *linuxContainer) ID() string { | ||
|
|
@@ -24,7 +32,7 @@ func (c *linuxContainer) Config() *Config { | |
| } | ||
|
|
||
| func (c *linuxContainer) RunState() (RunState, error) { | ||
| panic("not implemented") | ||
| return Destroyed, nil // FIXME return a real state | ||
| } | ||
|
|
||
| func (c *linuxContainer) Processes() ([]int, error) { | ||
|
|
@@ -53,13 +61,91 @@ func (c *linuxContainer) Stats() (*ContainerStats, error) { | |
| } | ||
|
|
||
| func (c *linuxContainer) StartProcess(config *ProcessConfig) (int, error) { | ||
| glog.Info("start new container process") | ||
| panic("not implemented") | ||
| state, err := c.RunState() | ||
| if err != nil { | ||
| return -1, err | ||
| } | ||
|
|
||
| if state != Destroyed { | ||
| glog.Info("start new container process") | ||
| panic("not implemented") | ||
| } | ||
|
|
||
| if err := c.startInitProcess(config); err != nil { | ||
| return -1, err | ||
| } | ||
|
|
||
| return c.state.InitPid, nil | ||
| } | ||
|
|
||
| func (c *linuxContainer) updateStateFile() error { | ||
| data, err := json.MarshalIndent(c.state, "", "\t") | ||
| if err != nil { | ||
| return newGenericError(err, SystemError) | ||
| } | ||
|
|
||
| fnew := filepath.Join(c.root, fmt.Sprintf("%s.new", stateFilename)) | ||
| f, err := os.Create(fnew) | ||
| if err != nil { | ||
| return newGenericError(err, SystemError) | ||
| } | ||
|
|
||
| _, err = f.Write(data) | ||
| if err != nil { | ||
| f.Close() | ||
| return newGenericError(err, SystemError) | ||
| } | ||
| f.Close() | ||
|
|
||
| fname := filepath.Join(c.root, stateFilename) | ||
| if err := os.Rename(fnew, fname); err != nil { | ||
| return newGenericError(err, SystemError) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (c *linuxContainer) startInitProcess(config *ProcessConfig) error { | ||
| cmd := exec.Command(c.initArgs[0], append(c.initArgs[1:], config.Args...)...) | ||
| cmd.Stdin = config.Stdin | ||
| cmd.Stdout = config.Stdout | ||
| cmd.Stderr = config.Stderr | ||
|
|
||
| cmd.Env = config.Env | ||
| cmd.Dir = c.config.RootFs | ||
|
|
||
| if cmd.SysProcAttr == nil { | ||
| cmd.SysProcAttr = &syscall.SysProcAttr{} | ||
| } | ||
|
|
||
| cmd.SysProcAttr.Pdeathsig = syscall.SIGKILL | ||
|
|
||
| //FIXME call namespaces.Exec() | ||
| if err := cmd.Start(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| c.state.InitPid = cmd.Process.Pid | ||
| err := c.updateStateFile() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (c *linuxContainer) Destroy() error { | ||
| glog.Info("destroy container") | ||
| panic("not implemented") | ||
| state, err := c.RunState() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if state != Destroyed { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably fine for now, but eventually I do believe we want to be destructive by default. |
||
| return newGenericError(nil, ContainerNotStopped) | ||
| } | ||
|
|
||
| os.RemoveAll(c.root) | ||
| return nil | ||
| } | ||
|
|
||
| func (c *linuxContainer) Pause() error { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| all: | ||
| go build -o nsinit . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we should switch depending on whether the init exists or not. This is a good place to start. Not at all something to do now :) but maybe worth a TODO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the previous if statement does this. If a container isn't "Destroyed", a new processes will be executed in the existing container. Or do you mean something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aaaah yes I see, ignore me.