-
Notifications
You must be signed in to change notification settings - Fork 650
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
jleveque
merged 3 commits into
sonic-net:master
from
jleveque:reset_failed_before_restart
Aug 20, 2019
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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', | ||
|
@@ -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 | ||
|
@@ -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() | ||
_restart_services() | ||
|
||
@config.command() | ||
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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`.") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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