File tree Expand file tree Collapse file tree 3 files changed +41
-4
lines changed
Expand file tree Collapse file tree 3 files changed +41
-4
lines changed Original file line number Diff line number Diff line change @@ -162,9 +162,23 @@ impl Client {
162162 . map_err ( ClientError :: RemoveContainer )
163163 }
164164
165- pub ( crate ) async fn stop ( & self , id : & str ) -> Result < ( ) , ClientError > {
165+ //pub(crate) async fn stop(&self, id: &str) -> Result<(), ClientError> {
166+ // self.bollard
167+ // .stop_container(id, None)
168+ // .await
169+ // .map_err(ClientError::StopContainer)
170+ //}
171+
172+ pub ( crate ) async fn stop (
173+ & self ,
174+ id : & str ,
175+ timeout_seconds : i64 ,
176+ ) -> Result < ( ) , ClientError > {
166177 self . bollard
167- . stop_container ( id, None )
178+ . stop_container (
179+ id,
180+ Some ( bollard:: container:: StopContainerOptions { t : timeout_seconds } ) ,
181+ )
168182 . await
169183 . map_err ( ClientError :: StopContainer )
170184 }
Original file line number Diff line number Diff line change @@ -282,9 +282,24 @@ where
282282
283283 /// Stops the container (not the same with `pause`).
284284 pub async fn stop ( & self ) -> Result < ( ) > {
285- log:: debug!( "Stopping docker container {}" , self . id) ;
285+ self . stop_with_timeout ( 0 ) . await ?;
286+ Ok ( ( ) )
287+ }
288+
289+ /// Stops the container with timeout before issuing SIGKILL (not the same with `pause`).
290+ ///
291+ /// Set -1 for immediate SIGKILL, otherwise the runtime will issue SIGINT and then wait
292+ /// the specified number of seconds for process to stop before issunging SIGKILL.
293+ pub async fn stop_with_timeout ( & self , timeout_seconds : i64 ) -> Result < ( ) > {
294+ log:: debug!(
295+ "Stopping docker container {} with {} second timeout" ,
296+ self . id,
297+ timeout_seconds
298+ ) ;
286299
287- self . docker_client . stop ( & self . id ) . await ?;
300+ self . docker_client
301+ . stop ( & self . id , timeout_seconds)
302+ . await ?;
288303 Ok ( ( ) )
289304 }
290305
Original file line number Diff line number Diff line change @@ -132,6 +132,14 @@ where
132132 self . rt ( ) . block_on ( self . async_impl ( ) . stop ( ) )
133133 }
134134
135+ /// Stops the container with timeout before issuing SIGKILL (not the same with `pause`).
136+ ///
137+ /// Set -1 for immediate SIGKILL, otherwise the runtime will issue SIGINT and then wait
138+ /// the specified number of seconds for process to stop before issunging SIGKILL.
139+ pub fn stop_with_timeout ( & self , timeout_seconds : i64 ) -> Result < ( ) > {
140+ self . rt ( ) . block_on ( self . async_impl ( ) . stop_with_timeout ( ) )
141+ }
142+
135143 /// Starts the container.
136144 pub fn start ( & self ) -> Result < ( ) > {
137145 self . rt ( ) . block_on ( self . async_impl ( ) . start ( ) )
You can’t perform that action at this time.
0 commit comments