我试图在 ubuntu 中使用 tomcat 构建 monit,但我遇到了两个问题。
我找不到 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
谢谢!
最佳答案
- 无论配置如何,Tomcat 似乎都不会创建 pid 文件。参见 this gist获取有关如何说服 Tomcat 创建一个的提示。
- 如果您使用的是 Ubuntu >= 15.04,您应该有
systemd
(参见 this wiki entry)。因此,启动/停止应该是systemctl start tomcat
和systemctl stop tomcat
(或tomcat.service
)。
如果你不能让你的 Tomcat 创建一个 pid 文件,你也可以使用 matching而不是 pidfile(但我总是推荐 pidfile!)。
其余的似乎没问题,但有一点限制:如果您开始使用 systemctl
来启动/停止服务,您需要有 super 用户权限才能这样做。您可以省略 start/stop program
的 as uid tomcat gid tomcat
部分。
编辑 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
关于ubuntu - Tomcat:/etc/init.d/tomcat 不存在并且 monit 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58646808/