sonic-buildimage/dockers/docker-fpm-frr/docker_init.sh
nmoray f978b2bb53
Timezone sync issue between the host and containers (#14000)
#### Why I did it
To fix the timezone sync issue between the containers and the host. If a certain timezone has been configured on the host (SONIC) then the expectation is to reflect the same across all the containers.

This will fix [Issue:13046](https://github.com/sonic-net/sonic-buildimage/issues/13046).

For instance, a PST timezone has been set on the host and if the user checks the link flap logs (inside the FRR), it shows the UTC timestamp. Ideally, it should be PST.
2023-06-25 16:36:09 -07:00

114 lines
4.4 KiB
Bash
Executable File

#!/usr/bin/env bash
mkdir -p /etc/frr
mkdir -p /etc/supervisor/conf.d
CFGGEN_PARAMS=" \
-d \
-y /etc/sonic/constants.yml \
-t /usr/share/sonic/templates/frr_vars.j2 \
-t /usr/share/sonic/templates/supervisord/supervisord.conf.j2,/etc/supervisor/conf.d/supervisord.conf \
-t /usr/share/sonic/templates/supervisord/critical_processes.j2,/etc/supervisor/critical_processes \
-t /usr/share/sonic/templates/isolate.j2,/usr/sbin/bgp-isolate \
-t /usr/share/sonic/templates/unisolate.j2,/usr/sbin/bgp-unisolate \
"
FRR_VARS=$(sonic-cfggen $CFGGEN_PARAMS)
CONFIG_TYPE=$(echo $FRR_VARS | jq -r '.docker_routing_config_mode')
update_default_gw()
{
IP_VER=${1}
# FRR is not running in host namespace so we need to delete
# default gw kernel route added by docker network via eth0 and add it back
# with higher administrative distance so that default route learnt
# by FRR becomes best route if/when available
GATEWAY_IP=$(ip -${IP_VER} route show default dev eth0 | awk '{print $3}')
#Check if docker default route is there
if [[ ! -z "$GATEWAY_IP" ]]; then
ip -${IP_VER} route del default dev eth0
#Make sure route is deleted
CHECK_GATEWAY_IP=$(ip -${IP_VER} route show default dev eth0 | awk '{print $3}')
if [[ -z "$CHECK_GATEWAY_IP" ]]; then
# Ref: http://docs.frrouting.org/en/latest/zebra.html#zebra-vrf
# Zebra does treat Kernel routes as special case for the purposes of Admin Distance. \
# Upon learning about a route that is not originated by FRR we read the metric value as a uint32_t.
# The top byte of the value is interpreted as the Administrative Distance and
# the low three bytes are read in as the metric.
# so here we are programming administrative distance of 210 (210 << 24) > 200 (for routes learnt via IBGP)
ip -${IP_VER} route add default via $GATEWAY_IP dev eth0 metric 3523215360
fi
fi
}
write_default_zebra_config()
{
FILE_NAME=${1}
grep -q '^no fpm use-next-hop-groups' $FILE_NAME || {
sed -i '1i no fpm use-next-hop-groups\nfpm address 127.0.0.1' $FILE_NAME
}
}
if [[ ! -z "$NAMESPACE_ID" ]]; then
update_default_gw 4
update_default_gw 6
fi
if [ -z "$CONFIG_TYPE" ] || [ "$CONFIG_TYPE" == "separated" ]; then
CFGGEN_PARAMS=" \
-d \
-y /etc/sonic/constants.yml \
-t /usr/share/sonic/templates/bgpd/gen_bgpd.conf.j2,/etc/frr/bgpd.conf \
-t /usr/share/sonic/templates/zebra/zebra.conf.j2,/etc/frr/zebra.conf \
-t /usr/share/sonic/templates/staticd/gen_staticd.conf.j2,/etc/frr/staticd.conf \
"
MGMT_FRAMEWORK_CONFIG=$(echo $FRR_VARS | jq -r '.frr_mgmt_framework_config')
if [ -n "$MGMT_FRAMEWORK_CONFIG" ] && [ "$MGMT_FRAMEWORK_CONFIG" != "false" ]; then
CFGGEN_PARAMS="$CFGGEN_PARAMS \
-t /usr/local/sonic/frrcfgd/bfdd.conf.j2,/etc/frr/bfdd.conf \
-t /usr/local/sonic/frrcfgd/ospfd.conf.j2,/etc/frr/ospfd.conf \
"
else
rm -f /etc/frr/bfdd.conf /etc/frr/ospfd.conf
fi
sonic-cfggen $CFGGEN_PARAMS
echo "no service integrated-vtysh-config" > /etc/frr/vtysh.conf
rm -f /etc/frr/frr.conf
elif [ "$CONFIG_TYPE" == "split" ]; then
echo "no service integrated-vtysh-config" > /etc/frr/vtysh.conf
rm -f /etc/frr/frr.conf
write_default_zebra_config /etc/frr/zebra.conf
elif [ "$CONFIG_TYPE" == "split-unified" ]; then
echo "service integrated-vtysh-config" > /etc/frr/vtysh.conf
rm -f /etc/frr/bgpd.conf /etc/frr/zebra.conf /etc/frr/staticd.conf
write_default_zebra_config /etc/frr/frr.conf
elif [ "$CONFIG_TYPE" == "unified" ]; then
CFGGEN_PARAMS=" \
-d \
-y /etc/sonic/constants.yml \
-t /usr/share/sonic/templates/gen_frr.conf.j2,/etc/frr/frr.conf \
"
sonic-cfggen $CFGGEN_PARAMS
echo "service integrated-vtysh-config" > /etc/frr/vtysh.conf
rm -f /etc/frr/bgpd.conf /etc/frr/zebra.conf /etc/frr/staticd.conf \
/etc/frr/bfdd.conf /etc/frr/ospfd.conf /etc/frr/pimd.conf
fi
chown -R frr:frr /etc/frr/
chown root:root /usr/sbin/bgp-isolate
chmod 0755 /usr/sbin/bgp-isolate
chown root:root /usr/sbin/bgp-unisolate
chmod 0755 /usr/sbin/bgp-unisolate
mkdir -p /var/sonic
echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status
TZ=$(cat /etc/timezone)
rm -rf /etc/localtime
ln -sf /usr/share/zoneinfo/$TZ /etc/localtime
exec /usr/local/bin/supervisord