From f6c7a64ff56ac49b8728e96456377be210df5780 Mon Sep 17 00:00:00 2001 From: Qi Luo Date: Thu, 1 Nov 2018 00:58:02 +0000 Subject: [PATCH] Fix sudo, and exit immediately if any failure Signed-off-by: Qi Luo --- files/build_templates/docker_image_ctl.j2 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/files/build_templates/docker_image_ctl.j2 b/files/build_templates/docker_image_ctl.j2 index 1255447b776b..59d367cb3ea5 100644 --- a/files/build_templates/docker_image_ctl.j2 +++ b/files/build_templates/docker_image_ctl.j2 @@ -28,12 +28,16 @@ function postStartAction() until [[ $(/usr/bin/docker exec database redis-cli ping | grep -c PONG) -gt 0 ]]; do sleep 1; done - if [[ "$REBOOT_TYPE" == "warm" && -d /host/warmboot ]]; then - WARM_DIR=/host/warmboot + WARM_DIR=/host/warmboot + SUDO=sudo -n + if [[ "$REBOOT_TYPE" == "warm" && -d $WARM_DIR ]]; then function redisLoadAndDelete() { - FILENAME="$1" - test -e $FILENAME && redis-load -s /var/run/redis/redis.sock -e EMPTY $FILENAME && rm $FILENAME + DB="$1" + FILENAME="$2" + test -e $FILENAME || { echo "No file $FILENAME" >&2; exit 10; } + $SUDO redis-load -s /var/run/redis/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 $WARM_DIR/appl_db.json