Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[warmboot] Load database from redis-cli save #2287

Merged
merged 5 commits into from
Nov 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dockers/docker-database/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
10 changes: 1 addition & 9 deletions dockers/docker-database/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Copy link
Collaborator

@lguohan lguohan Nov 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configdb-load is also used in virtual switch, can you change that too? #WontFix

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like keep behavior unchange on vs side, and visit the warm-reboot feature later.
Also applied to P4 side.


In reply to: 235583086 [](ancestors = 235583086)

command=/usr/bin/configdb-load.sh
priority=3
autostart=true
autorestart=false
startsecs=0
stdout_logfile=syslog
stderr_logfile=syslog
2 changes: 1 addition & 1 deletion files/build_templates/database.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
66 changes: 39 additions & 27 deletions files/build_templates/docker_image_ctl.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`

Expand All @@ -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 $?
Expand All @@ -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 %}
Expand All @@ -133,6 +143,8 @@ start() {
exit 4
}

preStartAction
docker start {{docker_container_name}}
postStartAction
}

Expand Down
1 change: 0 additions & 1 deletion rules/docker-database.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion src/sonic-utilities