Skip to content

Commit eff6984

Browse files
authored
Merge branch 'master' into master_lc
2 parents e065786 + 581e276 commit eff6984

File tree

8 files changed

+55
-9
lines changed

8 files changed

+55
-9
lines changed

dockers/docker-database/docker-database-init.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ if [[ $DATABASE_TYPE == "chassisdb" ]]; then
8282
VAR_LIB_REDIS_CHASSIS_DIR="/var/lib/redis_chassis"
8383
mkdir -p $VAR_LIB_REDIS_CHASSIS_DIR
8484
update_chassisdb_config -j $db_cfg_file_tmp -k -p $chassis_db_port
85+
# Set protected mode based on the hostname
86+
additional_data_json=$(jq -c '{INSTANCES: .INSTANCES | map_values({is_protected_mode: (.hostname == "127.0.0.1")})}' "$db_cfg_file_tmp")
8587
# generate all redis server supervisord configuration file
86-
sonic-cfggen -j $db_cfg_file_tmp \
88+
sonic-cfggen -j $db_cfg_file_tmp -a "$additional_data_json" \
8789
-t /usr/share/sonic/templates/supervisord.conf.j2,/etc/supervisor/conf.d/supervisord.conf \
8890
-t /usr/share/sonic/templates/critical_processes.j2,/etc/supervisor/critical_processes
8991
rm $db_cfg_file_tmp
@@ -104,7 +106,13 @@ then
104106
fi
105107
# delete chassisdb config to generate supervisord config
106108
update_chassisdb_config -j $db_cfg_file_tmp -d
107-
sonic-cfggen -j $db_cfg_file_tmp \
109+
# Set protected mode based on the hostname
110+
additional_data_json=$(jq -c '{INSTANCES: .INSTANCES | map_values({is_protected_mode: (.hostname == "127.0.0.1")})}' "$db_cfg_file_tmp")
111+
# For Linecard databases, disable Redis protected mode to expose them to the midplane.
112+
if [ -f "$chassisdb_config" ] && [[ "$start_chassis_db" != "1" ]]; then
113+
additional_data_json=$(jq -c '{INSTANCES: .INSTANCES | map_values({is_protected_mode: false})}' "$db_cfg_file_tmp")
114+
fi
115+
sonic-cfggen -j "$db_cfg_file_tmp" -a "$additional_data_json" \
108116
-t /usr/share/sonic/templates/supervisord.conf.j2,/etc/supervisor/conf.d/supervisord.conf \
109117
-t /usr/share/sonic/templates/critical_processes.j2,/etc/supervisor/critical_processes
110118

dockers/docker-database/supervisord.conf.j2

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@ dependent_startup=true
3535
{%- if redis_inst != 'remote_redis' %}
3636
[program:{{ redis_inst }}]
3737
{% if redis_items['hostname'] != '127.0.0.1' %}
38-
{%- set ADDITIONAL_OPTS = '--protected-mode no' %}
3938
{%- if redis_inst != 'redis_chassis' %}
4039
{%- set LOOPBACK_IP = '127.0.0.1' -%}
4140
{%- endif -%}
4241
{%- else -%}
4342
{%- set LOOPBACK_IP = '' -%}
43+
{%- endif -%}
44+
{%- if not redis_items['is_protected_mode'] %}
45+
{%- set ADDITIONAL_OPTS = '--protected-mode no' %}
46+
{%- else %}
4447
{%- set ADDITIONAL_OPTS = '' %}
4548
{%- endif -%}
4649
command=/bin/bash -c "{ [[ -s /var/lib/{{ redis_inst }}/dump.rdb ]] || rm -f /var/lib/{{ redis_inst }}/dump.rdb; } && mkdir -p /var/lib/{{ redis_inst }} && exec /usr/bin/redis-server /etc/redis/redis.conf --bind {{ LOOPBACK_IP }} {{ redis_items['hostname'] }} --port {{ redis_items['port'] }} --unixsocket {{ redis_items['unix_socket_path'] }} --pidfile /var/run/redis/{{ redis_inst }}.pid --dir /var/lib/{{ redis_inst }} {{ ADDITIONAL_OPTS }}"

files/build_templates/docker_image_ctl.j2

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ function postStartAction()
173173
{%- if docker_container_name == "database" %}
174174
midplane_ip=""
175175
CHASSISDB_CONF="/usr/share/sonic/device/$PLATFORM/chassisdb.conf"
176+
if [[ -f $CHASSISDB_CONF && $DATABASE_TYPE != "dpudb" ]]; then
177+
slot_id=$(python3 -c 'import sonic_platform.platform; platform_chassis = sonic_platform.platform.Platform().get_chassis(); print(platform_chassis.get_my_slot())' 2>/dev/null)
178+
supervisor_slot_id=$(python3 -c 'import sonic_platform.platform; platform_chassis = sonic_platform.platform.Platform().get_chassis(); print(platform_chassis.get_supervisor_slot())' 2>/dev/null)
179+
fi
176180
[ -f $CHASSISDB_CONF ] && source $CHASSISDB_CONF
177181
if [[ "$DEV" && $DATABASE_TYPE != "dpudb" ]]; then
178182
# Enable the forwarding on eth0 interface in namespace.
@@ -188,9 +192,6 @@ function postStartAction()
188192
ip netns exec "$NET_NS" ip addr add 127.0.0.1/16 dev lo
189193
ip netns exec "$NET_NS" ip addr del 127.0.0.1/8 dev lo
190194

191-
slot_id=$(python3 -c 'import sonic_platform.platform; platform_chassis = sonic_platform.platform.Platform().get_chassis(); print(platform_chassis.get_my_slot())' 2>/dev/null)
192-
supervisor_slot_id=$(python3 -c 'import sonic_platform.platform; platform_chassis = sonic_platform.platform.Platform().get_chassis(); print(platform_chassis.get_supervisor_slot())' 2>/dev/null)
193-
194195
# Create eth1 in database instance
195196
if [[ "${slot_id}" == "${supervisor_slot_id}" ]]; then
196197
ip link add name ns-eth1"$NET_NS" type veth peer name eth1@"$NET_NS"
@@ -235,6 +236,12 @@ function postStartAction()
235236
fi
236237
fi
237238
fi
239+
240+
# midplane ip for the Linecard database container
241+
if [[ -z "$DEV" && "$DATABASE_TYPE" != "dpudb" && -f $CHASSISDB_CONF && "${slot_id}" != "${supervisor_slot_id}" ]]; then
242+
midplane_ip=$(docker exec -i ${DOCKERNAME} ip addr show eth1-midplane | grep 'inet ' | awk '{print $2}' | cut -d'/' -f1)
243+
fi
244+
238245
# Setup ebtables configuration
239246
{%- if sonic_asic_platform != "vs" %}
240247
ebtables_config
@@ -330,8 +337,8 @@ function postStartAction()
330337
REDIS_SOCK="/var/run/redis-chassis/redis_chassis.sock"
331338
fi
332339
chgrp -f redis $REDIS_SOCK && chmod -f 0760 $REDIS_SOCK
333-
334-
if [[ $DEV && $midplane_ip ]]; then
340+
# Binding the midplane ip to the redisdb
341+
if [[ -n "$midplane_ip" ]]; then
335342
IFS=_ read ip port < <(jq -r '.INSTANCES | [.redis.hostname, .redis.port] | join("_")' /var/run/redis$DEV/sonic-db/database_config.json)
336343
bound_ips=$(redis-cli --raw -h $ip -p $port config get bind | sed -n '2,2 p')
337344
redis-cli -h $ip -p $port config set bind "$bound_ips $midplane_ip"

files/build_templates/sonic_debian_extension.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@ install_deb_package {{deb}}
349349
{% endfor %}
350350
{% endif %}
351351

352+
# Install SONiC host services Rust deb package
353+
install_deb_package $debs_path/sonic-host-services-rs_*.deb
354+
352355
# Install sonic-db-cli
353356
install_deb_package $debs_path/sonic-db-cli_*.deb
354357

rules/sonic-host-services-rs.dep

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SPATH := $($(SONIC_HOST_SERVICES_RS)_SRC_PATH)
2+
DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/sonic-host-services-rs.mk rules/sonic-host-services-rs.dep
3+
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST)
4+
SMDEP_FILES := $(addprefix $(SPATH)/,$(shell cd $(SPATH) && git ls-files))
5+
6+
$(SONIC_HOST_SERVICES_RS)_CACHE_MODE := GIT_CONTENT_SHA
7+
$(SONIC_HOST_SERVICES_RS)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST)
8+
$(SONIC_HOST_SERVICES_RS)_DEP_FILES := $(DEP_FILES)
9+
$(SONIC_HOST_SERVICES_RS)_SMDEP_FILES := $(SMDEP_FILES)
10+
$(SONIC_HOST_SERVICES_RS)_SMDEP_PATHS := $(SPATH)

rules/sonic-host-services-rs.mk

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
SONIC_HOST_SERVICES_RS_VERSION = 1.0.0
2+
SONIC_HOST_SERVICES_RS_NAME = sonic-host-services-rs
3+
4+
SONIC_HOST_SERVICES_RS = $(SONIC_HOST_SERVICES_RS_NAME)_$(SONIC_HOST_SERVICES_RS_VERSION)_$(CONFIGURED_ARCH).deb
5+
$(SONIC_HOST_SERVICES_RS)_SRC_PATH = $(SRC_PATH)/sonic-host-services
6+
$(SONIC_HOST_SERVICES_RS)_VERSION = $(SONIC_HOST_SERVICES_RS_VERSION)
7+
$(SONIC_HOST_SERVICES_RS)_NAME = $(SONIC_HOST_SERVICES_RS_NAME)
8+
$(SONIC_HOST_SERVICES_RS)_DEPENDS = $(LIBSWSSCOMMON_DEV)
9+
$(SONIC_HOST_SERVICES_RS)_RDEPENDS = $(LIBSWSSCOMMON)
10+
11+
SONIC_DPKG_DEBS += $(SONIC_HOST_SERVICES_RS)
12+
13+
SONIC_HOST_SERVICES_RS_DBG = $(SONIC_HOST_SERVICES_RS_NAME)-dbgsym_$(SONIC_HOST_SERVICES_RS_VERSION)_$(CONFIGURED_ARCH).deb
14+
$(eval $(call add_derived_package,$(SONIC_HOST_SERVICES_RS),$(SONIC_HOST_SERVICES_RS_DBG)))

slave.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
13981398
$(SONIC_RSYSLOG_PLUGIN) \
13991399
$(SONIC_UTILITIES_DATA) \
14001400
$(SONIC_CTRMGRD_RS) \
1401+
$(SONIC_HOST_SERVICES_RS) \
14011402
$(SONIC_HOST_SERVICES_DATA) \
14021403
$(BASH) \
14031404
$(BASH_TACPLUS) \

0 commit comments

Comments
 (0)