3

I have a Logstash container that keeps two data sources sync. When it runs, it queries non-synced entries in one database and posts them into the other. I would like to run this container say every 10 seconds.

What I have been doing is to specify --restart=always so that when the container exits, it restarts itself, around which takes around 5 seconds, which is a bit too often for this use case.

Does Docker support what I want to achieve (waiting X seconds between restarts, or any kind of scheduling) or should I remove the restart policy and schedule it with cron to run every 10 seconds?

Hasan Can Saral
  • 2,950
  • 5
  • 43
  • 78

1 Answers1

3

If your container exits succesfully, it will be restarted immediately with --restart=always

An ever increasing delay (double the previous delay, starting at 100 milliseconds) is added before each restart to prevent flooding the server. This means the daemon will wait for 100 ms, then 200 ms, 400, 800, 1600, and so on until either the on-failure limit is hit, or when you docker stop or docker rm -f the container.

Here is your part I guess:

If a container is successfully restarted (the container is started and runs for at least 10 seconds), the delay is reset to its default value of 100 ms.

What you can do is:

  • Restart your container with a cron every 10 seconds
  • Configure a cron inside your container and launch logstash every 10 seconds
  • Use a shell script which, in a loop, launch logstash then sleep 10
  • Maybe logstash has something like that already built-in? (I know that for example the jdbc-input-plugin has some schedule params)
michael_bitard
  • 3,613
  • 1
  • 24
  • 35
  • I will restart with cron. But I also liked the idea of sleeping 10 seconds after logstash exists in `docker-entrypoint.sh`, then exit the container, so that 10s will be passed when it restarts immediately. I sincerely believe and support that containers should be kept as simple as possible and do the least number of things possible so I don't want cron in my Logstash container, and afaik, I cannot schedule the input/output plugins of Logstash I am using. – Hasan Can Saral Jul 12 '16 at 14:39
  • 1
    I agree with you, some of my suggestions are clearly bad practices, I just wanted to be as exhaustive as possible. – michael_bitard Jul 12 '16 at 14:40
  • 1
    You could set up a separate linked container to start Logstash, manage the schedule and report if it doesn't come back up. This way you maintain the portability and host abstraction benefits of using a container. Another option would be to set up Logstash as a server and run queries against it on a schedule, which also might add some abstraction benefits. – ldg Jul 12 '16 at 15:22