Run as service

This post explains in details how to run logstash as a service on a Linux server.

It is possible to run logstash in different ways from the command line. But once you’ve run your tests, you’ll usually want your logstash instances running on the server, and to be able to start and stop it at will.

Moreover, there are in general different logstash instances running on the same server. Each of them must then be manipulated independently from the others.

Thus, our solution must respect following constraints :

  • logstash must run in background, even after a reboot.
  • Many instances may be running at the same time.
  • There must be a way to start/stop each one separately.

As I’m very bad as a sysadmin, this solution has been given to me by josephholsten from #logstash IRC channel on freenode. It’s based upon upstart, and works on Ubuntu, et most Linux distributions.

I’m assuming for this example that you’ll use the following directories :

  • /opt/logstash : contains logstash.jar file (should be a symbolic link to the last version)
  • /etc/logstash : contains the config files for each instances (in out case, they will be input.config and output.config)
  • /var/log/logstash : will contain the logs

Create a service configuration file for each instance in /etc/init with the name <servicename>.conf (eg. logstash-input.conf):

And that’s it. You may now control your service with :

sudo service logstash-input start
sudo service logstash-input stop
sudo service logstash-input status

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© Crocoware technical blog