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,
restoreCommand,
resumeCommand,
runCommand,
specCommand,
startCommand,
stateCommand,
updateCommand,
}

View File

@ -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")
},
}

View File

@ -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: `<container-id>
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
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 == "" {

View File

@ -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

View File

@ -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 ]
) &

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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+ ]]

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 ]
}

View File

@ -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

View File

@ -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"* ]]

View File

@ -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

View File

@ -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