[warmboot] Load database from redis-cli save
(#2287)
* [warmboot] Load database from `redis-cli save` Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com> * Add trivial statement to make bash function valid Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com> * Update submodule sonic-utilities: Use 'redis-cli save' to dump database to file Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com> * Move configdb-load.sh outside docker, and only run in cold Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com> * Fix for more strict warm check Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com>
This commit is contained in:
parent
6e71cc7887
commit
c2ae736f2e
@ -36,6 +36,5 @@ RUN sed -ri 's/^(save .*$)/# \1/g; \
|
||||
' /etc/redis/redis.conf
|
||||
|
||||
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
|
||||
COPY ["files/configdb-load.sh", "/usr/bin/"]
|
||||
|
||||
ENTRYPOINT ["/usr/bin/supervisord"]
|
||||
|
@ -12,18 +12,10 @@ stdout_logfile=syslog
|
||||
stderr_logfile=syslog
|
||||
|
||||
[program:redis-server]
|
||||
command=/usr/bin/redis-server /etc/redis/redis.conf
|
||||
command=/bin/bash -c "{ [[ -s /var/lib/redis/dump.rdb ]] || rm -f /var/lib/redis/dump.rdb; } && exec /usr/bin/redis-server /etc/redis/redis.conf"
|
||||
priority=2
|
||||
autostart=true
|
||||
autorestart=false
|
||||
stdout_logfile=syslog
|
||||
stderr_logfile=syslog
|
||||
|
||||
[program:configdb-load.sh]
|
||||
command=/usr/bin/configdb-load.sh
|
||||
priority=3
|
||||
autostart=true
|
||||
autorestart=false
|
||||
startsecs=0
|
||||
stdout_logfile=syslog
|
||||
stderr_logfile=syslog
|
||||
|
@ -4,7 +4,7 @@ Requires=docker.service
|
||||
After=docker.service
|
||||
|
||||
[Service]
|
||||
User={{ sonicadmin_user }}
|
||||
User=root
|
||||
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start
|
||||
ExecStart=/usr/bin/{{docker_container_name}}.sh attach
|
||||
ExecStop=/usr/bin/{{docker_container_name}}.sh stop
|
||||
|
@ -16,40 +16,46 @@ function getBootType()
|
||||
TYPE='warm'
|
||||
;;
|
||||
*)
|
||||
TYPE="normal"
|
||||
TYPE='cold'
|
||||
esac
|
||||
echo $TYPE
|
||||
}
|
||||
|
||||
function preStartAction()
|
||||
{
|
||||
{%- if docker_container_name == "database" %}
|
||||
WARM_DIR=/host/warmboot
|
||||
if [[ "$BOOT_TYPE" == "warm" && -f $WARM_DIR/dump.rdb ]]; then
|
||||
# Load redis content from /host/warm-reboot/dump.rdb
|
||||
docker cp $WARM_DIR/dump.rdb database:/var/lib/redis/dump.rdb
|
||||
else
|
||||
# Create an emtpy file and overwrite any RDB if already there
|
||||
echo -n > /tmp/dump.rdb
|
||||
docker cp /tmp/dump.rdb database:/var/lib/redis/
|
||||
fi
|
||||
{%- else %}
|
||||
: # nothing
|
||||
{%- endif %}
|
||||
}
|
||||
|
||||
function postStartAction()
|
||||
{
|
||||
{%- if docker_container_name == "database" %}
|
||||
# Wait until redis starts
|
||||
REDIS_SOCK="/var/run/redis/redis.sock"
|
||||
until [[ $(/usr/bin/docker exec database redis-cli -s $REDIS_SOCK ping | grep -c PONG) -gt 0 ]]; do
|
||||
sleep 1;
|
||||
sleep 1;
|
||||
done
|
||||
WARM_DIR=/host/warmboot
|
||||
SUDO="sudo -n"
|
||||
BOOT_TYPE=`getBootType`
|
||||
if [[ "$BOOT_TYPE" == "warm" && -d $WARM_DIR ]]; then
|
||||
function redisLoadAndDelete()
|
||||
{
|
||||
DB="$1"
|
||||
FILENAME="$2"
|
||||
test -e $FILENAME || { echo "No file $FILENAME" >&2; exit 10; }
|
||||
$SUDO redis-load -s $REDIS_SOCK -d $DB -e EMPTY $FILENAME || { echo "Failed to redis-load $FILENAME" >&2; exit 11; }
|
||||
$SUDO rm $FILENAME || exit 12
|
||||
}
|
||||
# Load applDB from /host/warm-reboot/appl_db.json
|
||||
redisLoadAndDelete 0 $WARM_DIR/appl_db.json
|
||||
# Load configDB from /host/warm-reboot/config_db.json
|
||||
redisLoadAndDelete 4 $WARM_DIR/config_db.json
|
||||
# Load stateDB from /host/warm-reboot/state_db.json
|
||||
redisLoadAndDelete 6 $WARM_DIR/state_db.json
|
||||
# Load asicDB from /host/warm-reboot/asic_db.json
|
||||
redisLoadAndDelete 1 $WARM_DIR/asic_db.json
|
||||
# Load loglevelDB from /host/warm-reboot/loglevel_db.json
|
||||
redisLoadAndDelete 3 $WARM_DIR/loglevel_db.json
|
||||
|
||||
if [[ "$BOOT_TYPE" == "warm" && -f $WARM_DIR/dump.rdb ]]; then
|
||||
rm -f $WARM_DIR/dump.rdb
|
||||
else
|
||||
# If there is a config db dump file, load it
|
||||
if [ -r /etc/sonic/config_db.json ]; then
|
||||
sonic-cfggen -j /etc/sonic/config_db.json --write-to-db
|
||||
fi
|
||||
|
||||
redis-cli -n 4 SET "CONFIG_DB_INITIALIZED" "1"
|
||||
fi
|
||||
{%- elif docker_container_name == "swss" %}
|
||||
docker exec swss rm -f /ready # remove cruft
|
||||
@ -79,6 +85,9 @@ function postStartAction()
|
||||
}
|
||||
|
||||
start() {
|
||||
# Obtain boot type from kernel arguments
|
||||
BOOT_TYPE=`getBootType`
|
||||
|
||||
# Obtain our platform as we will mount directories with these names in each docker
|
||||
PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`
|
||||
|
||||
@ -95,6 +104,7 @@ start() {
|
||||
DOCKERMOUNT=`getMountPoint "$DOCKERCHECK"`
|
||||
if [ "$DOCKERMOUNT" == "$HWSKU" ]; then
|
||||
echo "Starting existing {{docker_container_name}} container with HWSKU $HWSKU"
|
||||
preStartAction
|
||||
docker start {{docker_container_name}}
|
||||
postStartAction
|
||||
exit $?
|
||||
@ -106,11 +116,11 @@ start() {
|
||||
fi
|
||||
|
||||
{%- if docker_container_name == "database" %}
|
||||
echo "Starting new {{docker_container_name}} container"
|
||||
echo "Creating new {{docker_container_name}} container"
|
||||
{%- else %}
|
||||
echo "Starting new {{docker_container_name}} container with HWSKU $HWSKU"
|
||||
echo "Creating new {{docker_container_name}} container with HWSKU $HWSKU"
|
||||
{%- endif %}
|
||||
docker run -d {{docker_image_run_opt}} \
|
||||
docker create {{docker_image_run_opt}} \
|
||||
{%- if '--log-driver=json-file' in docker_image_run_opt or '--log-driver' not in docker_image_run_opt %}
|
||||
--log-opt max-size=2M --log-opt max-file=5 \
|
||||
{%- endif %}
|
||||
@ -133,6 +143,8 @@ start() {
|
||||
exit 4
|
||||
}
|
||||
|
||||
preStartAction
|
||||
docker start {{docker_container_name}}
|
||||
postStartAction
|
||||
}
|
||||
|
||||
|
@ -12,4 +12,3 @@ $(DOCKER_DATABASE)_RUN_OPT += --net=host --privileged -t
|
||||
$(DOCKER_DATABASE)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro
|
||||
|
||||
$(DOCKER_DATABASE)_BASE_IMAGE_FILES += redis-cli:/usr/bin/redis-cli
|
||||
$(DOCKER_DATABASE)_FILES += $(CONFIGDB_LOAD_SCRIPT)
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit a099681c56339ebcffd4aea9d2e232db07ed2cc0
|
||||
Subproject commit 46e03b76d7555090366524f9846d3747673a1a08
|
Loading…
Reference in New Issue
Block a user