I'm attempting to run Logstash under supervision with runit. My run script for Logstash is simply
#!/bin/sh
SSL_CERT_DIR=/etc/ssl/certs exec /usr/bin/java -jar /usr/local/bin/logstash.jar agent -f /tmp/logstash.conf --log /var/log/logstash.log
If I run this script manually it takes 30 or 45 seconds for the process to properly start up and start doing work, but it will stay up afterwards for a couple hours. However, when I try to do sv start logstash
it executes the script (and Logstash definitely starts because I see output written to /var/log/logstash.log), but after 15 or 20 seconds runit seems to kill and restart the Logstash java process.
I've tried setting the -w
option, but it doesn't seem to wait any longer for the process to run.
How can I have runit properly let this Java process process run and only restart it when it dies?
Best Answer
First, install
svlog
. Using it is fairly painless.Second, (assuming the service definition lives at /etc/sv) change your
/etc/sv/logstash/run
to say:You are right in that
stderr
must be redirected tostdout
.Then, do this (adapting to your installation as needed):
This creates a log entry for the service, sets up a stub file to be edited, creates a directory to hold the log files, and provides a symlink for the logging service to divert output to.
Finally, put this in
/etc/sv/logstash/log/run
Restart your service with sv restart logstash and wait a few seconds...and you should have two processes listed, your
logstash
service and thesvlog
running with it. All of the output fromlogstash
will be fed intosvlog
, which in turn will write a log file to the/etc/sv/logstash/log/main
symlink, which in turn drops off in/var/log/logstash/current
. Terminating thelogstash
service withsv stop logstash
will allow any final output to flush intosvlog
which will write to disk before exiting.