Browse code

Update based on comments from the code review

Signed-off-by: Michael Crosby <michael@docker.com>

Michael Crosby authored on 2014/08/14 06:56:35
Showing 2 changed files
... ...
@@ -24,7 +24,7 @@ type containerMonitor struct {
24 24
 	// container is the container being monitored
25 25
 	container *Container
26 26
 
27
-	// restartPolicy is the being applied to the container monitor
27
+	// restartPolicy is the current policy being applied to the container monitor
28 28
 	restartPolicy runconfig.RestartPolicy
29 29
 
30 30
 	// failureCount is the number of times the container has failed to
... ...
@@ -35,8 +35,7 @@ type containerMonitor struct {
35 35
 	// either because docker or the user asked for the container to be stopped
36 36
 	shouldStop bool
37 37
 
38
-	// startSignal signals with the initial process has launched after calling Start
39
-	// on the monitor
38
+	// startSignal is a channel that is closes after the container initially starts
40 39
 	startSignal chan struct{}
41 40
 
42 41
 	// stopChan is used to signal to the monitor whenever there is a wait for the
... ...
@@ -196,7 +195,7 @@ func (m *containerMonitor) resetMonitor(successful bool) {
196 196
 }
197 197
 
198 198
 // waitForNextRestart waits with the default time increment to restart the container unless
199
-// a user or docker asks to container to be stopped
199
+// a user or docker asks for the container to be stopped
200 200
 func (m *containerMonitor) waitForNextRestart() {
201 201
 	select {
202 202
 	case <-time.After(time.Duration(m.timeIncrement) * time.Millisecond):
... ...
@@ -245,8 +244,11 @@ func (m *containerMonitor) callback(command *execdriver.Command) {
245 245
 
246 246
 	m.container.State.SetRunning(command.Pid())
247 247
 
248
-	// signal that the process has started
249
-	close(m.startSignal)
248
+	if m.startSignal != nil {
249
+		// signal that the process has started
250
+		close(m.startSignal)
251
+		m.startSignal = nil
252
+	}
250 253
 
251 254
 	if err := m.container.ToDisk(); err != nil {
252 255
 		utils.Debugf("%s", err)
... ...
@@ -123,6 +123,7 @@ func (s *State) SetRunning(pid int) {
123 123
 	s.Lock()
124 124
 	s.Running = true
125 125
 	s.Paused = false
126
+	s.Restarting = false
126 127
 	s.ExitCode = 0
127 128
 	s.Pid = pid
128 129
 	s.StartedAt = time.Now().UTC()
... ...
@@ -134,6 +135,7 @@ func (s *State) SetRunning(pid int) {
134 134
 func (s *State) SetStopped(exitCode int) {
135 135
 	s.Lock()
136 136
 	s.Running = false
137
+	s.Restarting = false
137 138
 	s.Pid = 0
138 139
 	s.FinishedAt = time.Now().UTC()
139 140
 	s.ExitCode = exitCode
... ...
@@ -146,17 +148,15 @@ func (s *State) SetStopped(exitCode int) {
146 146
 // in the middle of a stop and being restarted again
147 147
 func (s *State) SetRestarting(exitCode int) {
148 148
 	s.Lock()
149
-	if s.Running {
150
-		// we should consider the container running when it is restarting because of
151
-		// all the checks in docker around rm/stop/etc
152
-		s.Running = true
153
-		s.Restarting = true
154
-		s.Pid = 0
155
-		s.FinishedAt = time.Now().UTC()
156
-		s.ExitCode = exitCode
157
-		close(s.waitChan) // fire waiters for stop
158
-		s.waitChan = make(chan struct{})
159
-	}
149
+	// we should consider the container running when it is restarting because of
150
+	// all the checks in docker around rm/stop/etc
151
+	s.Running = true
152
+	s.Restarting = true
153
+	s.Pid = 0
154
+	s.FinishedAt = time.Now().UTC()
155
+	s.ExitCode = exitCode
156
+	close(s.waitChan) // fire waiters for stop
157
+	s.waitChan = make(chan struct{})
160 158
 	s.Unlock()
161 159
 }
162 160