From 1f7602b2750473cedec3e4570f73a4c6aaabfc9a Mon Sep 17 00:00:00 2001 From: Guohan Lu Date: Fri, 15 May 2020 00:43:46 +0000 Subject: [PATCH] [docker-lldp-sv2]: use service dependency in supervisord to start services --- dockers/docker-lldp-sv2/Dockerfile.j2 | 1 + dockers/docker-lldp-sv2/start.sh | 30 ------------ dockers/docker-lldp-sv2/supervisord.conf.j2 | 49 +++++++++++++++---- dockers/docker-lldp-sv2/waitfor_lldp_ready.sh | 24 +++++++++ 4 files changed, 64 insertions(+), 40 deletions(-) create mode 100755 dockers/docker-lldp-sv2/waitfor_lldp_ready.sh diff --git a/dockers/docker-lldp-sv2/Dockerfile.j2 b/dockers/docker-lldp-sv2/Dockerfile.j2 index f45e1c0df8..15e755e6c6 100644 --- a/dockers/docker-lldp-sv2/Dockerfile.j2 +++ b/dockers/docker-lldp-sv2/Dockerfile.j2 @@ -37,6 +37,7 @@ RUN apt-get purge -y python-pip && \ COPY ["docker-lldp-init.sh", "/usr/bin/"] COPY ["start.sh", "/usr/bin/"] +COPY ["waitfor_lldp_ready.sh", "/usr/bin/"] COPY ["supervisord.conf.j2", "/usr/share/sonic/templates/"] COPY ["lldpd.conf.j2", "/usr/share/sonic/templates/"] COPY ["lldpd", "/etc/default/"] diff --git a/dockers/docker-lldp-sv2/start.sh b/dockers/docker-lldp-sv2/start.sh index 76666e77ac..5cb6042cee 100755 --- a/dockers/docker-lldp-sv2/start.sh +++ b/dockers/docker-lldp-sv2/start.sh @@ -5,34 +5,4 @@ sonic-cfggen -d -t /usr/share/sonic/templates/lldpd.conf.j2 > /etc/lldpd.conf mkdir -p /var/sonic echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status -rm -f /var/run/rsyslogd.pid rm -f /var/run/lldpd.socket - -supervisorctl start rsyslogd -supervisorctl start lldpd - -# Current lldpd version has a bug. -# When lldpd starts it is in the pause state by default -# But then it execute 'lldpcli resume' to configure and unpause itself. -# When lldpd execute lldpcli, it doesn't check the return code -# Sometimes lldpcli returns failure, but lldpd doesn't catch it -# and keeps working paused and unconfigured -# -# The fix below addresses the issue. -# - -# wait until lldpd started -until [[ -e /var/run/lldpd.socket ]]; -do - sleep 1; -done - -# Manually try to resume lldpd, until it's successful -while /bin/true; -do - lldpcli -u /var/run/lldpd.socket -c /etc/lldpd.conf -c /etc/lldpd.d resume > /dev/null && break - sleep 1 -done - -supervisorctl start lldp-syncd -supervisorctl start lldpmgrd diff --git a/dockers/docker-lldp-sv2/supervisord.conf.j2 b/dockers/docker-lldp-sv2/supervisord.conf.j2 index beae3aa942..776dcd0296 100644 --- a/dockers/docker-lldp-sv2/supervisord.conf.j2 +++ b/dockers/docker-lldp-sv2/supervisord.conf.j2 @@ -3,27 +3,39 @@ logfile_maxbytes=1MB logfile_backups=2 nodaemon=true +[eventlistener:dependent-startup] +command=python -m supervisord_dependent_startup +autostart=true +autorestart=unexpected +startretries=0 +exitcodes=0,3 +events=PROCESS_STATE + [eventlistener:supervisor-proc-exit-listener] command=/usr/bin/supervisor-proc-exit-listener --container-name lldp events=PROCESS_STATE_EXITED autostart=true autorestart=unexpected -[program:start.sh] -command=/usr/bin/start.sh -priority=1 -autostart=true -autorestart=false -stdout_logfile=syslog -stderr_logfile=syslog - [program:rsyslogd] -command=/usr/sbin/rsyslogd -n -priority=2 +command=/usr/sbin/rsyslogd -n -iNONE +priority=1 autostart=false autorestart=false stdout_logfile=syslog stderr_logfile=syslog +dependent_startup=true + +[program:start] +command=/usr/bin/start.sh +priority=2 +autostart=false +autorestart=false +startsecs=0 +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for=rsyslogd:running [program:lldpd] # https://github.com/vincentbernat/lldpd/commit/9856f2792c301116cc4a3fcfba91b9672ee5db1f @@ -41,6 +53,19 @@ autostart=false autorestart=false stdout_logfile=syslog stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for=start:exited + +[program:waitfor_lldp_ready] +command=/usr/bin/waitfor_lldp_ready.sh +priority=3 +autostart=false +autorestart=false +startsecs=0 +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for=lldpd:running [program:lldp-syncd] command=/usr/bin/env python2 -m lldp_syncd @@ -49,6 +74,8 @@ autostart=false autorestart=false stdout_logfile=syslog stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for=waitfor_lldp_ready:exited [program:lldpmgrd] command=/usr/bin/lldpmgrd @@ -57,3 +84,5 @@ autostart=false autorestart=false stdout_logfile=syslog stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for=lldp-syncd:running diff --git a/dockers/docker-lldp-sv2/waitfor_lldp_ready.sh b/dockers/docker-lldp-sv2/waitfor_lldp_ready.sh new file mode 100755 index 0000000000..ecb16dc2e5 --- /dev/null +++ b/dockers/docker-lldp-sv2/waitfor_lldp_ready.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Current lldpd version has a bug. +# When lldpd starts it is in the pause state by default +# But then it execute 'lldpcli resume' to configure and unpause itself. +# When lldpd execute lldpcli, it doesn't check the return code +# Sometimes lldpcli returns failure, but lldpd doesn't catch it +# and keeps working paused and unconfigured +# +# The fix below addresses the issue. +# + +# wait until lldpd started +until [[ -e /var/run/lldpd.socket ]]; +do + sleep 1; +done + +# Manually try to resume lldpd, until it's successful +while /bin/true; +do + lldpcli -u /var/run/lldpd.socket -c /etc/lldpd.conf -c /etc/lldpd.d resume > /dev/null && break + sleep 1 +done