Home > Mobile >  Tomcat OOM Kill
Tomcat OOM Kill

Time:09-27

I have a problem with tomcat. Every once in a while Tomcat get's killed by a oom...

So i tested it with stressapptest to force a oom and then trying to restart tomcat.

I wrote a simple bash script, that will restart the tomcat service.

This is the Script:

#!/bin/bash
if  [ "$(systemctl is-active tomcat9)" == "failed" ] || [ "$(systemctl is-active tomcat9)" == "inactive" ]; then
        echo "Restarting tomcat!"
        systemctl restart tomcat9.service
        exit
        else
        exit
fi

And inside the setenv.sh i wrote this option.

-XX:OnOutOfMemoryError='/root/restart.sh'

This is how the setenv.sh script looks like:

#!/bin/sh
JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djava.security.egd=file:/dev/./urandom -server -Xms1536m -Xmx1536m -XX:NewSize=1536m -XX:MaxNewSize=1536m -XX:OnOutOfMemoryError='pkill java;/root/restart.sh' -XX: DisableExplicitGC -DecadiaConsoleLogLevel=off"

But I don't know, why the Option "XX:OnOutOfMemoryError" is not working...

Can someone help me with this problem?

Thanks in advance!

CodePudding user response:

You are running Tomcat via systemd. That has two consequences:

  • Likely the startup command for Tomcat is coming from the systemd configuration instead of the script you edited. So you need to look at other files to make an effective change.

  • All you need to tell the JVM is to die on OutOfMemoryErrors. Then tell systemd to automatically restart the service. Your script is not required at all.

  • Related