Skip to content

Commit cb82462

Browse files
lifubangkolyshkin
authored andcommitted
proposal: add --keep to runc run
Signed-off-by: lifubang <[email protected]>
1 parent 2aabb29 commit cb82462

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

run.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ command(s) that get executed on start, edit the args parameter of the spec. See
4040
Name: "detach, d",
4141
Usage: "detach from the container's process",
4242
},
43+
cli.BoolFlag{
44+
Name: "keep",
45+
Usage: "do not delete the container after it exits",
46+
},
4347
cli.StringFlag{
4448
Name: "pid-file",
4549
Value: "",

tests/integration/run.bats

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bats
2+
3+
load helpers
4+
5+
function setup() {
6+
setup_hello
7+
}
8+
9+
function teardown() {
10+
teardown_bundle
11+
}
12+
13+
@test "runc run" {
14+
runc run test_hello
15+
[ "$status" -eq 0 ]
16+
17+
runc state test_hello
18+
[ "$status" -ne 0 ]
19+
}
20+
21+
@test "runc run --keep" {
22+
runc run --keep test_run_keep
23+
[ "$status" -eq 0 ]
24+
25+
testcontainer test_run_keep stopped
26+
27+
runc state test_run_keep
28+
[ "$status" -eq 0 ]
29+
30+
runc delete test_run_keep
31+
32+
runc state test_run_keep
33+
[ "$status" -ne 0 ]
34+
}
35+
36+
@test "runc run --keep (check cgroup exists)" {
37+
# for systemd driver, the unit's cgroup path will be auto removed if container's all processes exited
38+
requires no_systemd
39+
40+
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
41+
42+
set_cgroups_path
43+
44+
runc run --keep test_run_keep
45+
[ "$status" -eq 0 ]
46+
47+
testcontainer test_run_keep stopped
48+
49+
runc state test_run_keep
50+
[ "$status" -eq 0 ]
51+
52+
# check that cgroup exists
53+
check_cgroup_value "pids.max" "max"
54+
55+
runc delete test_run_keep
56+
57+
runc state test_run_keep
58+
[ "$status" -ne 0 ]
59+
}

utils_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ func startContainer(context *cli.Context, spec *specs.Spec, action CtAct, criuOp
439439

440440
r := &runner{
441441
enableSubreaper: !context.Bool("no-subreaper"),
442-
shouldDestroy: true,
442+
shouldDestroy: !context.Bool("keep"),
443443
container: container,
444444
listenFDs: listenFDs,
445445
notifySocket: notifySocket,

0 commit comments

Comments
 (0)