Rename start to run

`runc run` is the command that will create and start a container in one
single command.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2016-05-13 15:49:45 -07:00
parent 88bb59e35f
commit 75fb70be01
18 changed files with 97 additions and 88 deletions

View File

@ -96,8 +96,8 @@ func main() {
psCommand, psCommand,
restoreCommand, restoreCommand,
resumeCommand, resumeCommand,
runCommand,
specCommand, specCommand,
startCommand,
stateCommand, stateCommand,
updateCommand, updateCommand,
} }

View File

@ -2,4 +2,32 @@
package main 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")
},
}

View File

@ -5,24 +5,22 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"runtime"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/coreos/go-systemd/activation" "github.com/coreos/go-systemd/activation"
"github.com/opencontainers/runc/libcontainer"
"github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-spec/specs-go"
) )
// default action is to start a container // default action is to start a container
var startCommand = cli.Command{ var runCommand = cli.Command{
Name: "start", Name: "run",
Usage: "create and run a container", Usage: "create and run a container",
ArgsUsage: `<container-id> ArgsUsage: `<container-id>
Where "<container-id>" is your name for the instance of the container that you Where "<container-id>" 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 are starting. The name you provide for the container instance must be unique on
your host.`, 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 is a directory with a specification file named "` + specConfig + `" and a root
filesystem. 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) { func startContainer(context *cli.Context, spec *specs.Spec) (int, error) {
id := context.Args().First() id := context.Args().First()
if id == "" { if id == "" {

View File

@ -47,8 +47,8 @@ EOF
DATA=$(echo ${DATA} | sed 's/\n/\\n/g') DATA=$(echo ${DATA} | sed 's/\n/\\n/g')
sed -i "s/\(\"resources\": {\)/\1\n${DATA}/" ${BUSYBOX_BUNDLE}/config.json sed -i "s/\(\"resources\": {\)/\1\n${DATA}/" ${BUSYBOX_BUNDLE}/config.json
# start a detached busybox to work with # run a detached busybox to work with
runc start -d --console /dev/pts/ptmx test_cgroups_kmem runc run -d --console /dev/pts/ptmx test_cgroups_kmem
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
wait_for_container 15 1 test_cgroups_kmem wait_for_container 15 1 test_cgroups_kmem
@ -64,8 +64,8 @@ EOF
# Add cgroup path # Add cgroup path
sed -i 's/\("linux": {\)/\1\n "cgroupsPath": "runc-cgroups-integration-test",/' ${BUSYBOX_BUNDLE}/config.json sed -i 's/\("linux": {\)/\1\n "cgroupsPath": "runc-cgroups-integration-test",/' ${BUSYBOX_BUNDLE}/config.json
# start a detached busybox to work with # run a detached busybox to work with
runc start -d --console /dev/pts/ptmx test_cgroups_kmem runc run -d --console /dev/pts/ptmx test_cgroups_kmem
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
wait_for_container 15 1 test_cgroups_kmem wait_for_container 15 1 test_cgroups_kmem

View File

@ -21,8 +21,8 @@ function teardown() {
sed -i 's/"sh"/"sh","-c","while :; do date; sleep 1; done"/' config.json sed -i 's/"sh"/"sh","-c","while :; do date; sleep 1; done"/' config.json
( (
# start busybox (not detached) # run busybox (not detached)
runc start test_busybox runc run test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
) & ) &

View File

@ -12,15 +12,15 @@ function teardown() {
} }
@test "global --debug" { @test "global --debug" {
# start hello-world # run hello-world
runc --debug start test_hello runc --debug run test_hello
echo "${output}" echo "${output}"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
} }
@test "global --debug to --log" { @test "global --debug to --log" {
# start hello-world # run hello-world
runc --log log.out --debug start test_hello runc --log log.out --debug run test_hello
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check output does not include debug info # check output does not include debug info
@ -36,8 +36,8 @@ function teardown() {
} }
@test "global --debug to --log --log-format 'text'" { @test "global --debug to --log --log-format 'text'" {
# start hello-world # run hello-world
runc --log log.out --log-format "text" --debug start test_hello runc --log log.out --log-format "text" --debug run test_hello
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check output does not include debug info # check output does not include debug info
@ -53,8 +53,8 @@ function teardown() {
} }
@test "global --debug to --log --log-format 'json'" { @test "global --debug to --log --log-format 'json'" {
# start hello-world # run hello-world
runc --log log.out --log-format "json" --debug start test_hello runc --log log.out --log-format "json" --debug run test_hello
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check output does not include debug info # check output does not include debug info

View File

@ -12,8 +12,8 @@ function teardown() {
} }
@test "runc delete" { @test "runc delete" {
# start busybox detached # run busybox detached
runc start -d --console /dev/pts/ptmx test_busybox runc run -d --console /dev/pts/ptmx test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state

View File

@ -12,8 +12,8 @@ function teardown() {
} }
@test "events --stats" { @test "events --stats" {
# start busybox detached # run busybox detached
runc start -d --console /dev/pts/ptmx test_busybox runc run -d --console /dev/pts/ptmx test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state
@ -27,8 +27,8 @@ function teardown() {
} }
@test "events --interval default " { @test "events --interval default " {
# start busybox detached # run busybox detached
runc start -d --console /dev/pts/ptmx test_busybox runc run -d --console /dev/pts/ptmx test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state
@ -54,8 +54,8 @@ function teardown() {
} }
@test "events --interval 1s " { @test "events --interval 1s " {
# start busybox detached # run busybox detached
runc start -d --console /dev/pts/ptmx test_busybox runc run -d --console /dev/pts/ptmx test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state
@ -80,8 +80,8 @@ function teardown() {
} }
@test "events --interval 100ms " { @test "events --interval 100ms " {
# start busybox detached # run busybox detached
runc start -d --console /dev/pts/ptmx test_busybox runc run -d --console /dev/pts/ptmx test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state

View File

@ -65,6 +65,10 @@ load helpers
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[1]} =~ runc\ start+ ]] [[ ${lines[1]} =~ runc\ start+ ]]
runc run -h
[ "$status" -eq 0 ]
[[ ${lines[1]} =~ runc\ run+ ]]
runc state -h runc state -h
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ ${lines[1]} =~ runc\ state+ ]] [[ ${lines[1]} =~ runc\ state+ ]]

View File

@ -14,8 +14,8 @@ function teardown() {
@test "kill detached busybox" { @test "kill detached busybox" {
# start busybox detached # run busybox detached
runc start -d --console /dev/pts/ptmx test_busybox runc run -d --console /dev/pts/ptmx test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state

View File

@ -18,16 +18,16 @@ function teardown() {
} }
@test "list" { @test "list" {
# start a few busyboxes detached # run a few busyboxes detached
ROOT=$HELLO_BUNDLE runc start -d --console /dev/pts/ptmx test_box1 ROOT=$HELLO_BUNDLE runc run -d --console /dev/pts/ptmx test_box1
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
wait_for_container_inroot 15 1 test_box1 $HELLO_BUNDLE 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 ] [ "$status" -eq 0 ]
wait_for_container_inroot 15 1 test_box2 $HELLO_BUNDLE 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 ] [ "$status" -eq 0 ]
wait_for_container_inroot 15 1 test_box3 $HELLO_BUNDLE wait_for_container_inroot 15 1 test_box3 $HELLO_BUNDLE

View File

@ -12,8 +12,8 @@ function teardown() {
} }
@test "runc pause and resume" { @test "runc pause and resume" {
# start busybox detached # run busybox detached
runc start -d --console /dev/pts/ptmx test_busybox runc run -d --console /dev/pts/ptmx test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
wait_for_container 15 1 test_busybox wait_for_container 15 1 test_busybox

View File

@ -14,12 +14,12 @@ function teardown() {
} }
@test "global --root" { @test "global --root" {
# start busybox detached using $HELLO_BUNDLE for state # run busybox detached using $HELLO_BUNDLE for state
ROOT=$HELLO_BUNDLE runc start -d --console /dev/pts/ptmx test_dotbox ROOT=$HELLO_BUNDLE runc run -d --console /dev/pts/ptmx test_dotbox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# start busybox detached in default root # run busybox detached in default root
runc start -d --console /dev/pts/ptmx test_busybox runc run -d --console /dev/pts/ptmx test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state of the busyboxes are only in their respective root path # check state of the busyboxes are only in their respective root path

View File

@ -39,8 +39,8 @@ function teardown() {
# change the default args parameter from sh to hello # change the default args parameter from sh to hello
sed -i 's;"sh";"/hello";' config.json sed -i 's;"sh";"/hello";' config.json
# ensure the generated spec works by starting hello-world # ensure the generated spec works by running hello-world
runc start test_hello runc run test_hello
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
} }
@ -60,8 +60,8 @@ function teardown() {
# change the default args parameter from sh to hello # change the default args parameter from sh to hello
sed -i 's;"sh";"/hello";' "$HELLO_BUNDLE"/config.json sed -i 's;"sh";"/hello";' "$HELLO_BUNDLE"/config.json
# ensure the generated spec works by starting hello-world # ensure the generated spec works by running hello-world
runc start --bundle "$HELLO_BUNDLE" test_hello runc run --bundle "$HELLO_BUNDLE" test_hello
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
} }

View File

@ -11,9 +11,9 @@ function teardown() {
teardown_busybox teardown_busybox
} }
@test "runc start detached" { @test "runc run detached" {
# start busybox detached # run busybox detached
runc start -d --console /dev/pts/ptmx test_busybox runc run -d --console /dev/pts/ptmx test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state
@ -22,9 +22,9 @@ function teardown() {
testcontainer test_busybox running testcontainer test_busybox running
} }
@test "runc start detached --pid-file" { @test "runc run detached --pid-file" {
# start busybox detached # run busybox detached
runc start --pid-file pid.txt -d --console /dev/pts/ptmx test_busybox runc run --pid-file pid.txt -d --console /dev/pts/ptmx test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state

View File

@ -11,30 +11,30 @@ function teardown() {
teardown_hello teardown_hello
} }
@test "runc start" { @test "runc run" {
# start hello-world # run hello-world
runc start test_hello runc run test_hello
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check expected output # check expected output
[[ "${output}" == *"Hello"* ]] [[ "${output}" == *"Hello"* ]]
} }
@test "runc start with rootfs set to ." { @test "runc run with rootfs set to ." {
cp config.json rootfs/. cp config.json rootfs/.
rm config.json rm config.json
cd rootfs cd rootfs
sed -i 's;"rootfs";".";' config.json sed -i 's;"rootfs";".";' config.json
# start hello-world # run hello-world
runc start test_hello runc run test_hello
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "${output}" == *"Hello"* ]] [[ "${output}" == *"Hello"* ]]
} }
@test "runc start --pid-file" { @test "runc run --pid-file" {
# start hello-world # run hello-world
runc start --pid-file pid.txt test_hello runc run --pid-file pid.txt test_hello
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "${output}" == *"Hello"* ]] [[ "${output}" == *"Hello"* ]]

View File

@ -15,8 +15,8 @@ function teardown() {
runc state test_busybox runc state test_busybox
[ "$status" -ne 0 ] [ "$status" -ne 0 ]
# start busybox detached # run busybox detached
runc start -d --console /dev/pts/ptmx test_busybox runc run -d --console /dev/pts/ptmx test_busybox
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
# check state # check state

View File

@ -48,8 +48,8 @@ function check_cgroup_value() {
} }
@test "update" { @test "update" {
# start a few busyboxes detached # run a few busyboxes detached
runc start -d --console /dev/pts/ptmx test_update runc run -d --console /dev/pts/ptmx test_update
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
wait_for_container 15 1 test_update wait_for_container 15 1 test_update