diff --git a/ansible/roles/sonicv2/templates/etc/systemd/system/swss.j2 b/ansible/roles/sonicv2/templates/etc/systemd/system/swss.j2 index d5385edae6..c733403f46 100644 --- a/ansible/roles/sonicv2/templates/etc/systemd/system/swss.j2 +++ b/ansible/roles/sonicv2/templates/etc/systemd/system/swss.j2 @@ -5,6 +5,8 @@ After=database.service [Service] User={{ sonicadmin_user }} +# Wait for redis server start before database clean +ExecStartPre=/bin/bash -c "while true; do if [ \"$(/usr/bin/docker exec database redis-cli ping)\" == \"PONG\" ]; then break; fi; sleep 1; done" ExecStartPre=/usr/bin/docker exec database redis-cli -n 0 FLUSHDB ExecStartPre=/usr/bin/docker exec database redis-cli -n 1 FLUSHDB ExecStartPre=/usr/bin/docker exec database redis-cli -n 2 FLUSHDB diff --git a/ansible/roles/sonicv2/templates/etc/systemd/system/syncd.j2 b/ansible/roles/sonicv2/templates/etc/systemd/system/syncd.j2 index 4ee54915b8..27f8d8d876 100644 --- a/ansible/roles/sonicv2/templates/etc/systemd/system/syncd.j2 +++ b/ansible/roles/sonicv2/templates/etc/systemd/system/syncd.j2 @@ -1,7 +1,7 @@ [Unit] Description=syncd container -Requires=database.service -After=database.service +Requires=database.service swss.service +After=database.service swss.service [Service] User=root