首页 > 解决方案 > Tomcat:/etc/init.d/tomcat 不存在且 monit 不起作用

问题描述

我试图在 ubuntu 中使用 tomcat 构建监视器,但我有两个问题。

我找不到 pid 文件,并且“/etc/init.d/tomcat”不存在

我该怎么做?

这是我在监控中的代码:

check process tomcat with pidfile "/var/run/tomcat/tomcat.pid"
  start program = "/usr/local/tomcat/bin/startup.sh" as uid tomcat gid tomcat
  stop program = "/usr/local/tomcat/bin/shutdown.sh" as uid tomcat gid tomcat
  if failed port 8080 then alert
  if failed port 8080 for 5 cycles then restart

谢谢!

标签: ubuntutomcatmonit

解决方案


  1. 无论配置如何,Tomcat 似乎都不会创建 pidfile。有关如何说服 Tomcat 创建一个的提示,请参阅此要点。
  2. 如果您使用的是 Ubuntu >= 15.04,您应该已经systemd在场(请参阅此 wiki 条目)。因此开始/停止应该是systemctl start tomcatsystemctl stop tomcat(或tomcat.service)。

如果你不能让你的 Tomcat 创建一个 pidfile,你也可以使用匹配而不是一个 pidfile(但我总是推荐一个 pidfile!)。

其余的似乎还可以,但有一点限制:如果您开始使用systemctl启动/停止服务,则需要具有超级用户权限才能这样做。你比省略as uid tomcat gid tomcat.start/stop program


编辑 2019-11-02, 14:00 UTC

我的配置看起来像这样:

check process tomcat with pidfile "/var/run/tomcat/tomcat.pid"
  start program = "/bin/systemctl start tomcat.service"
  stop program = "/bin/systemctl stop tomcat.service"
  if failed port 8080 then restart
  if 3 restarts within 5 cycles then unmonitor

推荐阅读