ubuntutomcatmonit

Tomcat: /etc/init.d/tomcat dont exist and monit dont work


Im trying to build monit with tomcat in ubuntu, but I have two problems.

I cant find the pid file, and "/etc/init.d/tomcat" doesnt exist

How can I did it?

This is my code in 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

Thanks!


Solution

    1. Tomcat seems not to create a pidfile regardless of config. See this gist for a hint on how to convince Tomcat to create one.
    2. If you are on Ubuntu >= 15.04 you should have systemd present (see this wiki entry). Therefore start/stop should be systemctl start tomcat and systemctl stop tomcat (or tomcat.service).

    If you cannot get your Tomcat to creating a pidfile, you can also use matching instead of a pidfile (but I would always recommend a pidfile!).

    The rest seems okay with a little limitation: If you start using systemctl to start/stop services you need to have superuser privileges to do so. You than omit the as uid tomcat gid tomcat part of the start/stop program.


    edit 2019-11-02, 14:00 UTC:

    My config would look like this:

    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