From a2ab261dbadf1884e081c99b9f3f815a2f3b0844 Mon Sep 17 00:00:00 2001 From: Vitaliy Senchyshyn Date: Sat, 4 Feb 2017 00:32:07 +0200 Subject: [PATCH] Fixes problems with database - swss - syncd synchronization. (#110) * [syncd.service] Make syncd starting after swss in order to eliminate race condition with database flush/set * [swss.service] Make swss waiting for redis server start before cleaning the database * Fixed review comments for changes in swss service file --- ansible/roles/sonicv2/templates/etc/systemd/system/swss.j2 | 2 ++ ansible/roles/sonicv2/templates/etc/systemd/system/syncd.j2 | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) 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