-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[docker-syncd-brcm] [docker-syncd-mlnx]: Properly manage syncd with supervisord #585
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,122 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Based on /etc/init.d/syncd | ||
|
||
function clean_up { | ||
service syncd stop | ||
exit | ||
CMD_SYNCD=/usr/bin/syncd | ||
|
||
CMD_DSSERVE=/usr/bin/dsserve | ||
CMD_DSSERVE_ARGS="$CMD_SYNCD --diag" | ||
|
||
ENABLE_SAITHRIFT=0 | ||
|
||
PLATFORM_DIR=/usr/share/sonic/platform | ||
HWSKU_DIR=/usr/share/sonic/hwsku | ||
|
||
if [ -x $CMD_DSSERVE ]; then | ||
CMD=$CMD_DSSERVE | ||
CMD_ARGS=$CMD_DSSERVE_ARGS | ||
else | ||
CMD=$CMD_SYNCD | ||
fi | ||
|
||
parse_yaml() { | ||
local prefix=$2 | ||
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034') | ||
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \ | ||
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 | | ||
awk -F$fs '{ | ||
indent = length($1)/2; | ||
vname[indent] = $2; | ||
for (i in vname) {if (i > indent) {delete vname[i]}} | ||
if (length($3) > 0) { | ||
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")} | ||
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3); | ||
} | ||
}' | ||
} | ||
|
||
start_bcm() | ||
{ | ||
[ -e /dev/linux-bcm-knet ] || mknod /dev/linux-bcm-knet c 122 0 | ||
[ -e /dev/linux-user-bde ] || mknod /dev/linux-user-bde c 126 0 | ||
[ -e /dev/linux-kernel-bde ] || mknod /dev/linux-kernel-bde c 127 0 | ||
} | ||
|
||
start_mlnx() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is for mellanox platform. can we consider to still put this syncd.sh into the sairedis repo? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it also possible to take common parts to separate script so that it will be easier to maintain init.d and supervisord all at once? |
||
{ | ||
[ -e /dev/sxdevs/sxcdev ] || ( mkdir -p /dev/sxdevs && mknod /dev/sxdevs/sxcdev c 231 193 ) | ||
|
||
# Read MAC address and align the last 6 bits. | ||
MAC_ADDRESS=`ip link show eth0 | grep ether | awk '{print $2}'` | ||
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 | ||
ALIGNED_MAC_ADDRESS=`python -c "print '$MAC_ADDRESS'[:-2] + '$aligned_last_byte'"` # put aligned byte into the end of MAC | ||
|
||
# Write MAC address into /tmp/profile file. | ||
cat $HWSKU_DIR/sai.profile > /tmp/sai.profile | ||
echo "DEVICE_MAC_ADDRESS=$ALIGNED_MAC_ADDRESS" >> /tmp/sai.profile | ||
} | ||
|
||
trap clean_up SIGTERM SIGKILL | ||
start_centec() | ||
{ | ||
[ -e /dev/linux_dal ] || mknod /dev/linux_dal c 198 0 | ||
[ -e /dev/net/tun ] || ( mkdir -p /dev/net && mknod /dev/net/tun c 10 200 ) | ||
|
||
# Read MAC address and align the last 6 bits. | ||
MAC_ADDRESS=`ip link show eth0 | grep ether | awk '{print $2}'` | ||
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 | ||
ALIGNED_MAC_ADDRESS=`python -c "print '$MAC_ADDRESS'[:-2] + '$aligned_last_byte'"` # put aligned byte into the end of MAC | ||
|
||
# Write MAC address into /tmp/profile file. | ||
|
||
# Write MAC address into /tmp/profile file. | ||
cat $HWSKU_DIR/sai.profile > /tmp/sai.profile | ||
echo "DEVICE_MAC_ADDRESS=$ALIGNED_MAC_ADDRESS" >> /tmp/sai.profile | ||
} | ||
|
||
start_cavium() | ||
{ | ||
export XP_ROOT=/usr/bin/ | ||
} | ||
|
||
case "$(cat /proc/cmdline)" in | ||
*fast-reboot*) | ||
FAST_REBOOT='yes' | ||
;; | ||
*) | ||
FAST_REBOOT='no' | ||
;; | ||
esac | ||
|
||
eval $(parse_yaml /etc/sonic/sonic_version.yml "sonic_") | ||
|
||
if [ $sonic_asic_type == "broadcom" ]; then | ||
start_bcm | ||
CMD_ARGS+=" -p $HWSKU_DIR/sai.profile " | ||
if [ $FAST_REBOOT == "yes" ]; | ||
then | ||
CMD_ARGS+=" -t fast " | ||
fi | ||
elif [ $sonic_asic_type == "mellanox" ]; then | ||
start_mlnx | ||
CMD_ARGS+=" -p /tmp/sai.profile " | ||
elif [ $sonic_asic_type == "cavium" ]; then | ||
CMD_ARGS+=" -p $HWSKU_DIR/sai.profile " | ||
start_cavium | ||
elif [ $sonic_asic_type == "centec" ]; then | ||
start_centec | ||
CMD_ARGS+=" -p /tmp/sai.profile " | ||
else | ||
echo "Unknown asic type $sonic_asic_type" | ||
exit 1 | ||
fi | ||
|
||
if [ ${ENABLE_SAITHRIFT} == 1 ]; then | ||
CMD_ARGS+=" -r -m $HWSKU_DIR/port_config.ini" | ||
fi | ||
|
||
[ -r $PLATFORM_DIR/syncd.conf ] && . $PLATFORM_DIR/syncd.conf | ||
|
||
service syncd start | ||
exec ${CMD} ${CMD_ARGS} | ||
|
||
read |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,122 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Based on /etc/init.d/syncd | ||
|
||
function clean_up { | ||
service syncd stop | ||
exit | ||
CMD_SYNCD=/usr/bin/syncd | ||
|
||
CMD_DSSERVE=/usr/bin/dsserve | ||
CMD_DSSERVE_ARGS="$CMD_SYNCD --diag" | ||
|
||
ENABLE_SAITHRIFT=0 | ||
|
||
PLATFORM_DIR=/usr/share/sonic/platform | ||
HWSKU_DIR=/usr/share/sonic/hwsku | ||
|
||
if [ -x $CMD_DSSERVE ]; then | ||
CMD=$CMD_DSSERVE | ||
CMD_ARGS=$CMD_DSSERVE_ARGS | ||
else | ||
CMD=$CMD_SYNCD | ||
fi | ||
|
||
parse_yaml() { | ||
local prefix=$2 | ||
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034') | ||
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \ | ||
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 | | ||
awk -F$fs '{ | ||
indent = length($1)/2; | ||
vname[indent] = $2; | ||
for (i in vname) {if (i > indent) {delete vname[i]}} | ||
if (length($3) > 0) { | ||
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")} | ||
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3); | ||
} | ||
}' | ||
} | ||
|
||
start_bcm() | ||
{ | ||
[ -e /dev/linux-bcm-knet ] || mknod /dev/linux-bcm-knet c 122 0 | ||
[ -e /dev/linux-user-bde ] || mknod /dev/linux-user-bde c 126 0 | ||
[ -e /dev/linux-kernel-bde ] || mknod /dev/linux-kernel-bde c 127 0 | ||
} | ||
|
||
start_mlnx() | ||
{ | ||
[ -e /dev/sxdevs/sxcdev ] || ( mkdir -p /dev/sxdevs && mknod /dev/sxdevs/sxcdev c 231 193 ) | ||
|
||
# Read MAC address and align the last 6 bits. | ||
MAC_ADDRESS=`ip link show eth0 | grep ether | awk '{print $2}'` | ||
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 | ||
ALIGNED_MAC_ADDRESS=`python -c "print '$MAC_ADDRESS'[:-2] + '$aligned_last_byte'"` # put aligned byte into the end of MAC | ||
|
||
# Write MAC address into /tmp/profile file. | ||
cat $HWSKU_DIR/sai.profile > /tmp/sai.profile | ||
echo "DEVICE_MAC_ADDRESS=$ALIGNED_MAC_ADDRESS" >> /tmp/sai.profile | ||
} | ||
|
||
start_centec() | ||
{ | ||
[ -e /dev/linux_dal ] || mknod /dev/linux_dal c 198 0 | ||
[ -e /dev/net/tun ] || ( mkdir -p /dev/net && mknod /dev/net/tun c 10 200 ) | ||
|
||
# Read MAC address and align the last 6 bits. | ||
MAC_ADDRESS=`ip link show eth0 | grep ether | awk '{print $2}'` | ||
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 | ||
ALIGNED_MAC_ADDRESS=`python -c "print '$MAC_ADDRESS'[:-2] + '$aligned_last_byte'"` # put aligned byte into the end of MAC | ||
|
||
# Write MAC address into /tmp/profile file. | ||
|
||
# Write MAC address into /tmp/profile file. | ||
cat $HWSKU_DIR/sai.profile > /tmp/sai.profile | ||
echo "DEVICE_MAC_ADDRESS=$ALIGNED_MAC_ADDRESS" >> /tmp/sai.profile | ||
} | ||
|
||
start_cavium() | ||
{ | ||
export XP_ROOT=/usr/bin/ | ||
} | ||
|
||
trap clean_up SIGTERM SIGKILL | ||
case "$(cat /proc/cmdline)" in | ||
*fast-reboot*) | ||
FAST_REBOOT='yes' | ||
;; | ||
*) | ||
FAST_REBOOT='no' | ||
;; | ||
esac | ||
|
||
eval $(parse_yaml /etc/sonic/sonic_version.yml "sonic_") | ||
|
||
if [ $sonic_asic_type == "broadcom" ]; then | ||
start_bcm | ||
CMD_ARGS+=" -p $HWSKU_DIR/sai.profile " | ||
if [ $FAST_REBOOT == "yes" ]; | ||
then | ||
CMD_ARGS+=" -t fast " | ||
fi | ||
elif [ $sonic_asic_type == "mellanox" ]; then | ||
start_mlnx | ||
CMD_ARGS+=" -p /tmp/sai.profile " | ||
elif [ $sonic_asic_type == "cavium" ]; then | ||
CMD_ARGS+=" -p $HWSKU_DIR/sai.profile " | ||
start_cavium | ||
elif [ $sonic_asic_type == "centec" ]; then | ||
start_centec | ||
CMD_ARGS+=" -p /tmp/sai.profile " | ||
else | ||
echo "Unknown asic type $sonic_asic_type" | ||
exit 1 | ||
fi | ||
|
||
# fw-upgrade will exit if firmware was actually upgraded or if some error | ||
# occures | ||
. mlnx-fw-upgrade.sh | ||
if [ ${ENABLE_SAITHRIFT} == 1 ]; then | ||
CMD_ARGS+=" -r -m $HWSKU_DIR/port_config.ini" | ||
fi | ||
|
||
# FIXME: the script cannot trap SIGTERM signal and it exits without clean_up | ||
# Remove rsyslogd.pid file manually so that to start the rsyslog instantly | ||
service syncd start | ||
[ -r $PLATFORM_DIR/syncd.conf ] && . $PLATFORM_DIR/syncd.conf | ||
|
||
read | ||
exec ${CMD} ${CMD_ARGS} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to use sonic-cfggen instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better, however, the syncd dockers are currently built from docker-base, not docker-config-engine, so they don't have sonic-cfggen available. I plan to create a new PR that will do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we could replace the docker-base with docker-config-engine.