2626 get_container_config ,
2727 merge_container_config_with_image ,
2828 update_containers_data_after_check ,
29+ is_running_container ,
2930)
3031from backend .core .container import (
3132 GroupCheckProgressCache ,
@@ -170,8 +171,23 @@ def _will_update(gc: ContainerGroupItem) -> bool:
170171 and gc .new_image
171172 and gc .action == "update"
172173 and not gc .protected
174+ and is_running_container (gc .container )
173175 )
174176
177+ def _will_skip (gc : ContainerGroupItem ) -> bool :
178+ """Whether to skip container"""
179+ if gc .protected :
180+ logging .info (
181+ f"Container { gc .name } labeled with { TUGTAINER_PROTECTED_LABEL } , skipping."
182+ )
183+ return True
184+ elif not is_running_container (gc .container ):
185+ logging .info (
186+ f"Container { gc .name } is not running, skipping."
187+ )
188+ return True
189+ return False
190+
175191 def _group_state_to_result (
176192 group : ContainerGroup ,
177193 ) -> GroupCheckResult :
@@ -223,7 +239,7 @@ async def _run_commands(commands: list[list[str]]):
223239 result = _group_state_to_result (group )
224240 await update_containers_data_after_check (result )
225241 logging .info (
226- f"""Group check completed.
242+ f"""Group check completed.
227243================================================================="""
228244 )
229245 CACHE .update ({"status" : ECheckStatus .DONE , "result" : result })
@@ -232,20 +248,11 @@ async def _run_commands(commands: list[list[str]]):
232248 logging .info ("Starting to update a group..." )
233249 CACHE .update ({"status" : ECheckStatus .UPDATING })
234250
235- protected_containers = [
236- gc for gc in group .containers if gc .protected
237- ]
238- for gc in protected_containers :
239- logging .info (
240- f"Container { gc .name } labeled with { TUGTAINER_PROTECTED_LABEL } and will be skipped."
241- )
242-
243- # Starting from most dependent
251+ # Getting containers configs and stopping them,
252+ # from most dependent to most dependable.
244253 for gc in group .containers [::- 1 ]:
245- # Skipping protected containers
246- if gc .protected :
254+ if _will_skip (gc ):
247255 continue
248- # Getting configs for all containers
249256 try :
250257 logging .info (
251258 f"Getting config for container { gc .container .name } ..."
@@ -261,7 +268,6 @@ async def _run_commands(commands: list[list[str]]):
261268================================================================="""
262269 )
263270 return await _on_stop_fail ()
264- # Stopping all containers
265271 try :
266272 logging .info (f"Stopping container { gc .container .name } ..." )
267273 await client .container .stop (gc .name )
@@ -273,17 +279,15 @@ async def _run_commands(commands: list[list[str]]):
273279 )
274280 return await _on_stop_fail ()
275281
276- # Starting from most dependable.
277- # At that moment all containers should be stopped.
278- # Will update/start them in dependency order
282+ # Updating and/or starting containers,
283+ # from most dependable to most dependent.
279284
280285 # Indicates was there an exception during the update
281286 # If True, the following updates will not be processed.
282287 any_failed : bool = False
283288
284289 for gc in group .containers :
285- # Skipping protected containers
286- if gc .protected :
290+ if _will_skip (gc ):
287291 continue
288292 c_name = gc .name
289293 # Updating container
@@ -354,9 +358,13 @@ async def _run_commands(commands: list[list[str]]):
354358 if await wait_for_container_healthy (
355359 client , rolled_back , host .container_hc_timeout
356360 ):
357- logging .warning ("Container is healthy!" )
361+ logging .warning (
362+ "Container is healthy after rolling back!"
363+ )
358364 continue
359- logging .warning ("Container is unhealthy!" )
365+ logging .warning (
366+ "Container is unhealthy after rolling back!"
367+ )
360368 # Failed to roll back
361369 except Exception as e :
362370 logging .exception (e )
@@ -475,7 +483,9 @@ async def check_all(update: bool):
475483 Function performs checks in separate threads for each host.
476484 Should not raises errors, only logging.
477485 """
478- CACHE = ProcessCache [AllCheckProgressCache ](ALL_CONTAINERS_STATUS_KEY )
486+ CACHE = ProcessCache [AllCheckProgressCache ](
487+ ALL_CONTAINERS_STATUS_KEY
488+ )
479489 try :
480490 STATUS = CACHE .get ()
481491 if STATUS and STATUS .get ("status" ) not in _ALLOW_STATUSES :
0 commit comments