# tomcat service to start only after the Redis replication is completed

**URL:** <https://forum.ansible.com/t/tomcat-service-to-start-only-after-the-redis-replication-is-completed/16092>\
**Category:** Ansible Project\
**Created:** [September 1, 2014, 11:00am UTC](https://forum.ansible.com/t/tomcat-service-to-start-only-after-the-redis-replication-is-completed/16092 "2014-09-01T11:00:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolas\_G](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Nicolas\_G](https://forum.ansible.com/u/Nicolas_G)\
**Post date:** [September 1, 2014, 11:00am UTC](https://forum.ansible.com/t/tomcat-service-to-start-only-after-the-redis-replication-is-completed/16092/1 "2014-09-01T11:00:14Z")

</div>

Hi,

We use a single redis master server and many slave nodes that are running tomcat along with the redis slave service.

One of the problems I have is that I need my tomcat application to start when the replication is completed, on my playbook I first install and start redis slave service before tomcat but it seems tomcat service starts before the replication is completed which is not acceptable. How can I have Ansible to check when the redis replication was completed so it can THEN start tomcat ?

I could add a pause command but the replication time is something that will change in the future along with our database, I’m able to check for the replication status using the redis cli command or inspecting the redis log file :

# CLI

```auto
/usr/bin/redis-cli -a <password> -p <slave_port> info replication

```

# Log

“”"

```auto
[11347] 01 Sep 09:05:54.259 # Server started, Redis version 2.8.13
[11347] 01 Sep 09:06:17.406 * DB loaded from append only file: 23.148 seconds
[11347] 01 Sep 09:06:17.406 * The server is now ready to accept connections on port 6380
[11347] 01 Sep 09:06:18.259 * Connecting to MASTER master-redis[.example.com:6379](http://asset-feed.cogmatch.net:6379/)
[11347] 01 Sep 09:06:18.261 * MASTER <-> SLAVE sync started
[11347] 01 Sep 09:06:18.263 * Non blocking connect for SYNC fired the event.
[11347] 01 Sep 09:06:18.264 * Master replied to PING, replication can continue...
[11347] 01 Sep 09:06:18.264 * Partial resynchronization not possible (no cached master)
[11347] 01 Sep 09:06:18.265 * Full resync from master: 16d5e3d27f324kjdf2d10e5c8dadae90186ab85bd51:72507275921
[11347] 01 Sep 09:06:40.402 * MASTER <-> SLAVE sync: receiving 1672419047 bytes from master
[11347] 01 Sep 09:07:32.165 * MASTER <-> SLAVE sync: Flushing old data
[11347] 01 Sep 09:07:40.012 * MASTER <-> SLAVE sync: Loading DB in memory
[11347] 01 Sep 09:07:59.408 * MASTER <-> SLAVE sync: Finished with success

```

“”"

Can you please advise ?

Regards,  
Nicolas.

---

<div class="post-metadata">

**Author:** ![Frank\_Steffen](https://avatars.discourse-cdn.com/v4/letter/f/48db29/32.png) [@Frank\_Steffen](https://forum.ansible.com/u/Frank_Steffen)\
**Post date:** [September 1, 2014, 12:23pm UTC](https://forum.ansible.com/t/tomcat-service-to-start-only-after-the-redis-replication-is-completed/16092/2 "2014-09-01T12:23:47Z")

</div>

Hi Nicolas,

have you tried “wait\_for”?

Something like:

`  
wait\_for: path=/var/log/redis.log search\_regex=“Finished with success” state=present

`

Regards,

Frank

---

<div class="post-metadata">

**Author:** ![Nicolas\_G](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Nicolas\_G](https://forum.ansible.com/u/Nicolas_G)\
**Post date:** [September 2, 2014, 10:46am UTC](https://forum.ansible.com/t/tomcat-service-to-start-only-after-the-redis-replication-is-completed/16092/3 "2014-09-02T10:46:34Z")

</div>

Hi Frank, thanks for the reply.

I was not aware of the search\_regex thanks you, should be useful in other cases but I don’t thin in my case. The reason is if I need to restart the services (redis/tomcat), tomcat will start immediately as it will find the “Finished with success” from previous boot in the logs.

---

<div class="post-metadata">

**Author:** ![Frank\_Steffen](https://avatars.discourse-cdn.com/v4/letter/f/48db29/32.png) [@Frank\_Steffen](https://forum.ansible.com/u/Frank_Steffen)\
**Post date:** [September 3, 2014, 10:22am UTC](https://forum.ansible.com/t/tomcat-service-to-start-only-after-the-redis-replication-is-completed/16092/4 "2014-09-03T10:22:42Z")

</div>

You may delete or rotate the log file before.

---

<div class="post-metadata">

**Author:** ![Nicolas\_G](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Nicolas\_G](https://forum.ansible.com/u/Nicolas_G)\
**Post date:** [September 3, 2014, 12:13pm UTC](https://forum.ansible.com/t/tomcat-service-to-start-only-after-the-redis-replication-is-completed/16092/5 "2014-09-03T12:13:48Z")

</div>

this is not ideal, I found a better solution for my case :

“”"

- name: check if Redis replication has finished before proceeding  
shell: /usr/bin/redis-cli -a {{ REDIS\_PASSWORD }} -p {{ REDIS\_SLAVE\_PORT }} info replication | grep master\_link\_status | cut -d":" -f2  
register: result  
until: result.stdout.find(“up”) != -1  
retries: 5  
delay: 10  
“”"

Thanks for the help !
