@@ -1074,7 +1074,7 @@ def resize(self, container, height, width):
10741074 self ._raise_for_status (res )
10751075
10761076 @utils .check_resource ('container' )
1077- def restart (self , container , timeout = 10 ):
1077+ def restart (self , container , timeout = 10 , signal = None ):
10781078 """
10791079 Restart a container. Similar to the ``docker restart`` command.
10801080
@@ -1084,6 +1084,7 @@ def restart(self, container, timeout=10):
10841084 timeout (int): Number of seconds to try to stop for before killing
10851085 the container. Once killed it will then be restarted. Default
10861086 is 10 seconds.
1087+ signal (str or int): The signal to send. Defaults to ``SIGTERM``
10871088
10881089 Raises:
10891090 :py:class:`docker.errors.APIError`
@@ -1092,6 +1093,10 @@ def restart(self, container, timeout=10):
10921093 params = {'t' : timeout }
10931094 url = self ._url ("/containers/{0}/restart" , container )
10941095 conn_timeout = self .timeout
1096+ if signal is not None :
1097+ if not isinstance (signal , str ):
1098+ signal = int (signal )
1099+ params ["signal" ] = signal
10951100 if conn_timeout is not None :
10961101 conn_timeout += timeout
10971102 res = self ._post (url , params = params , timeout = conn_timeout )
@@ -1184,7 +1189,7 @@ def stats(self, container, decode=None, stream=True, one_shot=None):
11841189 return self ._result (self ._get (url , params = params ), json = True )
11851190
11861191 @utils .check_resource ('container' )
1187- def stop (self , container , timeout = None ):
1192+ def stop (self , container , timeout = None , signal = None ):
11881193 """
11891194 Stops a container. Similar to the ``docker stop`` command.
11901195
@@ -1194,6 +1199,7 @@ def stop(self, container, timeout=None):
11941199 stop before sending a ``SIGKILL``. If None, then the
11951200 StopTimeout value of the container will be used.
11961201 Default: None
1202+ signal (str or int): The signal to send. Defaults to ``SIGTERM``
11971203
11981204 Raises:
11991205 :py:class:`docker.errors.APIError`
@@ -1206,6 +1212,10 @@ def stop(self, container, timeout=None):
12061212 params = {'t' : timeout }
12071213 url = self ._url ("/containers/{0}/stop" , container )
12081214 conn_timeout = self .timeout
1215+ if signal is not None :
1216+ if not isinstance (signal , str ):
1217+ signal = int (signal )
1218+ params ["signal" ] = signal
12091219 if conn_timeout is not None :
12101220 conn_timeout += timeout
12111221 res = self ._post (url , params = params , timeout = conn_timeout )
0 commit comments