# Using message pattern match to shut down Logstash

**URL:** <https://discuss.elastic.co/t/using-message-pattern-match-to-shut-down-logstash/77367>\
**Category:** Logstash\
**Created:** [March 3, 2017, 10:04pm UTC](https://discuss.elastic.co/t/using-message-pattern-match-to-shut-down-logstash/77367 "2017-03-03T22:04:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![john6](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@john6](https://discuss.elastic.co/u/john6)\
**Post date:** [March 3, 2017, 10:04pm UTC](https://discuss.elastic.co/t/using-message-pattern-match-to-shut-down-logstash/77367/1 "2017-03-03T22:04:40Z")

</div>

What would be the best way of gracefully shutting down Logstash based on a message pattern match? The pattern match would indicate the file input stream is dead.

if ([message] =~ "patternA") {  
ruby{  
code =\> "some shutdown code"  
}  
}

Our Desired Scenario:  
An automated job runs performance tests that use Logstash to ship results to Elasticsearch. Each job requires a test run specific Logstash configuration and multiple jobs can run simultaneously on a server. Each Logstash instance lives only within the job and must live long enough to complete shipping of the results file.

The automated job implements the following steps

1. 

```
  An instance of Logstash is configured for the test and started to monitor the soon to exist performance test result file.

```

2. 

```
  The test is started and results are being generated. A test run can take a couple of minutes or up to a couple of hours

```

3. 

```
  Logstash starts reading the results stream and shipping to Elasticsearch

```

4. 

```
  The test completes

```

5. 

```
  The job appends a message, containing patternA, to the results file.

```

6. 

```
  Logstash continues reading and shipping

```

7. 

```
  Logstash reads the message containing patternA and starts graceful shutdown, allowing buffered data to ship

```

8. 

```
  Logstash completes shipping and then terminates

```

9. 

```
  Job verifies Logstash termination and completes
```

---

<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:** [March 31, 2017, 10:04pm UTC](https://discuss.elastic.co/t/using-message-pattern-match-to-shut-down-logstash/77367/2 "2017-03-31T22:04:41Z")

</div>

Closed on March 31, 2017, 10:04pm UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
