How to reboot Tomcat on a remote server if the application crashes?

Suppose I put a Java application on Tomcat on a remote server, say Amazon AWS. What do you recommend restarting tomcat AUTOMATICALLY if the application failed? Maybe there is a way to do this from the application itself, so if I see that the exception is very nasty, can I restart all this?

+3
source share
3 answers

One possibility would be to set a watchdog timer that monitors (for example, the port, some user checks, etc.) the application and, if necessary, restarts the entire server. It could even be a bash script that runs catalina.sh runon a managed sub-shell.

. , Zabbix , , , .

Tomcat manager, / . Apache Ant script, URL- . , , , "" .

+4

- : http://aujava.wordpress.com/2006/08/16/watchdog-for-tomcat/

isalive.html( "YES" ) script:

#!/bin/sh
HOST=127.0.0.1
PORT=8080

#infinite loop
while [ 1 ]
do
    #try to access tomcat page
    RES=`wget -O - -o /dev/null --proxy=off http://${HOST}:${PORT}/isalive.html | awk '{ print $1 }'`
    echo got ${RES}
    #decide on reply
if [ "$RES" = "YES" ]
then
    echo tomcat is responding on $HOST:$PORT
else
    echo tomcat seems to be dead.
    echo Killing...
    for thepin in `ps -Af | grep -v grep | grep tomcat | grep catalina | awk '{ print $2 }'`
    do
        kill -9 ${thepin}
    done
    echo Starting...
    sudo -u tomcat /usr/local/tomcat/bin/startup.sh
fi

sleep 60
done
+4

I would recommend looking at the monit utility. With monit, you can easily monitor maintenance, resource usage, check URLs to make sure the service responds as expected, and initiate a restart when something is wrong http://mmonit.com/monit/documentation/monit.html #connection_testing_using_the_url_notation

+1
source

Source: https://habr.com/ru/post/1789471/


All Articles