Skip to content →

CRON jobs to free Memory Leaks of web servers

Some webserver don’t protect well again memory leaks. And the Java garbage collector is not necessarily famous for sweeping properly. Whatever the cause is of the artefact, you need to fix it in your code.

As a temporary workaround for an older web service I’ve written – but is not in use anymore – I restarted the web container on a daily basis. Automated with cron of course.

The easiest way to avoid path resolution mistakes is to work with system control systemctl. Why? Because the executable is already defined in the service definition file (in this case in Ubuntu). In my case that is safed at /etc/systemd/system/wildfly.service

[Unit]
Description=The WildFly Application Server
After=syslog.target network.target
Before=httpd.service

[Service]
Environment=LAUNCH_JBOSS_IN_BACKGROUND=1
EnvironmentFile=/etc/default/wildfly
User=wildfly
LimitNOFILE=102642
PIDFile=/var/run/wildfly/wildfly.pid
ExecStart=/opt/wildfly/bin/launch.sh $WILDFLY_MODE $WILDFLY_CONFIG $WILDFLY_BIND
StandardOutput=null

[Install]
WantedBy=multi-user.target

Open the cron file crontab -e. Add a new line to invoke the systemctl command with the arguments of the service and command.

05 04 * * * systemctl restart wildfly

This cron job will start at 04:05 every day to restart the wildfly service respectively the container. This will free blocked memory availability. Anyhow, an increase of requests might still block the server

Published in Server Configuration

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *