Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[config] Call 'systemctl reset-failed' before 'systemctl restart' when restarting services #607

Merged
merged 3 commits into from
Aug 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 49 additions & 6 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,22 +287,57 @@ def _abort_if_false(ctx, param, value):
ctx.abort()

def _stop_services():
services = [
services_to_stop = [
'swss',
'lldp',
'pmon',
'bgp',
'hostcfgd',
]
for service in services:

for service in services_to_stop:
try:
run_command("systemctl stop %s" % service, display_cmd=True)
click.echo("Stopping service {} ...".format(service))
run_command("systemctl stop {}".format(service))

except SystemExit as e:
log_error("Stopping {} failed with error {}".format(service, e))
raise

def _reset_failed_services():
services_to_reset = [
'bgp',
'dhcp_relay',
'hostcfgd',
'hostname-config',
'interfaces-config',
'lldp',
'ntp-config',
'pmon',
'radv',
'rsyslog-config',
'snmp',
'swss',
'syncd',
'teamd'
]

command = "systemctl --failed | grep failed | awk '{ print $2 }' | awk -F'.' '{ print $1 }'"
proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
(out, err) = proc.communicate()
failed_services = out.rstrip('\n').split('\n')

for service in failed_services:
if service in services_to_reset:
try:
click.echo("Resetting failed service {} ...".format(service))
run_command("systemctl reset-failed {}".format(service))
except SystemExit as e:
log_error("Failed to reset service {}".format(service))
raise

def _restart_services():
services = [
services_to_restart = [
'hostname-config',
'interfaces-config',
'ntp-config',
Expand All @@ -313,9 +348,11 @@ def _restart_services():
'lldp',
'hostcfgd',
]
for service in services:

for service in services_to_restart:
try:
run_command("systemctl restart %s" % service, display_cmd=True)
click.echo("Restarting service {} ...".format(service))
run_command("systemctl restart {}".format(service))
except SystemExit as e:
log_error("Restart {} failed with error {}".format(service, e))
raise
Expand Down Expand Up @@ -398,6 +435,9 @@ def reload(filename, yes, load_sysinfo):
if os.path.isfile(db_migrator) and os.access(db_migrator, os.X_OK):
run_command(db_migrator + ' -o migrate')

# We first run "systemctl reset-failed" to remove the "failed"
# status from all services before we attempt to restart them
_reset_failed_services()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would only remove services that are already in failed status

_restart_services()

@config.command()
Expand Down Expand Up @@ -454,6 +494,9 @@ def load_minigraph():
if os.path.isfile(db_migrator) and os.access(db_migrator, os.X_OK):
run_command(db_migrator + ' -o set_version')

# We first run "systemctl reset-failed" to remove the "failed"
# status from all services before we attempt to restart them
_reset_failed_services()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would only remove services that are already in failed status

#FIXME: After config DB daemon is implemented, we'll no longer need to restart every service.
_restart_services()
click.echo("Please note setting loaded from minigraph will be lost after system reboot. To preserve setting, run `config save`.")
Expand Down