[docker-radvd]: use service dependency in supervisord to start services

This commit is contained in:
Guohan Lu 2020-05-15 04:05:35 +00:00 committed by lguohan
parent 1f7602b275
commit 7ea6d9dc8f
5 changed files with 81 additions and 71 deletions

View File

@ -24,10 +24,9 @@ RUN apt-get clean -y && \
apt-get autoremove -y && \
rm -rf /debs
COPY ["start.sh", "/usr/bin/"]
COPY ["docker-router-advertiser.supervisord.conf", "/etc/supervisor/conf.d/"]
COPY ["radvd.conf.j2", "wait_for_intf.sh.j2", "/usr/share/sonic/templates/"]
COPY ["docker-init.sh", "/usr/bin/"]
COPY ["radvd.conf.j2", "wait_for_intf.sh.j2", "docker-router-advertiser.supervisord.conf.j2", "/usr/share/sonic/templates/"]
COPY ["files/supervisor-proc-exit-listener", "/usr/bin"]
COPY ["critical_processes", "/etc/supervisor"]
ENTRYPOINT ["/usr/bin/supervisord"]
ENTRYPOINT ["/usr/bin/docker-init.sh"]

View File

@ -0,0 +1,13 @@
#!/usr/bin/env bash
mkdir -p /etc/supervisor/conf.d
sonic-cfggen -d -t /usr/share/sonic/templates/docker-router-advertiser.supervisord.conf.j2 > /etc/supervisor/conf.d/supervisord.conf
# Generate /etc/radvd.conf config file
sonic-cfggen -d -t /usr/share/sonic/templates/radvd.conf.j2 > /etc/radvd.conf
# Generate the script that waits for pertinent interfaces to come up and make it executable
sonic-cfggen -d -t /usr/share/sonic/templates/wait_for_intf.sh.j2 > /usr/bin/wait_for_intf.sh
chmod +x /usr/bin/wait_for_intf.sh
exec /usr/bin/supervisord

View File

@ -1,35 +0,0 @@
[supervisord]
logfile_maxbytes=1MB
logfile_backups=2
nodaemon=true
[eventlistener:supervisor-proc-exit-script]
command=/usr/bin/supervisor-proc-exit-listener --container-name radv
events=PROCESS_STATE_EXITED
autostart=true
autorestart=unexpected
[program:start.sh]
command=/usr/bin/start.sh
priority=1
autostart=true
autorestart=false
startsecs=0
stdout_logfile=syslog
stderr_logfile=syslog
[program:rsyslogd]
command=/usr/sbin/rsyslogd -n
priority=2
autostart=false
autorestart=false
stdout_logfile=syslog
stderr_logfile=syslog
[program:radvd]
command=/usr/sbin/radvd -n
priority=3
autostart=false
autorestart=false
stdout_logfile=syslog
stderr_logfile=syslog

View File

@ -0,0 +1,65 @@
[supervisord]
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-script]
command=/usr/bin/supervisor-proc-exit-listener --container-name radv
events=PROCESS_STATE_EXITED
autostart=true
autorestart=unexpected
[program:rsyslogd]
command=/usr/sbin/rsyslogd -n -iNONE
priority=1
autostart=false
autorestart=false
stdout_logfile=syslog
stderr_logfile=syslog
dependent_startup=true
{# Router advertiser should only run on ToR (T0) devices #}
{% if DEVICE_METADATA.localhost.type == "ToRRouter" %}
{% if VLAN_INTERFACE %}
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
{# If this VLAN has an IPv6 address... #}
{% if prefix | ipv6 %}
{% set ipv6_found = true %}
{% endif %}
{% endfor %}
{% endif %}
{# Enusre at least one ipv6 vlan interface #}
{% if ipv6_found == true %}
[program:wait_for_link]
command=/usr/bin/wait_for_link.sh
priority=3
autostart=false
autorestart=false
startsecs=0
stdout_logfile=syslog
stderr_logfile=syslog
dependent_startup=true
dependent_startup_wait_for=rsyslogd:running
[program:radvd]
command=/usr/sbin/radvd -n
priority=4
autostart=false
autorestart=false
stdout_logfile=syslog
stderr_logfile=syslog
dependent_startup=true
dependent_startup_wait_for=wait_for_link:exited
{% endif %}
{% endif %}

View File

@ -1,32 +0,0 @@
#!/usr/bin/env bash
rm -f /var/run/rsyslogd.pid
supervisorctl start rsyslogd
# Router advertiser should only run on ToR (T0) devices
DEVICE_ROLE=$(sonic-cfggen -d -v "DEVICE_METADATA.localhost.type")
if [ "$DEVICE_ROLE" != "ToRRouter" ]; then
echo "Device role is not ToRRouter. Not starting router advertiser process."
exit 0
fi
# Generate /etc/radvd.conf config file
sonic-cfggen -d -t /usr/share/sonic/templates/radvd.conf.j2 > /etc/radvd.conf
# Enusre at least one interface is specified in radvd.conf
NUM_IFACES=$(grep -c "^interface " /etc/radvd.conf)
if [ $NUM_IFACES -eq 0 ]; then
echo "No interfaces specified in radvd.conf. Not starting router advertiser process."
exit 0
fi
# Generate the script that waits for pertinent interfaces to come up and make it executable
sonic-cfggen -d -t /usr/share/sonic/templates/wait_for_intf.sh.j2 > /usr/bin/wait_for_intf.sh
chmod +x /usr/bin/wait_for_intf.sh
# Wait for pertinent interfaces to come up
/usr/bin/wait_for_intf.sh
# Start the router advertiser
supervisorctl start radvd