# Ensure Client Flushed Before Exit

**URL:** <https://discuss.elastic.co/t/ensure-client-flushed-before-exit/59137>\
**Category:** Beats\
**Created:** [August 29, 2016, 1:27am UTC](https://discuss.elastic.co/t/ensure-client-flushed-before-exit/59137 "2016-08-29T01:27:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![blachniet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/blachniet/32/11650_2.png) [@blachniet](https://discuss.elastic.co/u/blachniet)\
**Post date:** [August 29, 2016, 1:27am UTC](https://discuss.elastic.co/t/ensure-client-flushed-before-exit/59137/1 "2016-08-29T01:27:39Z")

</div>

I'm trying to create a custom beat that accepts input log input via stdin. For example you might feed a single completed log file into this beat like this:

```
cat myapp.log | mybeat

```

The problem that I'm having is that my beat exits before the `publisher.Client` has a chance to flush and send log events to the destination (Elasticsearch, for example). If I put a `time.Sleep(5 * time.Second)` after my custom beat completes, but before `main` exits, my events make it to Elasticsearch. Is there a cleaner way for me to ensure that the `publisher.Client` has flushed before exiting the application?

---

<div class="post-metadata">

**Author:** ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)\
**Post date:** [August 29, 2016, 7:33am UTC](https://discuss.elastic.co/t/ensure-client-flushed-before-exit/59137/2 "2016-08-29T07:33:53Z")

</div>

Great to hear that you are creating a beat. If you need a beat that accepts stdin, have a look at Filebeat. It accepts `input_type: stdin`.

For your shutdown question: Best is to have a look at the filebeat code as there filebeat is waiting until the publisher is closed. In case you need further help, please share the link to your code. That will make it much easier to comment.

---

<div class="post-metadata">

**Author:** ![blachniet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/blachniet/32/11650_2.png) [@blachniet](https://discuss.elastic.co/u/blachniet)\
**Post date:** [August 29, 2016, 10:56am UTC](https://discuss.elastic.co/t/ensure-client-flushed-before-exit/59137/3 "2016-08-29T10:56:19Z")

</div>

I did not realize Filebeat had the option to accept stdin. I will probably use that instead of creating my own. Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 19, 2016, 1:27am UTC](https://discuss.elastic.co/t/ensure-client-flushed-before-exit/59137/4 "2016-09-19T01:27:46Z")

</div>

This topic was automatically closed after 21 days. New replies are no longer allowed.
