Merge pull request #541 from crosbymichael/ids
Require container id as arg1
This commit is contained in:
commit
bfd3345be9
10
README.md
10
README.md
|
@ -65,9 +65,11 @@ You can also run specific test cases by:
|
||||||
|
|
||||||
### Using:
|
### Using:
|
||||||
|
|
||||||
To run a container, execute `runc start` in the bundle's root directory:
|
To run a container with the id "test", execute `runc start` with the containers id as arg one
|
||||||
|
in the bundle's root directory:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
runc start
|
runc start test
|
||||||
/ $ ps
|
/ $ ps
|
||||||
PID USER COMMAND
|
PID USER COMMAND
|
||||||
1 daemon sh
|
1 daemon sh
|
||||||
|
@ -98,7 +100,7 @@ tar -C rootfs -xf busybox.tar
|
||||||
* Create `config.json` by using `runc spec`.
|
* Create `config.json` by using `runc spec`.
|
||||||
* Execute `runc start` and you should be placed into a shell where you can run `ps`:
|
* Execute `runc start` and you should be placed into a shell where you can run `ps`:
|
||||||
```
|
```
|
||||||
$ runc start
|
$ runc start test
|
||||||
/ # ps
|
/ # ps
|
||||||
PID USER COMMAND
|
PID USER COMMAND
|
||||||
1 root sh
|
1 root sh
|
||||||
|
@ -120,7 +122,7 @@ After=network.target
|
||||||
[Service]
|
[Service]
|
||||||
CPUQuota=200%
|
CPUQuota=200%
|
||||||
MemoryLimit=1536M
|
MemoryLimit=1536M
|
||||||
ExecStart=/usr/local/bin/runc start
|
ExecStart=/usr/local/bin/runc start minecraft
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
WorkingDirectory=/containers/minecraftbuild
|
WorkingDirectory=/containers/minecraftbuild
|
||||||
|
|
||||||
|
|
2
exec.go
2
exec.go
|
@ -128,7 +128,7 @@ func getProcess(context *cli.Context, bundle string) (*specs.Process, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
p := spec.Process
|
p := spec.Process
|
||||||
p.Args = context.Args()
|
p.Args = context.Args()[1:]
|
||||||
// override the cwd, if passed
|
// override the cwd, if passed
|
||||||
if context.String("cwd") != "" {
|
if context.String("cwd") != "" {
|
||||||
p.Cwd = context.String("cwd")
|
p.Cwd = context.String("cwd")
|
||||||
|
|
2
kill.go
2
kill.go
|
@ -58,7 +58,7 @@ var killCommand = cli.Command{
|
||||||
fatal(err)
|
fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sigstr := context.Args().First()
|
sigstr := context.Args().Get(1)
|
||||||
if sigstr == "" {
|
if sigstr == "" {
|
||||||
sigstr = "SIGTERM"
|
sigstr = "SIGTERM"
|
||||||
}
|
}
|
||||||
|
|
9
main.go
9
main.go
|
@ -10,7 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
version = "0.0.7"
|
version = "0.0.8"
|
||||||
specConfig = "config.json"
|
specConfig = "config.json"
|
||||||
usage = `Open Container Initiative runtime
|
usage = `Open Container Initiative runtime
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ After creating config files for your root filesystem with runc, you can execute
|
||||||
a container in your shell by running:
|
a container in your shell by running:
|
||||||
|
|
||||||
# cd /mycontainer
|
# cd /mycontainer
|
||||||
# runc start [ -b bundle ]
|
# runc start [ -b bundle ] <container-id>
|
||||||
|
|
||||||
If not specified, the default value for the 'bundle' is the current directory.
|
If not specified, the default value for the 'bundle' is the current directory.
|
||||||
'Bundle' is the directory where '` + specConfig + `' must be located.`
|
'Bundle' is the directory where '` + specConfig + `' must be located.`
|
||||||
|
@ -39,11 +39,6 @@ func main() {
|
||||||
app.Usage = usage
|
app.Usage = usage
|
||||||
app.Version = fmt.Sprintf("%s\nspec version %s", version, specs.Version)
|
app.Version = fmt.Sprintf("%s\nspec version %s", version, specs.Version)
|
||||||
app.Flags = []cli.Flag{
|
app.Flags = []cli.Flag{
|
||||||
cli.StringFlag{
|
|
||||||
Name: "id",
|
|
||||||
Value: getDefaultID(),
|
|
||||||
Usage: "specify the ID to be used for the container",
|
|
||||||
},
|
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "debug",
|
Name: "debug",
|
||||||
Usage: "enable debug output for logging",
|
Usage: "enable debug output for logging",
|
||||||
|
|
|
@ -7,10 +7,6 @@ import (
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getDefaultID() string {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
checkpointCommand cli.Command
|
checkpointCommand cli.Command
|
||||||
eventsCommand cli.Command
|
eventsCommand cli.Command
|
||||||
|
|
17
restore.go
17
restore.go
|
@ -66,6 +66,10 @@ var restoreCommand = cli.Command{
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) {
|
Action: func(context *cli.Context) {
|
||||||
imagePath := context.String("image-path")
|
imagePath := context.String("image-path")
|
||||||
|
id := context.Args().First()
|
||||||
|
if id == "" {
|
||||||
|
fatal(errEmptyID)
|
||||||
|
}
|
||||||
if imagePath == "" {
|
if imagePath == "" {
|
||||||
imagePath = getDefaultImagePath(context)
|
imagePath = getDefaultImagePath(context)
|
||||||
}
|
}
|
||||||
|
@ -79,7 +83,7 @@ var restoreCommand = cli.Command{
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatal(err)
|
fatal(err)
|
||||||
}
|
}
|
||||||
config, err := createLibcontainerConfig(context.GlobalString("id"), spec)
|
config, err := createLibcontainerConfig(id, spec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatal(err)
|
fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -92,14 +96,17 @@ var restoreCommand = cli.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
func restoreContainer(context *cli.Context, spec *specs.LinuxSpec, config *configs.Config, imagePath string) (code int, err error) {
|
func restoreContainer(context *cli.Context, spec *specs.LinuxSpec, config *configs.Config, imagePath string) (code int, err error) {
|
||||||
rootuid := 0
|
var (
|
||||||
|
rootuid = 0
|
||||||
|
id = context.Args().First()
|
||||||
|
)
|
||||||
factory, err := loadFactory(context)
|
factory, err := loadFactory(context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
container, err := factory.Load(context.GlobalString("id"))
|
container, err := factory.Load(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
container, err = factory.Create(context.GlobalString("id"), config)
|
container, err = factory.Create(id, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
@ -111,7 +118,7 @@ func restoreContainer(context *cli.Context, spec *specs.LinuxSpec, config *confi
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
if status == libcontainer.Running {
|
if status == libcontainer.Running {
|
||||||
fatal(fmt.Errorf("Container with id %s already running", context.GlobalString("id")))
|
fatal(fmt.Errorf("Container with id %s already running", id))
|
||||||
}
|
}
|
||||||
|
|
||||||
setManageCgroupsMode(context, options)
|
setManageCgroupsMode(context, options)
|
||||||
|
|
10
start.go
10
start.go
|
@ -84,13 +84,17 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func startContainer(context *cli.Context, spec *specs.LinuxSpec) (int, error) {
|
func startContainer(context *cli.Context, spec *specs.LinuxSpec) (int, error) {
|
||||||
config, err := createLibcontainerConfig(context.GlobalString("id"), spec)
|
id := context.Args().First()
|
||||||
|
if id == "" {
|
||||||
|
return -1, errEmptyID
|
||||||
|
}
|
||||||
|
config, err := createLibcontainerConfig(id, spec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(config.Rootfs); err != nil {
|
if _, err := os.Stat(config.Rootfs); err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return -1, fmt.Errorf("Rootfs (%q) does not exist", config.Rootfs)
|
return -1, fmt.Errorf("rootfs (%q) does not exist", config.Rootfs)
|
||||||
}
|
}
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
@ -102,7 +106,7 @@ func startContainer(context *cli.Context, spec *specs.LinuxSpec) (int, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
container, err := factory.Create(context.GlobalString("id"), config)
|
container, err := factory.Create(id, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
|
24
utils.go
24
utils.go
|
@ -3,6 +3,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -17,6 +18,8 @@ import (
|
||||||
|
|
||||||
const wildcard = -1
|
const wildcard = -1
|
||||||
|
|
||||||
|
var errEmptyID = errors.New("container id cannot be empty")
|
||||||
|
|
||||||
var allowedDevices = []*configs.Device{
|
var allowedDevices = []*configs.Device{
|
||||||
// allow mknod for any device
|
// allow mknod for any device
|
||||||
{
|
{
|
||||||
|
@ -160,15 +163,15 @@ func loadFactory(context *cli.Context) (libcontainer.Factory, error) {
|
||||||
// getContainer returns the specified container instance by loading it from state
|
// getContainer returns the specified container instance by loading it from state
|
||||||
// with the default factory.
|
// with the default factory.
|
||||||
func getContainer(context *cli.Context) (libcontainer.Container, error) {
|
func getContainer(context *cli.Context) (libcontainer.Container, error) {
|
||||||
|
id := context.Args().First()
|
||||||
|
if id == "" {
|
||||||
|
return nil, errEmptyID
|
||||||
|
}
|
||||||
factory, err := loadFactory(context)
|
factory, err := loadFactory(context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
container, err := factory.Load(context.GlobalString("id"))
|
return factory.Load(id)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return container, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fatal prints the error's details if it is a libcontainer specific error type
|
// fatal prints the error's details if it is a libcontainer specific error type
|
||||||
|
@ -182,17 +185,6 @@ func fatal(err error) {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getDefaultID returns a string to be used as the container id based on the
|
|
||||||
// current working directory of the runc process. This function panics
|
|
||||||
// if the cwd is unable to be found based on a system error.
|
|
||||||
func getDefaultID() string {
|
|
||||||
cwd, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return filepath.Base(cwd)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getDefaultImagePath(context *cli.Context) string {
|
func getDefaultImagePath(context *cli.Context) string {
|
||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue