3

我正在为 logstash 使用示例 upstart 脚本,但在编写 pid 文件以供 monit 在 /var/run/logstash.pid 使用时遇到问题

当我使用“echo $$ > /var/run/logstash.pid”时,它会将错误的 pid 值写入文件,我认为它通常是 fork 之前的值。有针对这个的解决方法吗?

# 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
4

0 回答 0