# Setting jvm.options with multiple logstash (5.x) instances on the same box

**URL:** <https://discuss.elastic.co/t/setting-jvm-options-with-multiple-logstash-5-x-instances-on-the-same-box/67765>\
**Category:** Logstash\
**Created:** [December 1, 2016, 1:43pm UTC](https://discuss.elastic.co/t/setting-jvm-options-with-multiple-logstash-5-x-instances-on-the-same-box/67765 "2016-12-01T13:43:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emanuele\_Verga](https://avatars.discourse-cdn.com/v4/letter/e/74df32/32.png) [@Emanuele\_Verga](https://discuss.elastic.co/u/Emanuele_Verga)\
**Post date:** [December 1, 2016, 1:43pm UTC](https://discuss.elastic.co/t/setting-jvm-options-with-multiple-logstash-5-x-instances-on-the-same-box/67765/1 "2016-12-01T13:43:34Z")

</div>

Hi all,

we recently started looking into deploying multiple instances of logstash on the same box and noticed that when the logstash settings directory is changed from the default (/etc/logstash), the jvm.options file is no longer read.

For example in our current setup we have:  
/etc/logstash/instance1/(logstash.yml, jvm.options etc)  
/etc/logstash/instance2/(logstash.yml, jvm.options etc)

and jvm.options is not detected.  
If we move jvm.options back in /etc/logstash/ then it's read as normale (although neither instance has /etc/logstash/ has settings dir)

Looking into the bin/logstash.lib.sh I found a snippet of code where the /etc/logstash/jvm.options path is hardcoded:

if [-z "$LS\_JVM\_OPTS"]; then  
for jvm\_options in /etc/logstash/jvm.options   
"$LOGSTASH\_HOME"/config/jvm.options;  
do  
...  
Is this a design decision (as the idea is it doesn't make sense to have a separate jvm.options for each installation running on the same box) or is it a bug?

Any help is appreciated  
Thanks

---

<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:** [December 1, 2016, 2:21pm UTC](https://discuss.elastic.co/t/setting-jvm-options-with-multiple-logstash-5-x-instances-on-the-same-box/67765/2 "2016-12-01T14:21:29Z")

</div>

How did you install the instances? With the RPM/DEB package, or the TAR/ZIP package?

With the code you pasted, you can clearly see that Logstash expects to find the `jvm.options` file in `/etc/logstash` or in `$LOGSTASH_HOME/config`. This is by design, as making `jvm.options` deterministic proved exceptionally hard. How will `$LOGSTASH_HOME/bin/logstash.lib.sh` know where to find `jvm.options` if it is not hard coded or in the `$LOGSTASH_HOME` path somewhere? How would you make finding it deterministic? I would be very open to adding in a deterministic way of doing this if you can find one, but this puzzle has eluded us. This is why you must set `$LS_JVM_OPTS` on your own to avoid that block of code.

Provided you have a single install (from package or tarball) the current solution is to keep these settings in `/etc/logstash` or `$LOGSTASH_HOME/config`, as they are searched in that order. If the values in `jvm.options` need to be different for different instances, you should probably consider having multiple tarball instances of Logstash on the same machine, so that each will have its own `$LOGSTASH_HOME`, and therefore can have separate configurations. You could symlink `/etc/logstash/instanceN` to the respective paths. You can also use `$LOGSTASH_HOME/bin/system-install $LOGSTASH_HOME/config/startup.options` to create separate SysV/upstart/systemd startup scripts for each instance (be sure to edit `startup.options` accordingly).

---

<div class="post-metadata">

**Author:** ![Emanuele\_Verga](https://avatars.discourse-cdn.com/v4/letter/e/74df32/32.png) [@Emanuele\_Verga](https://discuss.elastic.co/u/Emanuele_Verga)\
**Post date:** [December 1, 2016, 3:49pm UTC](https://discuss.elastic.co/t/setting-jvm-options-with-multiple-logstash-5-x-instances-on-the-same-box/67765/3 "2016-12-01T15:49:33Z")

</div>

Hi Aaron,  
Thanks for your reply.

the installation has been done using Ansible to deploy the rpm packaged logstash and deleting the standard scripts/setting files

After that templated copies of the logstash.yml, systemd scripts and default files are deployed for each instance.  
All the instances have the same LOGSTASH\_HOME, but each of the has a separate LS\_SETTINGS\_DIR with logstash.yml etc in it, a separate systemd service definition and a separate /etc/sysconfig/instance\_X\_logstash file where environment variables are defined.

I agree I wouldn't know how to make it deterministic.  
I was wondering though why logstash doesn't try to load jvm.options also from the path specified in LS\_SETTINGS\_DIR, as that is what I was expecting after reading the directory layout documentation [https://www.elastic.co/guide/en/logstash/current/dir-layout.html](https://www.elastic.co/guide/en/logstash/current/dir-layout.html), where it says the settings directory contains: "Configuration files, including logstash.yml and jvm.options"

Thank you in advance

---

<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:** [December 1, 2016, 4:13pm UTC](https://discuss.elastic.co/t/setting-jvm-options-with-multiple-logstash-5-x-instances-on-the-same-box/67765/4 "2016-12-01T16:13:23Z")

</div>

> [@Emanuele\_Verga](#):
>
> I was wondering though why logstash doesn't try to load jvm.options also from the path specified in LS\_SETTINGS\_DIR

That's a bitter irony, isn't it?

The problem is that because Logstash needs Java to run, it needs its Java settings to be set _before_ it can load any of the other configuration data. That means that it doesn't know where `$LS_SETTINGS_DIR` is until _after_ it's actually started the startup process and reads the other configuration files. It can easily determine where `$LS_HOME` is, but what if `$LS_SETTINGS_DIR` is _not_ a subdirectory of `$LS_HOME`?

If you are setting environment variables in `/etc/sysconfig/instance_X_logstash`, you might try to set `$LS_JVM_OPTS` in there, having it point to the location of the respective `jvm.options` file. It's _supposed_ to use that, as stated in my previous post.

---

<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:** [December 26, 2016, 8:25pm UTC](https://discuss.elastic.co/t/setting-jvm-options-with-multiple-logstash-5-x-instances-on-the-same-box/67765/5 "2016-12-26T20:25:12Z")

</div>

I should point out here that this (not reading `jvm.options` from the `$LS_SETTINGS_DIR`) is resolved and will ship in Logstash 5.2.0: [https://github.com/elastic/logstash/pull/6382](https://github.com/elastic/logstash/pull/6382)

---

<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:** [January 23, 2017, 8:25pm UTC](https://discuss.elastic.co/t/setting-jvm-options-with-multiple-logstash-5-x-instances-on-the-same-box/67765/6 "2017-01-23T20:25:16Z")

</div>

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