create multiple Redis DB instances based on CONFIG at /etc/sonic/database_config.json (#2182)
this is the first step to moving different databases tables into different database instances
in this PR, only handle multiple database instances creation based on user configuration at /etc/sonic/database_config.json
we keep current method to create single database instance if no extra/new DATABASE configuration exist in database_config.json file.
if user try to configure more db instances at database_config.json , we create those new db instances along with the original db instance existing today.
The configuration is as below, later we can add more db related information if needed:
{
...
"DATABASE": {
"redis-db-01" : {
"port" : "6380",
"database": ["APPL_DB", "STATE_DB"]
},
"redis-db-02" : {
"port" : "6381",
"database":["ASIC_DB"]
},
}
...
}
The detail description is at design doc at Azure/SONiC#271
The main idea is : when database.sh started, we check the configuration and generate corresponding scripts.
rc.local service handle old_config copy when loading new images, there is no dependency between rc.local and database service today, for safety and make sure the copy operation are done before database try to read it, we make database service run after rc.local
Then database docker started, we check the configuration and generate corresponding scripts/.conf in database docker as well.
based on those conf, we create databases instances as required.
at last, we ping_pong check database are up and continue
Signed-off-by: Dong Zhang d.zhang@alibaba-inc.com
2019-08-28 13:15:10 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2020-06-30 16:32:04 -05:00
|
|
|
# For linux host namespace, in both single and multi ASIC platform use the loopback interface
|
|
|
|
# For other namespaces, use eth0 interface which is connected to the docker0 bridge in the host.
|
|
|
|
if [[ $NAMESPACE_ID == "" ]]
|
|
|
|
then
|
|
|
|
INTFC=lo
|
|
|
|
else
|
|
|
|
INTFC=eth0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Get the ip address of the interface
|
|
|
|
# if the ip address was not retrieved correctly, put localhost(127.0.0.1) as the default.
|
|
|
|
host_ip=$(ip -4 -o addr show $INTFC | awk '{print $4}' | cut -d'/' -f1 | head -1)
|
|
|
|
if [[ $host_ip == "" ]]
|
|
|
|
then
|
|
|
|
host_ip=127.0.0.1
|
|
|
|
fi
|
|
|
|
|
2023-11-17 11:10:03 -06:00
|
|
|
redis_port=6379
|
|
|
|
|
|
|
|
if [[ $DATABASE_TYPE == "dpudb" ]]; then
|
|
|
|
host_ip="169.254.200.254"
|
|
|
|
if ! ip -4 -o addr | awk '{print $4}' | grep $host_ip; then
|
|
|
|
host_ip=127.0.0.1
|
|
|
|
fi
|
|
|
|
DPU_ID=`echo $DEV | tr -dc '0-9'`
|
|
|
|
redis_port=`expr 6381 + $DPU_ID`
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2020-05-08 23:24:05 -05:00
|
|
|
REDIS_DIR=/var/run/redis$NAMESPACE_ID
|
|
|
|
mkdir -p $REDIS_DIR/sonic-db
|
2020-10-14 17:15:24 -05:00
|
|
|
mkdir -p /etc/supervisor/conf.d/
|
2020-05-08 23:24:05 -05:00
|
|
|
|
|
|
|
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
|
create multiple Redis DB instances based on CONFIG at /etc/sonic/database_config.json (#2182)
this is the first step to moving different databases tables into different database instances
in this PR, only handle multiple database instances creation based on user configuration at /etc/sonic/database_config.json
we keep current method to create single database instance if no extra/new DATABASE configuration exist in database_config.json file.
if user try to configure more db instances at database_config.json , we create those new db instances along with the original db instance existing today.
The configuration is as below, later we can add more db related information if needed:
{
...
"DATABASE": {
"redis-db-01" : {
"port" : "6380",
"database": ["APPL_DB", "STATE_DB"]
},
"redis-db-02" : {
"port" : "6381",
"database":["ASIC_DB"]
},
}
...
}
The detail description is at design doc at Azure/SONiC#271
The main idea is : when database.sh started, we check the configuration and generate corresponding scripts.
rc.local service handle old_config copy when loading new images, there is no dependency between rc.local and database service today, for safety and make sure the copy operation are done before database try to read it, we make database service run after rc.local
Then database docker started, we check the configuration and generate corresponding scripts/.conf in database docker as well.
based on those conf, we create databases instances as required.
at last, we ping_pong check database are up and continue
Signed-off-by: Dong Zhang d.zhang@alibaba-inc.com
2019-08-28 13:15:10 -05:00
|
|
|
else
|
2023-11-17 11:10:03 -06:00
|
|
|
HOST_IP=$host_ip REDIS_PORT=$redis_port DATABASE_TYPE=$DATABASE_TYPE j2 /usr/share/sonic/templates/database_config.json.j2 > $REDIS_DIR/sonic-db/database_config.json
|
create multiple Redis DB instances based on CONFIG at /etc/sonic/database_config.json (#2182)
this is the first step to moving different databases tables into different database instances
in this PR, only handle multiple database instances creation based on user configuration at /etc/sonic/database_config.json
we keep current method to create single database instance if no extra/new DATABASE configuration exist in database_config.json file.
if user try to configure more db instances at database_config.json , we create those new db instances along with the original db instance existing today.
The configuration is as below, later we can add more db related information if needed:
{
...
"DATABASE": {
"redis-db-01" : {
"port" : "6380",
"database": ["APPL_DB", "STATE_DB"]
},
"redis-db-02" : {
"port" : "6381",
"database":["ASIC_DB"]
},
}
...
}
The detail description is at design doc at Azure/SONiC#271
The main idea is : when database.sh started, we check the configuration and generate corresponding scripts.
rc.local service handle old_config copy when loading new images, there is no dependency between rc.local and database service today, for safety and make sure the copy operation are done before database try to read it, we make database service run after rc.local
Then database docker started, we check the configuration and generate corresponding scripts/.conf in database docker as well.
based on those conf, we create databases instances as required.
at last, we ping_pong check database are up and continue
Signed-off-by: Dong Zhang d.zhang@alibaba-inc.com
2019-08-28 13:15:10 -05:00
|
|
|
fi
|
|
|
|
|
2020-10-14 17:15:24 -05:00
|
|
|
# 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=""
|
2020-10-21 03:40:04 -05:00
|
|
|
chassisdb_config="/usr/share/sonic/platform/chassisdb.conf"
|
2020-10-14 17:15:24 -05:00
|
|
|
[ -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..."
|
2024-03-22 16:20:12 -05:00
|
|
|
VAR_LIB_REDIS_CHASSIS_DIR="/var/lib/redis_chassis"
|
|
|
|
mkdir -p $VAR_LIB_REDIS_CHASSIS_DIR
|
2020-10-14 17:15:24 -05:00
|
|
|
update_chassisdb_config -j $db_cfg_file_tmp -k -p $chassis_db_port
|
|
|
|
# generate all redis server supervisord configuration file
|
2024-01-19 23:52:30 -06:00
|
|
|
sonic-cfggen -j $db_cfg_file_tmp \
|
|
|
|
-t /usr/share/sonic/templates/supervisord.conf.j2,/etc/supervisor/conf.d/supervisord.conf \
|
|
|
|
-t /usr/share/sonic/templates/critical_processes.j2,/etc/supervisor/critical_processes
|
2020-10-14 17:15:24 -05:00
|
|
|
rm $db_cfg_file_tmp
|
2024-03-22 16:20:12 -05:00
|
|
|
chown -R redis:redis $VAR_LIB_REDIS_CHASSIS_DIR
|
|
|
|
chown -R redis:redis $REDIS_DIR
|
2020-11-22 23:18:44 -06:00
|
|
|
exec /usr/local/bin/supervisord
|
2020-10-14 17:15:24 -05:00
|
|
|
exit 0
|
|
|
|
fi
|
2020-05-08 23:24:05 -05:00
|
|
|
|
2023-11-21 11:41:20 -06:00
|
|
|
# copy/generate the database_global.json file if this is global database service in multi asic/smart switch platform.
|
|
|
|
if [[ $NAMESPACE_ID == "" && $DATABASE_TYPE == "" && ( $NAMESPACE_COUNT -gt 1 || $NUM_DPU -gt 1) ]]
|
2020-05-08 23:24:05 -05:00
|
|
|
then
|
|
|
|
if [ -f /etc/sonic/database_global.json ]; then
|
|
|
|
cp /etc/sonic/database_global.json $REDIS_DIR/sonic-db/database_global.json
|
|
|
|
else
|
|
|
|
j2 /usr/share/sonic/templates/database_global.json.j2 > $REDIS_DIR/sonic-db/database_global.json
|
|
|
|
fi
|
|
|
|
fi
|
2020-10-14 17:15:24 -05:00
|
|
|
# delete chassisdb config to generate supervisord config
|
|
|
|
update_chassisdb_config -j $db_cfg_file_tmp -d
|
2024-01-19 23:52:30 -06:00
|
|
|
sonic-cfggen -j $db_cfg_file_tmp \
|
|
|
|
-t /usr/share/sonic/templates/supervisord.conf.j2,/etc/supervisor/conf.d/supervisord.conf \
|
|
|
|
-t /usr/share/sonic/templates/critical_processes.j2,/etc/supervisor/critical_processes
|
2020-05-08 23:24:05 -05:00
|
|
|
|
2020-10-14 17:15:24 -05:00
|
|
|
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
|
create multiple Redis DB instances based on CONFIG at /etc/sonic/database_config.json (#2182)
this is the first step to moving different databases tables into different database instances
in this PR, only handle multiple database instances creation based on user configuration at /etc/sonic/database_config.json
we keep current method to create single database instance if no extra/new DATABASE configuration exist in database_config.json file.
if user try to configure more db instances at database_config.json , we create those new db instances along with the original db instance existing today.
The configuration is as below, later we can add more db related information if needed:
{
...
"DATABASE": {
"redis-db-01" : {
"port" : "6380",
"database": ["APPL_DB", "STATE_DB"]
},
"redis-db-02" : {
"port" : "6381",
"database":["ASIC_DB"]
},
}
...
}
The detail description is at design doc at Azure/SONiC#271
The main idea is : when database.sh started, we check the configuration and generate corresponding scripts.
rc.local service handle old_config copy when loading new images, there is no dependency between rc.local and database service today, for safety and make sure the copy operation are done before database try to read it, we make database service run after rc.local
Then database docker started, we check the configuration and generate corresponding scripts/.conf in database docker as well.
based on those conf, we create databases instances as required.
at last, we ping_pong check database are up and continue
Signed-off-by: Dong Zhang d.zhang@alibaba-inc.com
2019-08-28 13:15:10 -05:00
|
|
|
|
2020-12-10 13:06:19 -06:00
|
|
|
# copy dump.rdb file to each instance for restoration
|
|
|
|
DUMPFILE=/var/lib/redis/dump.rdb
|
2022-08-02 21:18:00 -05:00
|
|
|
redis_inst_list=`/usr/bin/python3 -c "from swsscommon import swsscommon; print(' '.join(swsscommon.SonicDBConfig.getInstanceList().keys()))"`
|
2020-12-10 13:06:19 -06:00
|
|
|
for inst in $redis_inst_list
|
|
|
|
do
|
|
|
|
mkdir -p /var/lib/$inst
|
|
|
|
if [[ -f $DUMPFILE ]]; then
|
|
|
|
# copy warmboot rdb file into each new instance location
|
|
|
|
if [[ "$DUMPFILE" != "/var/lib/$inst/dump.rdb" ]]; then
|
|
|
|
cp $DUMPFILE /var/lib/$inst/dump.rdb
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo -n > /var/lib/$inst/dump.rdb
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2023-06-25 18:36:09 -05:00
|
|
|
TZ=$(cat /etc/timezone)
|
|
|
|
rm -rf /etc/localtime
|
|
|
|
ln -sf /usr/share/zoneinfo/$TZ /etc/localtime
|
|
|
|
|
2023-09-02 01:03:15 -05:00
|
|
|
chown -R redis:redis $REDIS_DIR
|
|
|
|
|
2020-11-22 23:18:44 -06:00
|
|
|
exec /usr/local/bin/supervisord
|