'Restart Tomcat Service on AWS EC2 instance, on a schedule

I have an instance on Tomcat running on EC2. Based on some resourcing reasons that I don't want to get into, I'd like it to restart each evening at 11:00pm. I'm not interested in reloading or stopping the applications context as the PermGen space gets crowded until eventually the box tips over and dies.

So where on an aws linux instance do I specify service tomcat7 restart and give it a cron expression?



Solution 1:[1]

To add a cronab entry for root user:

sudo crontab -e

which will open an editor. Insert the following line to restart tomcat7 at 11pm daily

0 23 * * * /sbin/service tomcat7 restart

Update: /sbin/service tomcat7 restart no longer works as of 2022.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 niemand