Skip to content

Commit f520752

Browse files
Add pause, only if restart fails even after reset
1 parent 3bd91b5 commit f520752

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

generic_config_updater/services_validator.py

+28-17
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
print_to_console = False
77

8-
PAUSE_AFTER_FAILED_RESTART = "7s"
9-
108
def set_verbose(verbose=False):
119
global print_to_console, logger
1210

@@ -21,24 +19,22 @@ def _service_restart(svc_name):
2119
rc = os.system(f"systemctl restart {svc_name}")
2220
if rc != 0:
2321
# This failure is likely due to too many restarts
24-
# Which is the reflection of patch sorter not grouping
25-
# updates for keys effectively.
26-
# Once the patch sorter is tuned, the following
27-
# code would not be executed.
2822
#
2923
rc = os.system(f"systemctl reset-failed {svc_name}")
3024
logger.log(logger.LOG_PRIORITY_ERROR,
31-
f"Service has been reset. rc={rc} Pause for {PAUSE_AFTER_FAILED_RESTART}",
25+
f"Service has been reset. rc={rc}; Try restart again...",
3226
print_to_console)
3327

34-
# Even with successful reset-failed, a pause is required, else the
35-
# immediate restart was found to fail in manual tests.
36-
# Hence add a pause.
37-
# This pause would help even if the earlier reset-failed fails.
38-
# Hence we ignore return code from reset-failed.
39-
#
40-
os.system(f"sleep {PAUSE_AFTER_FAILED_RESTART}")
4128
rc = os.system(f"systemctl restart {svc_name}")
29+
if rc != 0:
30+
# Even with reset-failed, restart fails.
31+
# Give a pause before retry.
32+
#
33+
logger.log(logger.LOG_PRIORITY_ERROR,
34+
f"Restart failed for {svc_name} rc={rc} after reset; Pause for 10s & retry",
35+
print_to_console)
36+
os.system("sleep 10s")
37+
rc = os.system(f"systemctl restart {svc_name}")
4238

4339
if rc == 0:
4440
logger.log(logger.LOG_PRIORITY_NOTICE,
@@ -52,7 +48,11 @@ def _service_restart(svc_name):
5248

5349

5450
def rsyslog_validator(old_config, upd_config, keys):
55-
return _service_restart("rsyslog-config")
51+
rc = os.system("/usr/bin/rsyslog-config.sh")
52+
if rc != 0:
53+
return _service_restart("rsyslog")
54+
else:
55+
return True
5656

5757

5858
def dhcp_validator(old_config, upd_config, keys):
@@ -72,5 +72,16 @@ def vlan_validator(old_config, upd_config, keys):
7272

7373

7474
def main_test():
75-
for(i=0; i<10; ++i):
76-
_service_restart("rsyslog-config")
75+
print_to_console = True
76+
for i in range(20):
77+
print(f"i={i}")
78+
rc = _service_restart("rsyslog")
79+
# rc = rsyslog_validator("", "", "")
80+
if not rc:
81+
print("FAILED ...")
82+
break
83+
84+
85+
if __name__ == "__main__":
86+
main_test()
87+

0 commit comments

Comments
 (0)