-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docker-teamd]: Manage teamd and teamsyncd processes with supervisor (#…
- Loading branch information
Showing
10 changed files
with
240 additions
and
64 deletions.
There are no files selected for viewing
This file contains 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 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,43 @@ | ||
#!/usr/bin/env bash | ||
|
||
TEAMD_CONF_PATH="/etc/teamd" | ||
|
||
rm -rf $TEAMD_CONF_PATH | ||
mkdir -p $TEAMD_CONF_PATH | ||
|
||
SONIC_ASIC_TYPE=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type) | ||
MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}') | ||
|
||
# Align last byte | ||
if [ "$SONIC_ASIC_TYPE" == "mellanox" -o "$SONIC_ASIC_TYPE" == "centec" ]; then | ||
last_byte=$(python -c "print '$MAC_ADDRESS'[-2:]") | ||
aligned_last_byte=$(python -c "print format(int(int('$last_byte', 16) & 0b11000000), '02x')") # put mask and take away the 0x prefix | ||
MAC_ADDRESS=$(python -c "print '$MAC_ADDRESS'[:-2] + '$aligned_last_byte'") # put aligned byte into the end of MAC | ||
fi | ||
|
||
for pc in `sonic-cfggen -d -v "PORTCHANNEL.keys() | join(' ') if PORTCHANNEL"`; do | ||
sonic-cfggen -d -a '{"pc":"'$pc'","hwaddr":"'$MAC_ADDRESS'"}' -t /usr/share/sonic/templates/teamd.j2 > $TEAMD_CONF_PATH/$pc.conf | ||
# bring down all member ports before starting teamd | ||
for member in $(sonic-cfggen -d -v "PORTCHANNEL['$pc']['members'] | join(' ')" ); do | ||
if [ -L /sys/class/net/$member ]; then | ||
ip link set $member down | ||
fi | ||
done | ||
done | ||
|
||
# Create a Python dictionary where the key is the Jinja2 variable name | ||
# "lags" and the value is a list of dctionaries containing the name of | ||
# the LAG and the path of the LAG config file. Then output this in | ||
# JSON format, as we will pass it to sonic-cfggen as additional data | ||
# below for generating the supervisord config file. | ||
# Example output: {"lags": [{"name": "PortChannel1", "file": "/etc/teamd/PortChannel1.conf"}, {"name": "PortChannel2", "file": "/etc/teamd/PortChannel2.conf"}]} | ||
LAG_INFO_DICT=$(python -c "import json,os,sys; lags_dict = {}; lags_dict['lags'] = [{'name': os.path.basename(file).split('.')[0], 'file': os.path.join('${TEAMD_CONF_PATH}', file)} for file in sorted(os.listdir('${TEAMD_CONF_PATH}'))]; sys.stdout.write(json.dumps(lags_dict))") | ||
|
||
# Generate supervisord config file | ||
mkdir -p /etc/supervisor/conf.d/ | ||
sonic-cfggen -d -a "${LAG_INFO_DICT}" -t /usr/share/sonic/templates/docker-teamd.supervisord.conf.j2 > /etc/supervisor/conf.d/docker-teamd.supervisord.conf | ||
|
||
# The Docker container should start this script as PID 1, so now that we | ||
# have generated the proper supervisord configuration, we exec supervisord | ||
# so that it runs as PID 1 for the duration of the container's lifetime | ||
exec /usr/bin/supervisord |
This file contains 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,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
rm -f /var/run/rsyslogd.pid | ||
|
||
supervisorctl start rsyslogd | ||
|
||
supervisorctl start teamd:* | ||
|
||
supervisorctl start teamsyncd |
This file contains 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,52 @@ | ||
[supervisord] | ||
logfile_maxbytes=1MB | ||
logfile_backups=2 | ||
nodaemon=true | ||
|
||
[program:docker-teamd-start.sh] | ||
command=/usr/bin/docker-teamd-start.sh | ||
priority=1 | ||
autostart=true | ||
autorestart=false | ||
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 | ||
|
||
{# If there are LAGs... #} | ||
{% if lags -%} | ||
[group:teamd] | ||
programs= | ||
{%- set add_preceding_comma = { 'flag': False } -%} | ||
{%- for lag in lags -%} | ||
{%- if add_preceding_comma.flag %},{% endif -%} | ||
{%- set _dummy = add_preceding_comma.update({'flag': True}) -%} | ||
teamd-{{ lag['name'] }} | ||
{%- endfor %} | ||
|
||
{# Create a program entry for each teamd instance #} | ||
{% for lag in lags %} | ||
|
||
[program:teamd-{{ lag['name'] }}] | ||
command=/usr/bin/teamd.sh {{ lag['file'] }} | ||
priority=3 | ||
autostart=false | ||
autorestart=false | ||
stdout_logfile=syslog | ||
stderr_logfile=syslog | ||
{% endfor %} | ||
|
||
[program:teamsyncd] | ||
command=/usr/bin/teamsyncd | ||
priority=4 | ||
autostart=false | ||
autorestart=false | ||
stdout_logfile=syslog | ||
stderr_logfile=syslog | ||
{% endif %} |
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,28 +1,15 @@ | ||
#!/usr/bin/env bash | ||
|
||
TEAMD_CONF_PATH=/etc/teamd | ||
|
||
function start_app { | ||
rm -f /var/run/teamd/* | ||
if [ "$(ls -A $TEAMD_CONF_PATH)" ]; then | ||
for f in $TEAMD_CONF_PATH/*; do | ||
teamd -f $f -d | ||
done | ||
fi | ||
teamsyncd & | ||
} | ||
TEAMD_CONF_FILE=$1 | ||
|
||
function clean_up { | ||
if [ "$(ls -A $TEAMD_CONF_PATH)" ]; then | ||
for f in $TEAMD_CONF_PATH/*; do | ||
teamd -f $f -k | ||
done | ||
fi | ||
pkill -9 teamsyncd | ||
exit | ||
teamd -f $TEAMD_CONF_FILE -k | ||
exit $? | ||
} | ||
|
||
trap clean_up SIGTERM SIGKILL | ||
|
||
start_app | ||
read | ||
teamd -f $TEAMD_CONF_FILE & | ||
TEAMD_PID=$! | ||
wait $TEAMD_PID | ||
exit $? |
This file contains 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
64 changes: 64 additions & 0 deletions
64
src/sonic-config-engine/tests/sample_output/docker-teamd.supervisord.conf
This file contains 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,64 @@ | ||
[supervisord] | ||
logfile_maxbytes=1MB | ||
logfile_backups=2 | ||
nodaemon=true | ||
|
||
[program:docker-teamd-start.sh] | ||
command=/usr/bin/docker-teamd-start.sh | ||
priority=1 | ||
autostart=true | ||
autorestart=false | ||
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 | ||
|
||
[group:teamd] | ||
programs=teamd-PortChannel01,teamd-PortChannel02,teamd-PortChannel03,teamd-PortChannel04 | ||
|
||
[program:teamd-PortChannel01] | ||
command=/usr/bin/teamd.sh /sonic/src/sonic-config-engine/tests/sample_output/t0_sample_output/PortChannel01.conf | ||
priority=3 | ||
autostart=false | ||
autorestart=false | ||
stdout_logfile=syslog | ||
stderr_logfile=syslog | ||
|
||
[program:teamd-PortChannel02] | ||
command=/usr/bin/teamd.sh /sonic/src/sonic-config-engine/tests/sample_output/t0_sample_output/PortChannel02.conf | ||
priority=3 | ||
autostart=false | ||
autorestart=false | ||
stdout_logfile=syslog | ||
stderr_logfile=syslog | ||
|
||
[program:teamd-PortChannel03] | ||
command=/usr/bin/teamd.sh /sonic/src/sonic-config-engine/tests/sample_output/t0_sample_output/PortChannel03.conf | ||
priority=3 | ||
autostart=false | ||
autorestart=false | ||
stdout_logfile=syslog | ||
stderr_logfile=syslog | ||
|
||
[program:teamd-PortChannel04] | ||
command=/usr/bin/teamd.sh /sonic/src/sonic-config-engine/tests/sample_output/t0_sample_output/PortChannel04.conf | ||
priority=3 | ||
autostart=false | ||
autorestart=false | ||
stdout_logfile=syslog | ||
stderr_logfile=syslog | ||
|
||
[program:teamsyncd] | ||
command=/usr/bin/teamsyncd | ||
priority=4 | ||
autostart=false | ||
autorestart=false | ||
stdout_logfile=syslog | ||
stderr_logfile=syslog | ||
|
28 changes: 28 additions & 0 deletions
28
src/sonic-config-engine/tests/sample_output/wait_for_intf.sh
This file contains 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,28 @@ | ||
#!/usr/bin/env bash | ||
|
||
function wait_until_iface_exists | ||
{ | ||
IFACE=$1 | ||
|
||
echo "Waiting for interface ${IFACE}..." | ||
|
||
# Wait for the interface to come up (i.e., 'ip link show' returns 0) | ||
until ip link show $IFACE > /dev/null 2>&1; do | ||
sleep 1 | ||
done | ||
|
||
echo "Interface ${IFACE} is created" | ||
} | ||
|
||
|
||
# Wait for all interfaces to come up before starting the DHCP relay | ||
wait_until_iface_exists Vlan1000 | ||
wait_until_iface_exists PortChannel04 | ||
wait_until_iface_exists PortChannel02 | ||
wait_until_iface_exists PortChannel03 | ||
wait_until_iface_exists PortChannel03 | ||
wait_until_iface_exists PortChannel01 | ||
wait_until_iface_exists PortChannel02 | ||
wait_until_iface_exists PortChannel04 | ||
wait_until_iface_exists PortChannel01 | ||
|
This file contains 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