Ubuntu Tomcat:/etc/init.d/Tomcat不存在,并且monit不工作

Ubuntu Tomcat:/etc/init.d/Tomcat不存在,并且monit不工作,ubuntu,tomcat,monit,Ubuntu,Tomcat,Monit,我试图在ubuntu中用tomcat构建monit,但我有两个问题 我找不到pid文件,/etc/init.d/tomcat不存在 我怎么能做到 这是我在monit中的代码: 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 = "/us

我试图在ubuntu中用tomcat构建monit,但我有两个问题

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

我怎么能做到

这是我在monit中的代码:

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
谢谢

无论配置如何,Tomcat似乎都不会创建PID文件。有关如何说服Tomcat创建一个的提示,请参阅。 如果你在Ubuntu>=15.04上,你应该有systemd present,请参阅。因此,启动/停止应为systemctl start tomcat和systemctl stop tomcat或tomcat.service。 如果您无法让Tomcat创建pidfile,您也可以使用而不是pidfile,但我始终建议使用pidfile

剩下的似乎还可以,但有一点限制:如果开始使用systemctl启动/停止服务,则需要具有超级用户权限。您可以省略启动/停止程序的as-uid-tomcat-gid-tomcat部分

编辑2019-11-02,协调世界时14:00:

我的配置如下所示:

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
无论配置如何,Tomcat似乎都不会创建PID文件。有关如何说服Tomcat创建一个的提示,请参阅。 如果你在Ubuntu>=15.04上,你应该有systemd present,请参阅。因此,启动/停止应为systemctl start tomcat和systemctl stop tomcat或tomcat.service。 如果您无法让Tomcat创建pidfile,您也可以使用而不是pidfile,但我始终建议使用pidfile

剩下的似乎还可以,但有一点限制:如果开始使用systemctl启动/停止服务,则需要具有超级用户权限。您可以省略启动/停止程序的as-uid-tomcat-gid-tomcat部分

编辑2019-11-02,协调世界时14:00:

我的配置如下所示:

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

嗨,波比!谢谢你的回答:我按照你对第一点的评论做了,效果很好。但我有一个疑问,在我的代码中,我应该删除uid-tomcat-gid-tomcat,只留下start/stop-program=/路线/,不是吗?乍一看有点奇怪,但这是有道理的:systemd将使用非root用户启动tomcat。但要做到这一点,它需要超级用户权限。因此,对systemctl的调用是使用超级用户完成的,而结果是作为非超级用户启动的二进制文件。-我还添加了一个可能会起作用的最终配置。非常感谢@boppy:这非常有用。非常感谢。嗨,波比!谢谢你的回答:我按照你对第一点的评论做了,效果很好。但我有一个疑问,在我的代码中,我应该删除uid-tomcat-gid-tomcat,只留下start/stop-program=/路线/,不是吗?乍一看有点奇怪,但这是有道理的:systemd将使用非root用户启动tomcat。但要做到这一点,它需要超级用户权限。因此,对systemctl的调用是使用超级用户完成的,而结果是作为非超级用户启动的二进制文件。-我还添加了一个可能会起作用的最终配置。非常感谢@boppy:这非常有用。非常感谢你。