-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[teamd] Enable/disable container auto-restart based on configuration #4053
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d3188e1
[Docker-teamd] Add a separate event listener for teamd and let event
yozhao101 08caf9c
[Docker-teamd] Remove the event listener macro from docker-teamd.mk.
yozhao101 b642682
[Docker-teamd] Copy the event listener from current directory.
yozhao101 6f36956
[Docker-teamd] Use the constant string to represent the table name and
yozhao101 cc73bf3
[Docker-teamd] Update the comment in event listener.
yozhao101 969cbc6
[Docker-teamd] Change the name of constant string (TABLE_NAME) in the…
yozhao101 8adc6fb
[Docker-teamd] Use the new table name in event listener.
yozhao101 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 hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| import os | ||
| import signal | ||
| import sys | ||
| import syslog | ||
| import swsssdk | ||
|
|
||
| from supervisor import childutils | ||
|
|
||
| # Contents of file should be the names of critical processes (as defined in | ||
| # supervisor.conf file), one per line | ||
| CRITICAL_PROCESSES_FILE = '/etc/supervisor/critical_processes' | ||
|
|
||
| def main(): | ||
| # Read the list of critical processes from a file | ||
| with open(CRITICAL_PROCESSES_FILE, 'r') as f: | ||
| critical_processes = [line.rstrip('\n') for line in f] | ||
|
|
||
| while True: | ||
| # Transition from ACKNOWLEDGED to READY | ||
| childutils.listener.ready() | ||
|
|
||
| line = sys.stdin.readline() | ||
| headers = childutils.get_headers(line) | ||
| payload = sys.stdin.read(int(headers['len'])) | ||
|
|
||
| # Transition from READY to ACKNOWLEDGED | ||
| childutils.listener.ok() | ||
|
|
||
| # We only care about PROCESS_STATE_EXITED events | ||
| if headers['eventname'] == 'PROCESS_STATE_EXITED': | ||
| payload_headers, payload_data = childutils.eventdata(payload + '\n') | ||
|
|
||
| expected = int(payload_headers['expected']) | ||
| processname = payload_headers['processname'] | ||
| groupname = payload_headers['groupname'] | ||
|
|
||
| config_db = swsssdk.ConfigDBConnector() | ||
| config_db.connect() | ||
| docker_config = config_db.get_table('Container_Feature') | ||
| restart_feature = '' | ||
jleveque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if docker_config and docker_config.has_key('teamd'): | ||
jleveque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| restart_feature = docker_config['teamd']['restart'] | ||
jleveque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # If a critical process exited unexpectedly, terminate supervisor | ||
jleveque marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if restart_feature == 'enabled' and expected == 0 and (processname in critical_processes or groupname in critical_processes): | ||
| MSG_FORMAT_STR = "Process {} exited unxepectedly. Terminating supervisor..." | ||
| msg = MSG_FORMAT_STR.format(payload_headers['processname']) | ||
| syslog.syslog(syslog.LOG_INFO, msg) | ||
| os.kill(os.getppid(), signal.SIGTERM) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.