Setting up Self Healing Tomcat

System Administrator has to configure Critical services regularly. He/She also needs to monitor that services and if services stop then needs to start them. We can automate starting of service after failure using Daemontools/supervise. We can also use monit for same. In this note we will configure Daemontools to monitor Tomcat service and if Tomcat crashes, Daemontools will start it automatically.

Daemontools will make sure that tomcat service is running.

For Demo I have used OS -> CentOS-7 64bit &  Tomcat Version -> 8

Here are steps: Install Daemontools

$ git clone https://github.com/kteru/daemontools-rpm.git
$ cd /root/daemontools-rpm
$ wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
$ sudo yum -y install rpm-build redhat-rpm-config make gcc
$ cd /root/daemontools-rpm
$ ./buildrpm.sh
$ rpm -ivh /root/rpmbuild/RPMS/x86_64/daemontools-0.76-1.el7.x86_64.rpm
$ systemctl restart daemontools

Go to Tomcat Home. eg. /opt/tomcat

$ cd /opt/tomcat
$ cat >> /opt/tomcat/run <<'EOF'
#!/bin/sh
exec 2>&1
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75-2.5.4.2.el7_0.x86_64/jre
export JAVA_OPTS="-Xms512M -Xmx2048M -XX:+UseParallelGC -server"
export TOMCAT_HOME=/opt/tomcat
exec setuidgid root ${TOMCAT_HOME}/bin/catalina.sh run
EOF
$ chmod 755 /opt/tomcat/run

Configure Logging with multilog

$ mkdir /opt/tomcat/log
$ cat >> /opt/tomcat/log/run <<'EOF'
#!/bin/sh
multilog t n1024 s104857600 /opt/tomcat/log/
EOF
$ chmod 755 /opt/tomcat/log/run

Create Symlink tomcat in /service

$ ln -s /opt/tomcat /service/tomcat

Start daemontools service

$ systemctl restart daemontools


Now you can check status

$ svstat /service/tomcat
$ svstat /service/tomcat/log

Ref: https://github.com/kteru/daemontools-rpm





Neelesh Gurjar has written 120 articles