3

I am using the example upstart script for logstash but am having trouble writing a pid file for monit to use at /var/run/logstash.pid

When i use "echo $$ > /var/run/logstash.pid" it writes the wrong pid value to file, I think its often the value before a fork. Is there a solution to this?

# logstash - agent instance
#

description     "logstash agent instance"

start on virtual-filesystems
stop on runlevel [06]

# Respawn it if the process exits
respawn
respawn limit 5 30
limit nofile 65550 65550
expect fork

# You need to chdir somewhere writable because logstash needs to unpack a few
# temporary files on startup.
chdir /home/logstash

script
  # This runs logstash agent as the 'logstash' user
  echo $$ > /var/run/logstash.pid
  su -s /bin/sh -c 'exec "$0" "$@"' logstash -- /usr/bin/java -jar logstash.jar agent -f /etc/logstash/agent.conf --log /var/log/logstash.log &
  emit logstash-agent-running
end script
henry.oswald
  • 5,304
  • 13
  • 51
  • 73
  • I'm not sure why you feel you need a PID file for an Upstart-managed daemon, but how about using start-stop-daemon as described in http://stackoverflow.com/questions/9972023/ubuntu-upstart-and-creating-a-pid-for-monitoring? – Magnus Bäck Jan 11 '15 at 17:32

0 Answers0