# Systemd restarts logstash when using jdbc input

**URL:** <https://discuss.elastic.co/t/systemd-restarts-logstash-when-using-jdbc-input/109952>\
**Category:** Logstash\
**Created:** [December 1, 2017, 3:07pm UTC](https://discuss.elastic.co/t/systemd-restarts-logstash-when-using-jdbc-input/109952 "2017-12-01T15:07:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![arisbanach](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@arisbanach](https://discuss.elastic.co/u/arisbanach)\
**Post date:** [December 1, 2017, 3:07pm UTC](https://discuss.elastic.co/t/systemd-restarts-logstash-when-using-jdbc-input/109952/1 "2017-12-01T15:07:09Z")

</div>

Not sure if I've configured something wrong since this is my first time working with JDBC. I am trying to import a large database into Elasticsearch using Logstash and the logstash-input-jdbc plugin. Here is my pipeline:

```
input {
  jdbc {
    jdbc_driver_library => "/home/ubuntu/postgresql-42.1.4.jar"
    jdbc_driver_class => "org.postgresql.Driver"
    jdbc_connection_string => "jdbc:postgresql://myhost.com:5432/dbname?user=myuser&password=mypassword"
    jdbc_user => "myuser"
    jdbc_password => "mypassword"
# schedule => "* * * * *"                                                                                                 
    statement => "SELECT * from tablename LIMIT 1"
    jdbc_paging_enabled => "true"
    #jdbc_fetch_size => "1000"                                                                                               
  }
}
output {
  stdout { codec => json_lines }
  #elasticsearch {                                                                                                           
  # hosts => localhost                                                                                                      
  # index => "db-import"                                                                                                   
  #}                                                                                                                         
}

```

I commented out a couple lines because I wasn't sure if they were causing issues or not. Right now when I run this and do `journalctl -f` I see:

```
Dec 01 15:01:59 elastisearch systemd[1]: logstash.service: Service hold-off time over, scheduling restart.
Dec 01 15:01:59 elastisearch systemd[1]: Stopped logstash.
Dec 01 15:01:59 elastisearch systemd[1]: Started logstash.
Dec 01 15:02:35 elastisearch logstash[11884]: Sending Logstash's logs to /var/log/logstash which is now configured via log4j2.properties

```

and then the next log line is one row from the database. Then, it repeats: logstash has the `Service hold-off time over, scheduling restart` error, restarts, and imports the same row.

Why is it stuck in a loop? Shouldn't it just import the one row and then stop the job? And why is Logstash itself restarting? Does that imply there is a config error somewhere?

Thank you

---

<div class="post-metadata">

**Author:** ![arisbanach](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@arisbanach](https://discuss.elastic.co/u/arisbanach)\
**Post date:** [December 1, 2017, 11:28pm UTC](https://discuss.elastic.co/t/systemd-restarts-logstash-when-using-jdbc-input/109952/2 "2017-12-01T23:28:44Z")

</div>

I also noticed that when I put a LIMIT on the statement, it does return results quickly, but if I'm running this with systemd it will return the results, stop Logstash, start it again, then process the pipeline again, and repeat until I stop the service.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [December 2, 2017, 6:36pm UTC](https://discuss.elastic.co/t/systemd-restarts-logstash-when-using-jdbc-input/109952/3 "2017-12-02T18:36:20Z")

</div>

Unless you use the schedule option Logstash will shut down after the jdbc input has processed all rows returned by the query. systemd has obviously been configured to keep Logstash alive by restarting it when it shuts down.

---

<div class="post-metadata">

**Author:** ![arisbanach](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@arisbanach](https://discuss.elastic.co/u/arisbanach)\
**Post date:** [December 2, 2017, 7:01pm UTC](https://discuss.elastic.co/t/systemd-restarts-logstash-when-using-jdbc-input/109952/4 "2017-12-02T19:01:23Z")

</div>

Ah, that makes sense then! Is there a reason Logstash shuts down after the pipeline finishes? I'm relatively new to Logstash but expected that if I start it with systemd that it would only stop if there is either an error or I tell systemd to stop it. Wouldn't it make more sense to just have the pipeline finish and then Logstash to stay running and just output "finished pipeline" to the console or something?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [December 2, 2017, 8:45pm UTC](https://discuss.elastic.co/t/systemd-restarts-logstash-when-using-jdbc-input/109952/5 "2017-12-02T20:45:04Z")

</div>

> Is there a reason Logstash shuts down after the pipeline finishes?

Why keep running if you only have a jdbc input that won't run more than once?

> I'm relatively new to Logstash but expected that if I start it with systemd that it would only stop if there is either an error or I tell systemd to stop it. Wouldn't it make more sense to just have the pipeline finish and then Logstash to stay running and just output "finished pipeline" to the console or something?

That would make some sense when run as a service as in your case but would be undesirable if run interactively. In fact, a common complaint about the file input is that it _doesn't_ shut Logstash down once it has reached the end of the file.

Running Logstash with just non-scheduled jdbc inputs is a rather unusual use case, I'd say. I'd expect you to be able to adjust the unit file to not respawn Logstash when it shuts down.

---

<div class="post-metadata">

**Author:** ![arisbanach](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@arisbanach](https://discuss.elastic.co/u/arisbanach)\
**Post date:** [December 2, 2017, 9:34pm UTC](https://discuss.elastic.co/t/systemd-restarts-logstash-when-using-jdbc-input/109952/6 "2017-12-02T21:34:36Z")

</div>

Okay, thank you!

---

<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:** [December 30, 2017, 9:34pm UTC](https://discuss.elastic.co/t/systemd-restarts-logstash-when-using-jdbc-input/109952/7 "2017-12-30T21:34:48Z")

</div>

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