# Logstash run as a background service

**URL:** <https://discuss.elastic.co/t/logstash-run-as-a-background-service/76138>\
**Category:** Logstash\
**Created:** [February 23, 2017, 3:30am UTC](https://discuss.elastic.co/t/logstash-run-as-a-background-service/76138 "2017-02-23T03:30:44Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Suin\_You](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@Suin\_You](https://discuss.elastic.co/u/Suin_You)\
**Post date:** [February 23, 2017, 3:30am UTC](https://discuss.elastic.co/t/logstash-run-as-a-background-service/76138/1 "2017-02-23T03:30:44Z")

</div>

I install logstash-5.2.0.tar.gz and wanna start logstash as a background service using script.  
My command in the script is 'bin/logstash -f test.conf &'. But it is also not in background and 'agent' not is included in this version.  
How do I exec the logstash as the daemon?

---

<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:** [February 23, 2017, 6:50am UTC](https://discuss.elastic.co/t/logstash-run-as-a-background-service/76138/2 "2017-02-23T06:50:40Z")

</div>

What operating system and version are you using?

---

<div class="post-metadata">

**Author:** ![Suin\_You](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@Suin\_You](https://discuss.elastic.co/u/Suin_You)\
**Post date:** [February 24, 2017, 8:14am UTC](https://discuss.elastic.co/t/logstash-run-as-a-background-service/76138/3 "2017-02-24T08:14:38Z")

</div>

I uses centOs 6.4.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [February 24, 2017, 8:15am UTC](https://discuss.elastic.co/t/logstash-run-as-a-background-service/76138/4 "2017-02-24T08:15:27Z")

</div>

If you use the RPM you get the service files included.

---

<div class="post-metadata">

**Author:** ![Suin\_You](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@Suin\_You](https://discuss.elastic.co/u/Suin_You)\
**Post date:** [February 24, 2017, 8:18am UTC](https://discuss.elastic.co/t/logstash-run-as-a-background-service/76138/5 "2017-02-24T08:18:17Z")

</div>

is there other command instead of using rpm?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [February 24, 2017, 8:18am UTC](https://discuss.elastic.co/t/logstash-run-as-a-background-service/76138/6 "2017-02-24T08:18:55Z")

</div>

You'd need to build the service file(s) yourself.

---

<div class="post-metadata">

**Author:** ![Suin\_You](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@Suin\_You](https://discuss.elastic.co/u/Suin_You)\
**Post date:** [February 24, 2017, 8:26am UTC](https://discuss.elastic.co/t/logstash-run-as-a-background-service/76138/7 "2017-02-24T08:26:45Z")

</div>

I made the script file in the /etc/init.d/.

```
start(){
    if [-z $PID]
    then
        $LOGSTASH -f $CONF_FILE > $LOG 2> /dev/null &
        echo "logstash start"
    else
        echo "logstash is already running (pid $PID)"
    fi
}

```

I started this service but it also had logstash's log.

---

<div class="post-metadata">

**Author:** ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)\
**Post date:** [February 24, 2017, 6:36pm UTC](https://discuss.elastic.co/t/logstash-run-as-a-background-service/76138/8 "2017-02-24T18:36:42Z")

</div>

Don't make your own. Logstash can auto-detect the system type and install a script accordingly, or it can be coerced into installing SysV. For CentOS 6.4, the auto-detected startup type would be upstart, so you could start/stop logstash with `initctl`.

Step 1, edit `startup.options`, `logstash.yml`, and `jvm.options` found in `$LS_HOME/config/`  
Step 2, As root, or with sudo, run:

```auto
$LS_HOME/bin/system-install $LS_HOME/config/startup.options

```

for auto-detected system type, or optionally coerce sysv by appending it like this,

```auto
$LS_HOME/bin/system-install $LS_HOME/config/startup.options sysv

```

Be sure to either export `$LS_HOME` or substitute the path where you extracted the tarball. You may also need to export `JAVA_HOME` _before_ running `system-install`.

---

<div class="post-metadata">

**Author:** ![Suin\_You](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@Suin\_You](https://discuss.elastic.co/u/Suin_You)\
**Post date:** [February 27, 2017, 5:54am UTC](https://discuss.elastic.co/t/logstash-run-as-a-background-service/76138/9 "2017-02-27T05:54:02Z")

</div>

Ok. Thank you for detail answer!

---

<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 27, 2017, 5:54am UTC](https://discuss.elastic.co/t/logstash-run-as-a-background-service/76138/10 "2017-03-27T05:54:13Z")

</div>

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