# Pass the schedule dynamically to logstash config file

**URL:** <https://discuss.elastic.co/t/pass-the-schedule-dynamically-to-logstash-config-file/254351>\
**Category:** Logstash\
**Created:** [November 5, 2020, 5:48am UTC](https://discuss.elastic.co/t/pass-the-schedule-dynamically-to-logstash-config-file/254351 "2020-11-05T05:48:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shanmuka\_Chowdary](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shanmuka_chowdary/32/73073_2.png) [@Shanmuka\_Chowdary](https://discuss.elastic.co/u/Shanmuka_Chowdary)\
**Post date:** [November 5, 2020, 5:48am UTC](https://discuss.elastic.co/t/pass-the-schedule-dynamically-to-logstash-config-file/254351/1 "2020-11-05T05:48:30Z")

</div>

I'm Indexing data from mssql using logstash with schedule like below

```auto
         jdbc {
            jdbc_driver_library => "C:\Program Files\Microsoft JDBC Driver 4.2 for SQL Server\sqljdbc_4.2\enu\jre8\sqljdbc42.jar"
            jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
            jdbc_connection_string => "jdbc:sqlserver://localhost:1433;databaseName=databasename;"
            jdbc_user => "user"
            jdbc_password => "password"
            statement => "SELECT * TABLE_NAME > :sql_last_value ORDER BY CREATED_ON"
            tracking_column => "created_on"
            schedule => "*/5 * * * *"
            tracking_column_type => "timestamp"
            use_column_value => true
            jdbc_default_timezone => "EST"
        }

```

But i want to change the schedule from my web application  
Is there a way to pass the dynamic schedule to the logstash.conf file when i want to change.

---

<div class="post-metadata">

**Author:** ![Wolfram\_Haussig](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wolfram_haussig/32/70528_2.png) [@Wolfram\_Haussig](https://discuss.elastic.co/u/Wolfram_Haussig)\
**Post date:** [November 5, 2020, 6:49am UTC](https://discuss.elastic.co/t/pass-the-schedule-dynamically-to-logstash-config-file/254351/2 "2020-11-05T06:49:46Z")

</div>

Hi,

There are multiple ways to do what you want - depending on your requirements:

1. Use an [environment variable](https://www.elastic.co/guide/en/logstash/current/environment-variables.html) in the schedule. Your application would have to stop logstash, set the new value for the environment variable and start Logstash again
2. Use [automatic config reloading](https://www.elastic.co/guide/en/logstash/current/reloading-config.html). Your application would have to change the Logstash pipeline file. Logstash would detect the change and restart the pipeline
3. Use [centralized pipeline management](https://www.elastic.co/guide/en/logstash/current/logstash-centralized-pipeline-management.html). Your app would have to use the [Kibana API](https://www.elastic.co/guide/en/kibana/master/logstash-configuration-management-api-create.html) (experimental) to update the logstash pipeline. Logstash would detect the change and restart the pipeline

Maybe there are better ways to do that. but this is what I am aware of.

Best regards  
Wolfram

---

<div class="post-metadata">

**Author:** ![Shanmuka\_Chowdary](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shanmuka_chowdary/32/73073_2.png) [@Shanmuka\_Chowdary](https://discuss.elastic.co/u/Shanmuka_Chowdary)\
**Post date:** [November 5, 2020, 7:23am UTC](https://discuss.elastic.co/t/pass-the-schedule-dynamically-to-logstash-config-file/254351/3 "2020-11-05T07:23:38Z")

</div>

Hi @Wolfram_Haussig  
Thanks for the response and the information you have provided is very much helpful.  
I was reading the links you shared. Can you please help on the below points

1. Can you please give an example Where I need to set the environmental variable and How to load that to logstash in windows  
where i need to set this `export Schedule="*/1 * * * *"`

2. Is there a way to change the logstash pipeline file with java programm.

---

<div class="post-metadata">

**Author:** ![Wolfram\_Haussig](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wolfram_haussig/32/70528_2.png) [@Wolfram\_Haussig](https://discuss.elastic.co/u/Wolfram_Haussig)\
**Post date:** [November 5, 2020, 8:07am UTC](https://discuss.elastic.co/t/pass-the-schedule-dynamically-to-logstash-config-file/254351/4 "2020-11-05T08:07:01Z")

</div>

1. Environment variables  
If you have the following config:

```auto
jdbc {
            jdbc_driver_library => "C:\Program Files\Microsoft JDBC Driver 4.2 for SQL Server\sqljdbc_4.2\enu\jre8\sqljdbc42.jar"
            jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
            jdbc_connection_string => "jdbc:sqlserver://localhost:1433;databaseName=databasename;"
            jdbc_user => "user"
            jdbc_password => "password"
            statement => "SELECT * TABLE_NAME > :sql_last_value ORDER BY CREATED_ON"
            tracking_column => "created_on"
            schedule => "${JDBC_SCHEDULE}"
            tracking_column_type => "timestamp"
            use_column_value => true
            jdbc_default_timezone => "EST"
        }

```

You can start Logstash using the following commands(Linux/Unix):

```auto
set JDBC_SCHEDULE="*/5 * * * *"
./logstash.bat

```

Your program can do that using(I use Java as example, untested):

```auto
public static void main(String[] args) throws Exception {
        ProcessBuilder pb = new ProcessBuilder("cmd", "/c","start", "logstash.bat");
        Map<String, String> env = pb.environment();
        env.put("JDBC_SCHEDULE", "*/5 * * * *");

        Process p = pb.start();
        String output = loadStream(p.getInputStream());
        String error = loadStream(p.getErrorStream());
        int rc = p.waitFor();
        System.out.println("Process ended with rc=" + rc);
        System.out.println("\nStandard Output:\n");
        System.out.println(output);
        System.out.println("\nStandard Error:\n");
        System.out.println(error);
    }

```

1. LogStash pipeline file  
I am not aware of a library to parse the logstash file but you could do:

- check the [GitHub repo](https://github.com/elastic/logstash) how Logstash parses them
- use regular expressions to find and replace the values in the pipeline config

---

<div class="post-metadata">

**Author:** ![Shanmuka\_Chowdary](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shanmuka_chowdary/32/73073_2.png) [@Shanmuka\_Chowdary](https://discuss.elastic.co/u/Shanmuka_Chowdary)\
**Post date:** [November 5, 2020, 9:10am UTC](https://discuss.elastic.co/t/pass-the-schedule-dynamically-to-logstash-config-file/254351/5 "2020-11-05T09:10:16Z")

</div>

The **Java program** works fine, Thank you very much.  
Before starting the logstash I always need to kill the old process right? Can we do that with Java/ with script.

Since I'm working on windows i couldn't verify Linux/Unix command. It would be great and helpful, if you can provide windows command, So I'll skip Java and write a power shell script

---

<div class="post-metadata">

**Author:** ![Wolfram\_Haussig](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wolfram_haussig/32/70528_2.png) [@Wolfram\_Haussig](https://discuss.elastic.co/u/Wolfram_Haussig)\
**Post date:** [November 5, 2020, 9:17am UTC](https://discuss.elastic.co/t/pass-the-schedule-dynamically-to-logstash-config-file/254351/6 "2020-11-05T09:17:31Z")

</div>

> [@Shanmuka\_Chowdary](#):
>
> Before starting the logstash I always need to kill the old process right? Can we do that with Java/ with script.

Although Java does not support killing processes natively, you can use windows tools to do that(start them the same way as the logstash example above):

- Get the process using the [tasklist](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/tasklist) commandline tool
- Kill the process using [taskkill](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/taskkill) commandline tool

Powershell has the following corresponding elements:

- [Get-Process](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-process?view=powershell-7)
- [Stop-Process](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/stop-process?view=powershell-7)

---

<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 3, 2020, 9:17am UTC](https://discuss.elastic.co/t/pass-the-schedule-dynamically-to-logstash-config-file/254351/7 "2020-12-03T09:17:32Z")

</div>

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