Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
moby
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
emulab
moby
Commits
95e066d2
Commit
95e066d2
authored
11 years ago
by
Solomon Hykes
Browse files
Options
Downloads
Plain Diff
- Runtime: ghost containers can be killed.
parents
82b8f7a5
b76d63cb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
commands.go
+4
-0
4 additions, 0 deletions
commands.go
container.go
+34
-11
34 additions, 11 deletions
container.go
runtime.go
+9
-6
9 additions, 6 deletions
runtime.go
with
47 additions
and
17 deletions
commands.go
+
4
−
0
View file @
95e066d2
...
...
@@ -836,6 +836,10 @@ func (srv *Server) CmdAttach(stdin io.ReadCloser, stdout rcli.DockerConn, args .
return
fmt
.
Errorf
(
"No such container: %s"
,
name
)
}
if
container
.
State
.
Ghost
{
return
fmt
.
Errorf
(
"Impossible to attach to a ghost container"
)
}
if
container
.
Config
.
Tty
{
stdout
.
SetOptionRawTerminal
()
}
...
...
This diff is collapsed.
Click to expand it.
container.go
+
34
−
11
View file @
95e066d2
...
...
@@ -530,16 +530,42 @@ func (container *Container) releaseNetwork() {
container
.
NetworkSettings
=
&
NetworkSettings
{}
}
// FIXME: replace this with a control socket within docker-init
func
(
container
*
Container
)
waitLxc
()
error
{
for
{
if
output
,
err
:=
exec
.
Command
(
"lxc-info"
,
"-n"
,
container
.
Id
)
.
CombinedOutput
();
err
!=
nil
{
return
err
}
else
{
if
!
strings
.
Contains
(
string
(
output
),
"RUNNING"
)
{
return
nil
}
}
time
.
Sleep
(
500
*
time
.
Millisecond
)
}
return
nil
}
func
(
container
*
Container
)
monitor
()
{
// Wait for the program to exit
Debugf
(
"Waiting for process"
)
if
err
:=
container
.
cmd
.
Wait
();
err
!=
nil
{
// Discard the error as any signals or non 0 returns will generate an error
Debugf
(
"%s: Process: %s"
,
container
.
Id
,
err
)
// If the command does not exists, try to wait via lxc
if
container
.
cmd
==
nil
{
if
err
:=
container
.
waitLxc
();
err
!=
nil
{
Debugf
(
"%s: Process: %s"
,
container
.
Id
,
err
)
}
}
else
{
if
err
:=
container
.
cmd
.
Wait
();
err
!=
nil
{
// Discard the error as any signals or non 0 returns will generate an error
Debugf
(
"%s: Process: %s"
,
container
.
Id
,
err
)
}
}
Debugf
(
"Process finished"
)
exitCode
:=
container
.
cmd
.
ProcessState
.
Sys
()
.
(
syscall
.
WaitStatus
)
.
ExitStatus
()
var
exitCode
int
=
-
1
if
container
.
cmd
!=
nil
{
exitCode
=
container
.
cmd
.
ProcessState
.
Sys
()
.
(
syscall
.
WaitStatus
)
.
ExitStatus
()
}
// Cleanup
container
.
releaseNetwork
()
...
...
@@ -588,7 +614,7 @@ func (container *Container) monitor() {
}
func
(
container
*
Container
)
kill
()
error
{
if
!
container
.
State
.
Running
||
container
.
cmd
==
nil
{
if
!
container
.
State
.
Running
{
return
nil
}
...
...
@@ -600,6 +626,9 @@ func (container *Container) kill() error {
// 2. Wait for the process to die, in last resort, try to kill the process directly
if
err
:=
container
.
WaitTimeout
(
10
*
time
.
Second
);
err
!=
nil
{
if
container
.
cmd
==
nil
{
return
fmt
.
Errorf
(
"lxc-kill failed, impossible to kill the container %s"
,
container
.
Id
)
}
log
.
Printf
(
"Container %s failed to exit within 10 seconds of lxc SIGKILL - trying direct SIGKILL"
,
container
.
Id
)
if
err
:=
container
.
cmd
.
Process
.
Kill
();
err
!=
nil
{
return
err
...
...
@@ -617,9 +646,6 @@ func (container *Container) Kill() error {
if
!
container
.
State
.
Running
{
return
nil
}
if
container
.
State
.
Ghost
{
return
fmt
.
Errorf
(
"Can't kill ghost container"
)
}
return
container
.
kill
()
}
...
...
@@ -629,9 +655,6 @@ func (container *Container) Stop(seconds int) error {
if
!
container
.
State
.
Running
{
return
nil
}
if
container
.
State
.
Ghost
{
return
fmt
.
Errorf
(
"Can't stop ghost container"
)
}
// 1. Send a SIGTERM
if
output
,
err
:=
exec
.
Command
(
"lxc-kill"
,
"-n"
,
container
.
Id
,
"15"
)
.
CombinedOutput
();
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
runtime.go
+
9
−
6
View file @
95e066d2
...
...
@@ -184,12 +184,6 @@ func (runtime *Runtime) Register(container *Container) error {
}
}
// If the container is not running or just has been flagged not running
// then close the wait lock chan (will be reset upon start)
if
!
container
.
State
.
Running
{
close
(
container
.
waitLock
)
}
// Even if not running, we init the lock (prevents races in start/stop/kill)
container
.
State
.
initLock
()
...
...
@@ -207,6 +201,15 @@ func (runtime *Runtime) Register(container *Container) error {
// done
runtime
.
containers
.
PushBack
(
container
)
runtime
.
idIndex
.
Add
(
container
.
Id
)
// If the container is not running or just has been flagged not running
// then close the wait lock chan (will be reset upon start)
if
!
container
.
State
.
Running
{
close
(
container
.
waitLock
)
}
else
{
container
.
allocateNetwork
()
go
container
.
monitor
()
}
return
nil
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment