Skip to content

Commit a21e01a

Browse files
authored
[config] Don't attempt to restart disabled services (sonic-net#944)
When restarting services, don't attempt to restart a service if it is disabled/masked or the `systemctl restart` command will fail, causing the calling command (e.g., `config load`, `config reload`, `config load_minigraph`) to error out.
1 parent 1565ba2 commit a21e01a

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

config/main.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,32 @@ def _abort_if_false(ctx, param, value):
497497
if not value:
498498
ctx.abort()
499499

500+
501+
def _get_disabled_services_list():
502+
disabled_services_list = []
503+
504+
config_db = ConfigDBConnector()
505+
config_db.connect()
506+
feature_table = config_db.get_table('FEATURE')
507+
if feature_table is not None:
508+
for feature_name in feature_table.keys():
509+
if not feature_name:
510+
log_warning("Feature is None")
511+
continue
512+
513+
status = feature_table[feature_name]['status']
514+
if not status:
515+
log_warning("Status of feature '{}' is None".format(feature_name))
516+
continue
517+
518+
if status == "disabled":
519+
disabled_services_list.append(feature_name)
520+
else:
521+
log_warning("Unable to retreive FEATURE table")
522+
523+
return disabled_services_list
524+
525+
500526
def _stop_services():
501527
# on Mellanox platform pmon is stopped by syncd
502528
services_to_stop = [
@@ -514,6 +540,7 @@ def _stop_services():
514540

515541
execute_systemctl(services_to_stop, SYSTEMCTL_ACTION_STOP)
516542

543+
517544
def _reset_failed_services():
518545
services_to_reset = [
519546
'bgp',
@@ -534,8 +561,8 @@ def _reset_failed_services():
534561
'sflow',
535562
'restapi'
536563
]
537-
execute_systemctl(services_to_reset, SYSTEMCTL_ACTION_RESET_FAILED)
538564

565+
execute_systemctl(services_to_reset, SYSTEMCTL_ACTION_RESET_FAILED)
539566

540567

541568
def _restart_services():
@@ -555,6 +582,12 @@ def _restart_services():
555582
'restapi'
556583
]
557584

585+
disable_services = _get_disabled_services_list()
586+
587+
for service in disable_services:
588+
if service in services_to_restart:
589+
services_to_restart.remove(service)
590+
558591
if asic_type == 'mellanox' and 'pmon' in services_to_restart:
559592
services_to_restart.remove('pmon')
560593

0 commit comments

Comments
 (0)