File tree Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change 16
16
# along with this program. If not, see <http://www.gnu.org/licenses/>
17
17
#
18
18
19
+ import contextlib
19
20
import logging
21
+ import signal
20
22
import time
23
+ import typing
21
24
22
25
from sambacc import samba_cmds
23
26
import sambacc .paths as paths
@@ -103,16 +106,32 @@ def _run_container_args(parser):
103
106
)
104
107
105
108
109
+ _COND_TIMEOUT = 5 * 60
110
+
111
+
112
+ @contextlib .contextmanager
113
+ def _timeout (timeout : int ) -> typing .Iterator [None ]:
114
+ def _handler (sig : int , frame : typing .Any ) -> None :
115
+ raise RuntimeError ("timed out waiting for conditions" )
116
+
117
+ signal .signal (signal .SIGALRM , _handler )
118
+ signal .alarm (timeout )
119
+ yield
120
+ signal .alarm (0 )
121
+ signal .signal (signal .SIGALRM , signal .SIG_DFL )
122
+
123
+
106
124
@commands .command (name = "run" , arg_func = _run_container_args )
107
125
def run_container (ctx : Context ) -> None :
108
126
"""Run a specified server process."""
109
127
if ctx .cli .no_init and ctx .cli .setup :
110
128
raise Fail ("can not specify both --no-init and --setup" )
111
129
112
130
if ctx .cli .wait_for :
113
- conditions = [_wait_for_conditions [n ]() for n in ctx .cli .wait_for ]
114
- while not all (c .met (ctx ) for c in conditions ):
115
- time .sleep (1 )
131
+ with _timeout (_COND_TIMEOUT ):
132
+ conditions = [_wait_for_conditions [n ]() for n in ctx .cli .wait_for ]
133
+ while not all (c .met (ctx ) for c in conditions ):
134
+ time .sleep (1 )
116
135
117
136
# running servers expect to make use of ctdb whenever it is configured
118
137
ctx .expects_ctdb = True
You can’t perform that action at this time.
0 commit comments