Skip to content

Commit

Permalink
[ChassisDB]: bring up ChassisDB service (sonic-net#5283)
Browse files Browse the repository at this point in the history
bring up chassisdb service on sonic switch according to the design in
Distributed Forwarding in VoQ Arch HLD

Signed-off-by: Honggang Xu <[email protected]>

**- Why I did it**
To bring up new ChassisDB service in sonic as designed in ['Distributed forwarding in a VOQ architecture HLD' ](https://github.com/Azure/SONiC/blob/90c1289eaf89a70939e7c81e042e261947c6a850/doc/chassis/architecture.md). 

**- How I did it**
Implement the section 2.3.1 Global DB Organization of the VOQ architecture HLD.

**- How to verify it**
ChassisDB service won't start without chassisdb.conf file on the existing platforms.
ChassisDB service is accessible with global.conf file in the distributed arichitecture.

Signed-off-by: Honggang Xu <[email protected]>
  • Loading branch information
BrynXu authored Oct 14, 2020
1 parent 8b135af commit a2e3d2f
Show file tree
Hide file tree
Showing 22 changed files with 367 additions and 129 deletions.
2 changes: 2 additions & 0 deletions device/arista/x86_64-arista_7800_sup/chassisdb.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
start_chassis_db=1
chassis_db_address=127.100.1.1
1 change: 1 addition & 0 deletions device/arista/x86_64-arista_7800r3_48cq2_lc/chassisdb.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
chassis_db_address=127.100.1.1
1 change: 1 addition & 0 deletions dockers/docker-database/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ COPY ["database_global.json.j2", "/usr/share/sonic/templates/"]
COPY ["files/supervisor-proc-exit-listener", "/usr/bin"]
COPY ["files/sysctl-net.conf", "/etc/sysctl.d/"]
COPY ["critical_processes", "/etc/supervisor"]
COPY ["files/update_chassisdb_config", "/usr/local/bin/"]

ENTRYPOINT ["/usr/local/bin/docker-database-init.sh"]
11 changes: 11 additions & 0 deletions dockers/docker-database/database_config.json.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
"port" : 6379,
"unix_socket_path" : "/var/run/redis{{NAMESPACE_ID}}/redis.sock",
"persistence_for_warm_boot" : "yes"
},
"redis_chassis":{
"hostname" : "redis_chassis.server",
"port": 6380,
"unix_socket_path": "/var/run/redis-chassis/redis_chassis.sock",
"persistence_for_warm_boot" : "yes"
}
},
"DATABASES" : {
Expand Down Expand Up @@ -72,6 +78,11 @@
"id" : 11,
"separator": "|",
"instance" : "redis"
},
"CHASSIS_APP_DB" : {
"id" : 12,
"separator": "|",
"instance" : "redis_chassis"
}
},
"VERSION" : "1.0"
Expand Down
44 changes: 41 additions & 3 deletions dockers/docker-database/docker-database-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,45 @@ fi

REDIS_DIR=/var/run/redis$NAMESPACE_ID
mkdir -p $REDIS_DIR/sonic-db
mkdir -p /etc/supervisor/conf.d/

if [ -f /etc/sonic/database_config$NAMESPACE_ID.json ]; then
cp /etc/sonic/database_config$NAMESPACE_ID.json $REDIS_DIR/sonic-db/database_config.json
else
HOST_IP=$host_ip j2 /usr/share/sonic/templates/database_config.json.j2 > $REDIS_DIR/sonic-db/database_config.json
fi

mkdir -p /etc/supervisor/conf.d/
# on VoQ system, we only publish redis_chassis instance and CHASSIS_APP_DB when
# either chassisdb.conf indicates starts chassis_db or connect to chassis_db,
# and redis_chassis instance is started in different container.
# in order to do that, first we save original database config file, then
# call update_chasissdb_config to remove chassis_db config from
# the original database config file and use the modified config file to generate
# supervisord config, so that we won't start redis_chassis service.
# then we will decide to publish modified or original database config file based
# on the setting in chassisdb.conf
start_chassis_db=0
chassis_db_address=""
chassis_db_port=""
chassisdb_config="/etc/sonic/chassisdb.conf"
[ -f $chassisdb_config ] && source $chassisdb_config

db_cfg_file="/var/run/redis/sonic-db/database_config.json"
db_cfg_file_tmp="/var/run/redis/sonic-db/database_config.json.tmp"
cp $db_cfg_file $db_cfg_file_tmp

if [[ $DATABASE_TYPE == "chassisdb" ]]; then
# Docker init for database-chassis
echo "Init docker-database-chassis..."
update_chassisdb_config -j $db_cfg_file_tmp -k -p $chassis_db_port
mkdir -p /var/run/redis/sonic-db
cp /etc/default/sonic-db/database_config.json /var/run/redis/sonic-db
# generate all redis server supervisord configuration file
sonic-cfggen -j $db_cfg_file_tmp -t /usr/share/sonic/templates/supervisord.conf.j2 > /etc/supervisor/conf.d/supervisord.conf
rm $db_cfg_file_tmp
exec /usr/bin/supervisord
exit 0
fi

# copy/generate the database_global.json file if this is global database service in multi asic platform.
if [[ $NAMESPACE_ID == "" ]] && [[ $NAMESPACE_COUNT -gt 1 ]]
Expand All @@ -37,8 +68,15 @@ then
j2 /usr/share/sonic/templates/database_global.json.j2 > $REDIS_DIR/sonic-db/database_global.json
fi
fi
# delete chassisdb config to generate supervisord config
update_chassisdb_config -j $db_cfg_file_tmp -d
sonic-cfggen -j $db_cfg_file_tmp -t /usr/share/sonic/templates/supervisord.conf.j2 > /etc/supervisor/conf.d/supervisord.conf

# generate all redis server supervisord configuration file
sonic-cfggen -j /var/run/redis/sonic-db/database_config.json -t /usr/share/sonic/templates/supervisord.conf.j2 > /etc/supervisor/conf.d/supervisord.conf
if [[ "$start_chassis_db" != "1" ]] && [[ -z "$chassis_db_address" ]]; then
cp $db_cfg_file_tmp $db_cfg_file
else
update_chassisdb_config -j $db_cfg_file -p $chassis_db_port
fi
rm $db_cfg_file_tmp

exec /usr/bin/supervisord
2 changes: 1 addition & 1 deletion dockers/docker-database/supervisord.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ stderr_logfile=syslog
{% if INSTANCES %}
{% for redis_inst, redis_items in INSTANCES.iteritems() %}
[program: {{ redis_inst }}]
{% if redis_items['hostname'] != '127.0.0.1' %}
{% if redis_items['hostname'] != '127.0.0.1' and redis_inst != 'redis_chassis' %}
{%- set LOOPBACK_IP = '127.0.0.1' -%}
{%- else -%}
{%- set LOOPBACK_IP = '' -%}
Expand Down
12 changes: 12 additions & 0 deletions files/build_templates/config-chassisdb.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Config chassis_db
After=rc-local.service
Requires=rc-local.service

[Service]
Type=oneshot
ExecStart=/usr/bin/config-chassisdb
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
Loading

0 comments on commit a2e3d2f

Please sign in to comment.