diff --git a/main.go b/main.go index 1b0df8a2..79561957 100644 --- a/main.go +++ b/main.go @@ -96,8 +96,8 @@ func main() { psCommand, restoreCommand, resumeCommand, + runCommand, specCommand, - startCommand, stateCommand, updateCommand, } diff --git a/main_unix.go b/main_unix.go index 7bbec9fa..da14caba 100644 --- a/main_unix.go +++ b/main_unix.go @@ -2,4 +2,32 @@ package main -import _ "github.com/opencontainers/runc/libcontainer/nsenter" +import ( + "os" + "runtime" + + "github.com/codegangsta/cli" + "github.com/opencontainers/runc/libcontainer" + _ "github.com/opencontainers/runc/libcontainer/nsenter" +) + +func init() { + if len(os.Args) > 1 && os.Args[1] == "init" { + runtime.GOMAXPROCS(1) + runtime.LockOSThread() + } +} + +var initCommand = cli.Command{ + Name: "init", + Usage: `initialize the namespaces and launch the process (do not call it outside of runc)`, + Action: func(context *cli.Context) { + factory, _ := libcontainer.New("") + if err := factory.StartInitialization(); err != nil { + // as the error is sent back to the parent there is no need to log + // or write it to stderr because the parent process will handle this + os.Exit(1) + } + panic("libcontainer: container init failed to exec") + }, +} diff --git a/start.go b/run.go similarity index 79% rename from start.go rename to run.go index cf9392c2..d999f49c 100644 --- a/start.go +++ b/run.go @@ -5,24 +5,22 @@ package main import ( "fmt" "os" - "runtime" "github.com/codegangsta/cli" "github.com/coreos/go-systemd/activation" - "github.com/opencontainers/runc/libcontainer" "github.com/opencontainers/runtime-spec/specs-go" ) // default action is to start a container -var startCommand = cli.Command{ - Name: "start", +var runCommand = cli.Command{ + Name: "run", Usage: "create and run a container", ArgsUsage: ` Where "" is your name for the instance of the container that you are starting. The name you provide for the container instance must be unique on your host.`, - Description: `The start command creates an instance of a container for a bundle. The bundle + Description: `The run command creates an instance of a container for a bundle. The bundle is a directory with a specification file named "` + specConfig + `" and a root filesystem. @@ -90,27 +88,6 @@ command(s) that get executed on start, edit the args parameter of the spec. See }, } -func init() { - if len(os.Args) > 1 && os.Args[1] == "init" { - runtime.GOMAXPROCS(1) - runtime.LockOSThread() - } -} - -var initCommand = cli.Command{ - Name: "init", - Usage: `initialize the namespaces and launch the process (do not call it outside of runc)`, - Action: func(context *cli.Context) error { - factory, _ := libcontainer.New("") - if err := factory.StartInitialization(); err != nil { - // as the error is sent back to the parent there is no need to log - // or write it to stderr because the parent process will handle this - os.Exit(1) - } - panic("libcontainer: container init failed to exec") - }, -} - func startContainer(context *cli.Context, spec *specs.Spec) (int, error) { id := context.Args().First() if id == "" { diff --git a/tests/integration/cgroups.bats b/tests/integration/cgroups.bats index 0f98514f..c415d5da 100644 --- a/tests/integration/cgroups.bats +++ b/tests/integration/cgroups.bats @@ -47,8 +47,8 @@ EOF DATA=$(echo ${DATA} | sed 's/\n/\\n/g') sed -i "s/\(\"resources\": {\)/\1\n${DATA}/" ${BUSYBOX_BUNDLE}/config.json - # start a detached busybox to work with - runc start -d --console /dev/pts/ptmx test_cgroups_kmem + # run a detached busybox to work with + runc run -d --console /dev/pts/ptmx test_cgroups_kmem [ "$status" -eq 0 ] wait_for_container 15 1 test_cgroups_kmem @@ -64,8 +64,8 @@ EOF # Add cgroup path sed -i 's/\("linux": {\)/\1\n "cgroupsPath": "runc-cgroups-integration-test",/' ${BUSYBOX_BUNDLE}/config.json - # start a detached busybox to work with - runc start -d --console /dev/pts/ptmx test_cgroups_kmem + # run a detached busybox to work with + runc run -d --console /dev/pts/ptmx test_cgroups_kmem [ "$status" -eq 0 ] wait_for_container 15 1 test_cgroups_kmem diff --git a/tests/integration/checkpoint.bats b/tests/integration/checkpoint.bats index 97194d03..4a369396 100644 --- a/tests/integration/checkpoint.bats +++ b/tests/integration/checkpoint.bats @@ -21,8 +21,8 @@ function teardown() { sed -i 's/"sh"/"sh","-c","while :; do date; sleep 1; done"/' config.json ( - # start busybox (not detached) - runc start test_busybox + # run busybox (not detached) + runc run test_busybox [ "$status" -eq 0 ] ) & diff --git a/tests/integration/debug.bats b/tests/integration/debug.bats index 5473b4b6..971bc7e1 100644 --- a/tests/integration/debug.bats +++ b/tests/integration/debug.bats @@ -12,15 +12,15 @@ function teardown() { } @test "global --debug" { - # start hello-world - runc --debug start test_hello + # run hello-world + runc --debug run test_hello echo "${output}" [ "$status" -eq 0 ] } @test "global --debug to --log" { - # start hello-world - runc --log log.out --debug start test_hello + # run hello-world + runc --log log.out --debug run test_hello [ "$status" -eq 0 ] # check output does not include debug info @@ -36,8 +36,8 @@ function teardown() { } @test "global --debug to --log --log-format 'text'" { - # start hello-world - runc --log log.out --log-format "text" --debug start test_hello + # run hello-world + runc --log log.out --log-format "text" --debug run test_hello [ "$status" -eq 0 ] # check output does not include debug info @@ -53,8 +53,8 @@ function teardown() { } @test "global --debug to --log --log-format 'json'" { - # start hello-world - runc --log log.out --log-format "json" --debug start test_hello + # run hello-world + runc --log log.out --log-format "json" --debug run test_hello [ "$status" -eq 0 ] # check output does not include debug info diff --git a/tests/integration/delete.bats b/tests/integration/delete.bats index ec102b79..8e0e2948 100644 --- a/tests/integration/delete.bats +++ b/tests/integration/delete.bats @@ -12,8 +12,8 @@ function teardown() { } @test "runc delete" { - # start busybox detached - runc start -d --console /dev/pts/ptmx test_busybox + # run busybox detached + runc run -d --console /dev/pts/ptmx test_busybox [ "$status" -eq 0 ] # check state diff --git a/tests/integration/events.bats b/tests/integration/events.bats index 81d245c9..18855d5e 100644 --- a/tests/integration/events.bats +++ b/tests/integration/events.bats @@ -12,8 +12,8 @@ function teardown() { } @test "events --stats" { - # start busybox detached - runc start -d --console /dev/pts/ptmx test_busybox + # run busybox detached + runc run -d --console /dev/pts/ptmx test_busybox [ "$status" -eq 0 ] # check state @@ -27,8 +27,8 @@ function teardown() { } @test "events --interval default " { - # start busybox detached - runc start -d --console /dev/pts/ptmx test_busybox + # run busybox detached + runc run -d --console /dev/pts/ptmx test_busybox [ "$status" -eq 0 ] # check state @@ -54,8 +54,8 @@ function teardown() { } @test "events --interval 1s " { - # start busybox detached - runc start -d --console /dev/pts/ptmx test_busybox + # run busybox detached + runc run -d --console /dev/pts/ptmx test_busybox [ "$status" -eq 0 ] # check state @@ -80,8 +80,8 @@ function teardown() { } @test "events --interval 100ms " { - # start busybox detached - runc start -d --console /dev/pts/ptmx test_busybox + # run busybox detached + runc run -d --console /dev/pts/ptmx test_busybox [ "$status" -eq 0 ] # check state diff --git a/tests/integration/help.bats b/tests/integration/help.bats index d7d873b3..61a62d8b 100644 --- a/tests/integration/help.bats +++ b/tests/integration/help.bats @@ -64,7 +64,11 @@ load helpers runc start -h [ "$status" -eq 0 ] [[ ${lines[1]} =~ runc\ start+ ]] - + + runc run -h + [ "$status" -eq 0 ] + [[ ${lines[1]} =~ runc\ run+ ]] + runc state -h [ "$status" -eq 0 ] [[ ${lines[1]} =~ runc\ state+ ]] diff --git a/tests/integration/kill.bats b/tests/integration/kill.bats index ccc03545..e688db00 100644 --- a/tests/integration/kill.bats +++ b/tests/integration/kill.bats @@ -14,8 +14,8 @@ function teardown() { @test "kill detached busybox" { - # start busybox detached - runc start -d --console /dev/pts/ptmx test_busybox + # run busybox detached + runc run -d --console /dev/pts/ptmx test_busybox [ "$status" -eq 0 ] # check state diff --git a/tests/integration/list.bats b/tests/integration/list.bats index 4caff04b..c63a9aa4 100644 --- a/tests/integration/list.bats +++ b/tests/integration/list.bats @@ -18,16 +18,16 @@ function teardown() { } @test "list" { - # start a few busyboxes detached - ROOT=$HELLO_BUNDLE runc start -d --console /dev/pts/ptmx test_box1 + # run a few busyboxes detached + ROOT=$HELLO_BUNDLE runc run -d --console /dev/pts/ptmx test_box1 [ "$status" -eq 0 ] wait_for_container_inroot 15 1 test_box1 $HELLO_BUNDLE - ROOT=$HELLO_BUNDLE runc start -d --console /dev/pts/ptmx test_box2 + ROOT=$HELLO_BUNDLE runc run -d --console /dev/pts/ptmx test_box2 [ "$status" -eq 0 ] wait_for_container_inroot 15 1 test_box2 $HELLO_BUNDLE - ROOT=$HELLO_BUNDLE runc start -d --console /dev/pts/ptmx test_box3 + ROOT=$HELLO_BUNDLE runc run -d --console /dev/pts/ptmx test_box3 [ "$status" -eq 0 ] wait_for_container_inroot 15 1 test_box3 $HELLO_BUNDLE diff --git a/tests/integration/pause.bats b/tests/integration/pause.bats index 94ad3fc0..ed12f4a6 100644 --- a/tests/integration/pause.bats +++ b/tests/integration/pause.bats @@ -12,8 +12,8 @@ function teardown() { } @test "runc pause and resume" { - # start busybox detached - runc start -d --console /dev/pts/ptmx test_busybox + # run busybox detached + runc run -d --console /dev/pts/ptmx test_busybox [ "$status" -eq 0 ] wait_for_container 15 1 test_busybox diff --git a/tests/integration/root.bats b/tests/integration/root.bats index 8ee79996..f4a7ff0d 100644 --- a/tests/integration/root.bats +++ b/tests/integration/root.bats @@ -14,12 +14,12 @@ function teardown() { } @test "global --root" { - # start busybox detached using $HELLO_BUNDLE for state - ROOT=$HELLO_BUNDLE runc start -d --console /dev/pts/ptmx test_dotbox + # run busybox detached using $HELLO_BUNDLE for state + ROOT=$HELLO_BUNDLE runc run -d --console /dev/pts/ptmx test_dotbox [ "$status" -eq 0 ] - # start busybox detached in default root - runc start -d --console /dev/pts/ptmx test_busybox + # run busybox detached in default root + runc run -d --console /dev/pts/ptmx test_busybox [ "$status" -eq 0 ] # check state of the busyboxes are only in their respective root path diff --git a/tests/integration/spec.bats b/tests/integration/spec.bats index ef29710a..c0c2537b 100644 --- a/tests/integration/spec.bats +++ b/tests/integration/spec.bats @@ -39,8 +39,8 @@ function teardown() { # change the default args parameter from sh to hello sed -i 's;"sh";"/hello";' config.json - # ensure the generated spec works by starting hello-world - runc start test_hello + # ensure the generated spec works by running hello-world + runc run test_hello [ "$status" -eq 0 ] } @@ -60,8 +60,8 @@ function teardown() { # change the default args parameter from sh to hello sed -i 's;"sh";"/hello";' "$HELLO_BUNDLE"/config.json - # ensure the generated spec works by starting hello-world - runc start --bundle "$HELLO_BUNDLE" test_hello + # ensure the generated spec works by running hello-world + runc run --bundle "$HELLO_BUNDLE" test_hello [ "$status" -eq 0 ] } diff --git a/tests/integration/start_detached.bats b/tests/integration/start_detached.bats index c88fbae1..e9df8e8b 100644 --- a/tests/integration/start_detached.bats +++ b/tests/integration/start_detached.bats @@ -11,9 +11,9 @@ function teardown() { teardown_busybox } -@test "runc start detached" { - # start busybox detached - runc start -d --console /dev/pts/ptmx test_busybox +@test "runc run detached" { + # run busybox detached + runc run -d --console /dev/pts/ptmx test_busybox [ "$status" -eq 0 ] # check state @@ -22,9 +22,9 @@ function teardown() { testcontainer test_busybox running } -@test "runc start detached --pid-file" { - # start busybox detached - runc start --pid-file pid.txt -d --console /dev/pts/ptmx test_busybox +@test "runc run detached --pid-file" { + # run busybox detached + runc run --pid-file pid.txt -d --console /dev/pts/ptmx test_busybox [ "$status" -eq 0 ] # check state diff --git a/tests/integration/start_hello.bats b/tests/integration/start_hello.bats index bba51771..cddc2be3 100644 --- a/tests/integration/start_hello.bats +++ b/tests/integration/start_hello.bats @@ -11,30 +11,30 @@ function teardown() { teardown_hello } -@test "runc start" { - # start hello-world - runc start test_hello +@test "runc run" { + # run hello-world + runc run test_hello [ "$status" -eq 0 ] # check expected output [[ "${output}" == *"Hello"* ]] } -@test "runc start with rootfs set to ." { +@test "runc run with rootfs set to ." { cp config.json rootfs/. rm config.json cd rootfs sed -i 's;"rootfs";".";' config.json - # start hello-world - runc start test_hello + # run hello-world + runc run test_hello [ "$status" -eq 0 ] [[ "${output}" == *"Hello"* ]] } -@test "runc start --pid-file" { - # start hello-world - runc start --pid-file pid.txt test_hello +@test "runc run --pid-file" { + # run hello-world + runc run --pid-file pid.txt test_hello [ "$status" -eq 0 ] [[ "${output}" == *"Hello"* ]] diff --git a/tests/integration/state.bats b/tests/integration/state.bats index 697bd495..582986d3 100644 --- a/tests/integration/state.bats +++ b/tests/integration/state.bats @@ -15,8 +15,8 @@ function teardown() { runc state test_busybox [ "$status" -ne 0 ] - # start busybox detached - runc start -d --console /dev/pts/ptmx test_busybox + # run busybox detached + runc run -d --console /dev/pts/ptmx test_busybox [ "$status" -eq 0 ] # check state diff --git a/tests/integration/update.bats b/tests/integration/update.bats index 991accd6..bd164d19 100644 --- a/tests/integration/update.bats +++ b/tests/integration/update.bats @@ -48,8 +48,8 @@ function check_cgroup_value() { } @test "update" { - # start a few busyboxes detached - runc start -d --console /dev/pts/ptmx test_update + # run a few busyboxes detached + runc run -d --console /dev/pts/ptmx test_update [ "$status" -eq 0 ] wait_for_container 15 1 test_update