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

[Service] Enable/disable container auto-restart based on configuration. #4073

Merged
merged 35 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e334536
[Event_listener] modify event listener such that it will read the flag
yozhao101 Jan 27, 2020
d0bf16b
[Docker-teamd] Modify supervisord config file to pass the container n…
yozhao101 Jan 27, 2020
5953740
[Docker-telemetry] Modify the supervisord config file to pass container
yozhao101 Jan 27, 2020
5d007b1
[Docker-sflow] Modify supervisord config file to pass container name to
yozhao101 Jan 27, 2020
4439c4a
[Docker-lldp] Modify supervisord config file to pass container name to
yozhao101 Jan 27, 2020
e2ef606
[Docker-swss] Modify supervisord config file to pass container name to
yozhao101 Jan 27, 2020
8a963d6
[Docker-pmon] Modify supervisord config file to pass container name to
yozhao101 Jan 27, 2020
f460268
[Docker-radv] Modify supervisord config file to pass container name to
yozhao101 Jan 27, 2020
e1580dd
[Docker-dhcp-relay] Modify supervisord config file to pass container
yozhao101 Jan 27, 2020
091a550
[Docker-snmp] Modify supervisord config file to pass container name to
yozhao101 Jan 27, 2020
ec4d6ee
[Docker-bgp] Add an event listener, critical process list for contai…
yozhao101 Jan 27, 2020
8161903
[Docker-bgp] Set the maximum restart times to 3 during 20 mins.
yozhao101 Jan 27, 2020
9097988
[Docker-bgp] Add a macro in docker's makefile.
yozhao101 Jan 27, 2020
05170f3
[Docker-syncd-barefoot] Modify the supervisord config file to pass
yozhao101 Jan 27, 2020
0d52f4e
[Docker-syncd-broadcom] Modify supervisord config file to pass container
yozhao101 Jan 27, 2020
4b9b009
[Docker-syncd-cavium] Modify supervisord config file to pass container
yozhao101 Jan 27, 2020
81cb12b
[Docker-syncd-centec] Modify supervisord config file to pass container
yozhao101 Jan 27, 2020
3b84e80
[Docker-syncd-marvell] Modify supervisord config file to pass container
yozhao101 Jan 27, 2020
44970a0
[Docker-syncd-marvell-arm64] Modify supervisord config file to pass
yozhao101 Jan 27, 2020
e73a86d
[Docker-syncd-marvell-armhf] Modify supervisord config file to pass
yozhao101 Jan 27, 2020
bcf43c7
[Docker-syncd-mellanox] Modify supervisord config file to pass container
yozhao101 Jan 27, 2020
cbebfe0
[Docker-syncd-nephos] Modify the supervisord config file to pass
yozhao101 Jan 27, 2020
b8a2f39
[Event listener] Add '=' for getopt parameters.
yozhao101 Jan 28, 2020
5dcb1ec
[Event-listener] Reorganize the import commands in event listener.
yozhao101 Jan 28, 2020
b30a5a2
[Docker-bgp] Delete all the relevant files of auto-restart feature.
yozhao101 Jan 28, 2020
51cdf73
[Docker-dhcp-relay] Pass container name as paramter in sampled generated
yozhao101 Jan 28, 2020
6a2932b
[Event-listener] Add the logic to handle if the container name is not
yozhao101 Jan 29, 2020
2457dbf
[Event-listener] Change the exit code.
yozhao101 Jan 29, 2020
5e6ab1f
[Event-listener] Change the exit code from 1 to 2.
yozhao101 Jan 29, 2020
693fd78
[Event-listener] Change the exit code from 2 to 1 in line 30.
yozhao101 Jan 29, 2020
324dd4f
[Event-listener] Add three periods in the line 61.
yozhao101 Jan 29, 2020
8201389
[Event-listener] Add logic to decide the invalid container name.
yozhao101 Jan 29, 2020
3df1a3d
[Event-listener] Change the logic to avoid invalid container name.
yozhao101 Jan 29, 2020
0833a03
[Event-listener] Add the logic to handle the corner caseis if the tab…
yozhao101 Jan 30, 2020
56ed262
[Event-listener] Use the syslog.LOG_ERR to write message into syslog
yozhao101 Feb 3, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ logfile_backups=2
nodaemon=true

[eventlistener:supervisor-proc-exit-listener]
command=/usr/bin/supervisor-proc-exit-listener
command=/usr/bin/supervisor-proc-exit-listener --container-name dhcp_relay
jleveque marked this conversation as resolved.
Show resolved Hide resolved
events=PROCESS_STATE_EXITED
autostart=true
autorestart=unexpected
Expand Down
2 changes: 1 addition & 1 deletion dockers/docker-lldp-sv2/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ logfile_backups=2
nodaemon=true

[eventlistener:supervisor-proc-exit-listener]
command=/usr/bin/supervisor-proc-exit-listener
command=/usr/bin/supervisor-proc-exit-listener --container-name lldp
events=PROCESS_STATE_EXITED
autostart=true
autorestart=unexpected
Expand Down
2 changes: 1 addition & 1 deletion dockers/docker-orchagent/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ logfile_backups=2
nodaemon=true

[eventlistener:supervisor-proc-exit-listener]
command=/usr/bin/supervisor-proc-exit-listener
command=/usr/bin/supervisor-proc-exit-listener --container-name swss
events=PROCESS_STATE_EXITED
autostart=true
autorestart=unexpected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ logfile_backups=2
nodaemon=true

[eventlistener:supervisor-proc-exit-listener]
command=/usr/bin/supervisor-proc-exit-listener
command=/usr/bin/supervisor-proc-exit-listener --container-name pmon
events=PROCESS_STATE_EXITED
autostart=true
autorestart=unexpected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ logfile_backups=2
nodaemon=true

[eventlistener:supervisor-proc-exit-script]
command=/usr/bin/supervisor-proc-exit-listener
command=/usr/bin/supervisor-proc-exit-listener --container-name radv
events=PROCESS_STATE_EXITED
autostart=true
autorestart=unexpected
Expand Down
2 changes: 1 addition & 1 deletion dockers/docker-sflow/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ logfile_backups=2
nodaemon=true

[eventlistener:supervisor-proc-exit-listener]
command=/usr/bin/supervisor-proc-exit-listener
command=/usr/bin/supervisor-proc-exit-listener --container-name sflow
events=PROCESS_STATE_EXITED
autostart=true
autorestart=unexpected
Expand Down
2 changes: 1 addition & 1 deletion dockers/docker-snmp-sv2/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ logfile_backups=2
nodaemon=true

[eventlistener:supervisor-proc-exit-listener]
command=/usr/bin/supervisor-proc-exit-listener
command=/usr/bin/supervisor-proc-exit-listener --container-name snmp
events=PROCESS_STATE_EXITED
autostart=true
autorestart=unexpected
Expand Down
2 changes: 1 addition & 1 deletion dockers/docker-sonic-telemetry/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ logfile_backups=2
nodaemon=true

[eventlistener:supervisor-proc-exit-listener]
command=/usr/bin/supervisor-proc-exit-listener
command=/usr/bin/supervisor-proc-exit-listener --container-name telemetry
events=PROCESS_STATE_EXITED
autostart=true
autorestart=false
Expand Down
2 changes: 1 addition & 1 deletion dockers/docker-teamd/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ logfile_backups=2
nodaemon=true

[eventlistener:supervisor-proc-exit-listener]
command=/usr/bin/supervisor-proc-exit-listener
command=/usr/bin/supervisor-proc-exit-listener --container-name teamd
events=PROCESS_STATE_EXITED
autostart=true
autorestart=unexpected
Expand Down
34 changes: 30 additions & 4 deletions files/scripts/supervisor-proc-exit-listener
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
#!/usr/bin/env python

import getopt
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():
# This table in databse contains the features for container and each
# feature for a row will be configured a state or number.
CONTAINER_FEATURE_TABLE_NAME = 'CONTAINER_FEATURE'

def main(argv):
container_name = None
opts, args = getopt.getopt(argv, "c:", ["container-name="])
for opt, arg in opts:
if opt in ("-c", "--container-name"):
container_name = arg
jleveque marked this conversation as resolved.
Show resolved Hide resolved

if not container_name:
syslog.syslog(syslog.LOG_ERROR, "Container name not specified. Exiting...")
sys.exit(2)
jleveque marked this conversation as resolved.
Show resolved Hide resolved

# 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]
Expand All @@ -35,12 +52,21 @@ def main():
processname = payload_headers['processname']
groupname = payload_headers['groupname']

# If a critical process exited unexpectedly, terminate supervisor
if expected == 0 and processname in critical_processes or groupname in critical_processes:
config_db = swsssdk.ConfigDBConnector()
config_db.connect()
docker_config = config_db.get_table(CONTAINER_FEATURE_TABLE_NAME)
jleveque marked this conversation as resolved.
Show resolved Hide resolved
if docker_config and docker_config.has_key(container_name):
jleveque marked this conversation as resolved.
Show resolved Hide resolved
restart_feature = docker_config[container_name].get('auto_restart')
jleveque marked this conversation as resolved.
Show resolved Hide resolved
if not restart_feature:
syslog.syslog(syslog.LOG_ERROR, "Unable to determine auto-restart feature status for container '{}'. Exiting".format(container_name))
jleveque marked this conversation as resolved.
Show resolved Hide resolved
sys.exit(2)

# If auto-restart feature is enabled and a critical process exited unexpectedly, terminate supervisor
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()
main(sys.argv[1:])
6 changes: 6 additions & 0 deletions platform/barefoot/docker-syncd-bfn/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ logfile_maxbytes=1MB
logfile_backups=2
nodaemon=true

[eventlistener:supervisor-proc-exit-listener]
command=/usr/bin/supervisor-proc-exit-listener --container-name syncd
events=PROCESS_STATE_EXITED
autostart=true
autorestart=unexpected

[program:start.sh]
command=/usr/bin/start.sh
priority=1
Expand Down
2 changes: 1 addition & 1 deletion platform/broadcom/docker-syncd-brcm/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ logfile_backups=2
nodaemon=true

[eventlistener:supervisor-proc-exit-listener]
command=/usr/bin/supervisor-proc-exit-listener
command=/usr/bin/supervisor-proc-exit-listener --container-name syncd
events=PROCESS_STATE_EXITED
autostart=true
autorestart=unexpected
Expand Down
2 changes: 1 addition & 1 deletion platform/cavium/docker-syncd-cavm/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ logfile_backups=2
nodaemon=true

[eventlistener:supervisor-proc-exit-listener]
command=/usr/bin/supervisor-proc-exit-listener
command=/usr/bin/supervisor-proc-exit-listener --container-name syncd
events=PROCESS_STATE_EXITED
autostart=true
autorestart=unexpected
Expand Down
2 changes: 1 addition & 1 deletion platform/centec/docker-syncd-centec/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ logfile_backups=2
nodaemon=true

[eventlistener:supervisor-proc-exit-listener]
command=/usr/bin/supervisor-proc-exit-listener
command=/usr/bin/supervisor-proc-exit-listener --container-name syncd
events=PROCESS_STATE_EXITED
autostart=true
autorestart=unexpected
Expand Down
6 changes: 6 additions & 0 deletions platform/marvell-arm64/docker-syncd-mrvl/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ logfile_maxbytes=1MB
logfile_backups=2
nodaemon=true

[eventlistener:supervisor-proc-exit-listener]
command=/usr/bin/supervisor-proc-exit-listener --container-name syncd
events=PROCESS_STATE_EXITED
autostart=true
autorestart=unexpected

[program:start.sh]
command=/usr/bin/start.sh
priority=1
Expand Down
6 changes: 6 additions & 0 deletions platform/marvell-armhf/docker-syncd-mrvl/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ logfile_maxbytes=1MB
logfile_backups=2
nodaemon=true

[eventlistener:supervisor-proc-exit-listener]
command=/usr/bin/supervisor-proc-exit-listener --container-name syncd
events=PROCESS_STATE_EXITED
autostart=true
autorestart=unexpected

[program:start.sh]
command=/usr/bin/start.sh
priority=1
Expand Down
2 changes: 1 addition & 1 deletion platform/marvell/docker-syncd-mrvl/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ logfile_backups=2
nodaemon=true

[eventlistener:supervisor-proc-exit-listener]
command=/usr/bin/supervisor-proc-exit-listener
command=/usr/bin/supervisor-proc-exit-listener --container-name syncd
events=PROCESS_STATE_EXITED
autostart=true
autorestart=unexpected
Expand Down
2 changes: 1 addition & 1 deletion platform/mellanox/docker-syncd-mlnx/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ logfile_backups=2
nodaemon=true

[eventlistener:supervisor-proc-exit-listener]
command=/usr/bin/supervisor-proc-exit-listener
command=/usr/bin/supervisor-proc-exit-listener --container-name syncd
events=PROCESS_STATE_EXITED
autostart=true
autorestart=unexpected
Expand Down
2 changes: 1 addition & 1 deletion platform/nephos/docker-syncd-nephos/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ logfile_backups=2
nodaemon=true

[eventlistener:supervisor-proc-exit-listener]
command=/usr/bin/supervisor-proc-exit-listener
command=/usr/bin/supervisor-proc-exit-listener --container-name syncd
events=PROCESS_STATE_EXITED
autostart=true
autorestart=unexpected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ logfile_backups=2
nodaemon=true

[eventlistener:supervisor-proc-exit-listener]
command=/usr/bin/supervisor-proc-exit-listener
command=/usr/bin/supervisor-proc-exit-listener --container-name dhcp_relay
events=PROCESS_STATE_EXITED
autostart=true
autorestart=unexpected
Expand Down