[dhcp-relay] Reduce Calls to SONiC Cfggen (#5175)
Calls to sonic-cfggen is CPU expensive. This PR reduces calls to sonic-cfggen to one call during startup when starting dhcp-relay service. singed-off-by: Tamer Ahmed <tamer.ahmed@microsoft.com>
This commit is contained in:
parent
dfc0617283
commit
3a10e9c6fa
@ -25,7 +25,7 @@ RUN apt-get clean -y && \
|
||||
rm -rf /debs
|
||||
|
||||
COPY ["docker_init.sh", "start.sh", "/usr/bin/"]
|
||||
COPY ["docker-dhcp-relay.supervisord.conf.j2", "wait_for_intf.sh.j2", "/usr/share/sonic/templates/"]
|
||||
COPY ["docker-dhcp-relay.supervisord.conf.j2", "port-name-alias-map.txt.j2", "wait_for_intf.sh.j2", "/usr/share/sonic/templates/"]
|
||||
COPY ["files/supervisor-proc-exit-listener", "/usr/bin"]
|
||||
COPY ["critical_processes", "/etc/supervisor"]
|
||||
|
||||
|
@ -2,16 +2,22 @@
|
||||
|
||||
# Generate supervisord config file
|
||||
mkdir -p /etc/supervisor/conf.d/
|
||||
sonic-cfggen -d -t /usr/share/sonic/templates/docker-dhcp-relay.supervisord.conf.j2 > /etc/supervisor/conf.d/docker-dhcp-relay.supervisord.conf
|
||||
|
||||
# Generate the script that waits for all 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
|
||||
# Generate the following files from templates:
|
||||
# 1. supervisord configuration
|
||||
# 2. wait_for_intf.sh, which waits for all interfaces to come up
|
||||
# 3. port-to-alias name map
|
||||
CFGGEN_PARAMS=" \
|
||||
-d \
|
||||
-t /usr/share/sonic/templates/docker-dhcp-relay.supervisord.conf.j2,/etc/supervisor/conf.d/docker-dhcp-relay.supervisord.conf \
|
||||
-t /usr/share/sonic/templates/wait_for_intf.sh.j2,/usr/bin/wait_for_intf.sh \
|
||||
-t /usr/share/sonic/templates/port-name-alias-map.txt.j2,/tmp/port-name-alias-map.txt \
|
||||
"
|
||||
sonic-cfggen $CFGGEN_PARAMS
|
||||
|
||||
# Make the script that waits for all interfaces to come up executable
|
||||
chmod +x /usr/bin/wait_for_intf.sh
|
||||
|
||||
# Generate port name-alias map for isc-dhcp-relay to parse. Each line contains one
|
||||
# name-alias pair of the form "<name> <alias>"
|
||||
sonic-cfggen -d --var-json "PORT" | python -c "import sys, json, os; [sys.stdout.write('%s %s\n' % (k, v['alias'] if 'alias' in v else k)) for (k, v) in json.load(sys.stdin).iteritems()]" > /tmp/port-name-alias-map.txt
|
||||
|
||||
# The docker container should start this script as PID 1, so now that supervisord is
|
||||
# properly configured, we exec supervisord so that it runs as PID 1 for the
|
||||
# duration of the container's lifetime
|
||||
|
5
dockers/docker-dhcp-relay/port-name-alias-map.txt.j2
Normal file
5
dockers/docker-dhcp-relay/port-name-alias-map.txt.j2
Normal file
@ -0,0 +1,5 @@
|
||||
{# Generate port name-alias map for isc-dhcp-relay to parse. Each line contains one #}
|
||||
{# name-alias pair of the form "<name> <alias>" #}
|
||||
{% for port, config in PORT.items() %}
|
||||
{{- port }} {% if "alias" in config %}{{ config["alias"] }}{% else %}{{ port }}{% endif %} {{- "\n" -}}
|
||||
{% endfor -%}
|
Loading…
Reference in New Issue
Block a user