Commit b589c911 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Harden container shutdown/removal

parent a3d40a0a
Loading
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ from __future__ import annotations

import ipaddress
import json
import logging
from contextlib import contextmanager
from pathlib import Path
from secrets import token_hex
@@ -218,7 +219,10 @@ class Container(Item):
		details = self.inspect()
		if details.path('$.State.Status', str) == 'exited':
			code = details.path('$.State.ExitCode', int)
			raise ProcessLookupError(f"container {self.cid} exited ({code})")
			if code != 0:
				logging.getLogger(__name__).warning(
					f"container {self.cid} exited ({code})",
				)
		return (
			self.cid is not None
			and details.path('$.State.Running', bool)
@@ -265,8 +269,10 @@ class Container(Item):
		"""
		if self.cid is None:
			return
		try:
			if self.is_running():
				docker_quiet('container', 'stop', self.cid)
		finally:
			if rm:
				docker_quiet('container', 'rm', self.cid)
				self.cid = None