How to Run Logstash Immediately and Maintain a Scheduled Execution?

I'm using Logstash to fetch data from a database and index it into Elasticsearch. My Logstash configuration includes a schedule to run every 50 minutes like this:

input {
  jdbc {
    jdbc_connection_string => "jdbc:mysql://your-database-url"
    jdbc_user => "your-user"
    jdbc_password => "your-password"
    schedule => "*/50 * * * *"
    statement => "SELECT * FROM your_table"
  }
}
output {
  elasticsearch {
    hosts => ["http://localhost:9200"]
    index => "my-index"
  }
}

What I Want to Achieve

  • Delete the Elasticsearch index at 10:00 AM every day.
  • Run Logstash immediately after the deletion.
  • Ensure Logstash continues running on the 50-minute schedule.

Logstash does not work like that, it is built to keep running until stopped.

To do what you want you need to control the execution of Logstash outside of it, like using some bash scripts and crontab.

can you explain to me the schedule in logstash configuration for example
/50 * * * * *
I want to know the starting point (is it when the logstash is started or 00:00)

If I run an exec plugin

exec { command => "/bin/true" schedule => "*/12 * * * *" }

then I get

[2025-01-30T12:41:34,777][INFO ][logstash.agent           ] Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
{
   "process" => {
       "exit_code" => 0,
    "command_line" => "/bin/true"
},
"@timestamp" => 2025-01-30T17:48:00.173038104Z,

so it looks like it starts at 00:00, not when logstash starts