Skip to content

Commit c4c9bee

Browse files
core: commonwealth: DHCPServerManager: Try to start DHCP server 3 times
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
1 parent 2bd40b9 commit c4c9bee

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

core/libs/commonwealth/commonwealth/utils/DHCPServerManager.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,23 @@ def command_list(self) -> List[Union[str, pathlib.Path]]:
101101
]
102102

103103
def start(self) -> None:
104-
try:
105-
# pylint: disable=consider-using-with
106-
self._subprocess = subprocess.Popen(self.command_list(), shell=False, encoding="utf-8", errors="ignore")
107-
time.sleep(3)
108-
if not self.is_running():
104+
attempts = 3
105+
for attempt in range(attempts):
106+
try:
107+
# pylint: disable=consider-using-with
108+
self._subprocess = subprocess.Popen(self.command_list(), shell=False, encoding="utf-8", errors="ignore")
109+
time.sleep(3)
110+
if self.is_running():
111+
logger.info("DHCP Server started.")
112+
return
113+
109114
exit_code = self._subprocess.returncode
110-
raise RuntimeError(f"Failed to initialize Dnsmasq ({exit_code}).")
111-
logger.info("DHCP Server started.")
112-
except Exception as error:
113-
raise RuntimeError("Unable to start DHCP Server.") from error
115+
logger.error(f"Attempt {attempt} failed to initialize Dnsmasq ({exit_code}).")
116+
except Exception as error:
117+
logger.error(f"Attempt {attempt} encountered an error: {error}")
118+
time.sleep(1)
119+
120+
raise RuntimeError("Unable to start DHCP Server")
114121

115122
def stop(self) -> None:
116123
if self.is_running():

0 commit comments

Comments
 (0)