@@ -125,6 +125,34 @@ function setPlatformLagIdBoundaries()
125
125
docker exec -i ${DOCKERNAME} $SONIC_DB_CLI CHASSIS_APP_DB SET " SYSTEM_LAG_ID_END" " $lag_id_end "
126
126
fi
127
127
}
128
+ function waitForAllInstanceDatabaseConfigJsonFilesReady()
129
+ {
130
+ if [ ! -z " $DEV " ]; then
131
+ cnt=0
132
+ SONIC_DB_GLOBAL_JSON=" /var/run/redis/sonic-db/database_global.json"
133
+ if [ -f " $SONIC_DB_GLOBAL_JSON " ]; then
134
+ # Create a separate python script to get a list of location of all instance database_config.json file
135
+ redis_database_cfg_list=` /usr/bin/python -c " import sys; import os; import json; f=open(sys.argv[1]); \
136
+ global_db_dir = os.path.dirname(sys.argv[1]); data=json.load(f); \
137
+ print(\" \" .join([os.path.normpath(global_db_dir+'/'+elem['include']) \
138
+ for elem in data['INCLUDES'] if 'namespace' in elem])); f.close()" $SONIC_DB_GLOBAL_JSON `
139
+ for file in $redis_database_cfg_list
140
+ do
141
+ while [ ! -f $file ]
142
+ do
143
+ sleep 1
144
+ cnt=$(( $cnt + 1 ))
145
+ if [ $cnt -ge 60 ]; then
146
+ echo " Error: $file not found"
147
+ break
148
+ fi
149
+ done
150
+ done
151
+ fi
152
+ fi
153
+ }
154
+ # delay a second to allow the file to be fully accessible
155
+ sleep 1
128
156
{%- endif %}
129
157
130
158
function postStartAction()
@@ -161,6 +189,11 @@ function postStartAction()
161
189
else
162
190
# If there is a config_db.json dump file, load it.
163
191
if [ -r /etc/sonic/config_db$DEV .json ]; then
192
+
193
+ # For multi-asic, all /var/run/redis$DEV/sonic-db/database_config.json need to ready
194
+ # for loading config with --write-to-db
195
+ waitForAllInstanceDatabaseConfigJsonFilesReady
196
+
164
197
if [ -r /etc/sonic/init_cfg.json ]; then
165
198
$SONIC_CFGGEN -j /etc/sonic/init_cfg.json -j /etc/sonic/config_db$DEV .json --write-to-db
166
199
else
0 commit comments