Skip to content

Commit

Permalink
[config] Don't attempt to restart disabled services (sonic-net#944)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jleveque authored Jun 12, 2020
1 parent 1565ba2 commit a21e01a
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,32 @@ def _abort_if_false(ctx, param, value):
if not value:
ctx.abort()


def _get_disabled_services_list():
disabled_services_list = []

config_db = ConfigDBConnector()
config_db.connect()
feature_table = config_db.get_table('FEATURE')
if feature_table is not None:
for feature_name in feature_table.keys():
if not feature_name:
log_warning("Feature is None")
continue

status = feature_table[feature_name]['status']
if not status:
log_warning("Status of feature '{}' is None".format(feature_name))
continue

if status == "disabled":
disabled_services_list.append(feature_name)
else:
log_warning("Unable to retreive FEATURE table")

return disabled_services_list


def _stop_services():
# on Mellanox platform pmon is stopped by syncd
services_to_stop = [
Expand All @@ -514,6 +540,7 @@ def _stop_services():

execute_systemctl(services_to_stop, SYSTEMCTL_ACTION_STOP)


def _reset_failed_services():
services_to_reset = [
'bgp',
Expand All @@ -534,8 +561,8 @@ def _reset_failed_services():
'sflow',
'restapi'
]
execute_systemctl(services_to_reset, SYSTEMCTL_ACTION_RESET_FAILED)

execute_systemctl(services_to_reset, SYSTEMCTL_ACTION_RESET_FAILED)


def _restart_services():
Expand All @@ -555,6 +582,12 @@ def _restart_services():
'restapi'
]

disable_services = _get_disabled_services_list()

for service in disable_services:
if service in services_to_restart:
services_to_restart.remove(service)

if asic_type == 'mellanox' and 'pmon' in services_to_restart:
services_to_restart.remove('pmon')

Expand Down

0 comments on commit a21e01a

Please sign in to comment.