cron question
I am having tomcat issues. For some reason tomcat will stop working after 20 minutes to 90 minutes. and connections to mysql will soar due to unclosed connections. This brings everything down.
So I want to run a cron to restart tomcat every 30 minutes. I know its not a good solution but I need to keep things running while trying to find whats wrong. Trouble is the software hasn't changed on my end and its been working for several years, so maybe its an OS change. Or maybe something else. the cron I want to use is */30 * * * * service tomcat restart I put it in an existing con but it just isn't working. Any ideas? Or does anyone have a cron to so this? Lou |
I assume tomcat has to be restarted as root. So you have to put this either in root's crontab, or in the system crontab. I recommend the latter.
The system crontab is /etc/crontab. The is one additional column: the user under which credentials the command has to run. So the line becomes: Code:
*/30 * * * * root service tomcat restart jlinkels |
Quote:
|
can't find file there
Quote:
|
placement
Quote:
crontab -e brings up a VERY confusing editor so not sure how to use taht |
Quote:
There are many directories where you can put the file where it will run as a system cron task. /etc/crontab /etc/cron.d /etc/cron.hourly /etc/cron.daily /etc/cron.monthly /etc/cron.weekly Code:
*/30 * * * * root /sbin/service tomcat restart |
OK I'm assuming you're on CentOS7 as I don't find that file on 6.
Interesting although file /etc/cron.hourly/0yum-hourly.cron does exist on 7 it calls a command that does NOT exist on 7 on my system so it isn't actually running. For /etc/cron.hourly the idea is not to edit existing files (unless you're changing what those specifically do) but rather to add a new one for the purpose you want. There are also cron.daily and other directories under /etc. As specified by their directory names they run only once per hour, once per day etc... You could no doubt create a job that did the restart once and hour, sleep for half and hour and restart by using cron.hourly but that would be klugey in my opinion. crontab -e edits the main user cron files in /var/spool/cron as I mentioned earlier. By default you are likely using vim as your editor. If you prefer something else like nano or (God forbid) emacs you can set your variable to use that instead. From "man crontab": Quote:
Code:
*/30 * * * * service tomcat restart With systemctl the order is slightly different than with service. Instead of "service tomcat restart" you'd run "systemctl restart tomcat". Of course this assumes you have a systemd start script for tomcat. Test with "systemctl status tomcat". |
Hmm... I'm just running a basic VM CentOS 7 install and I don't anything any file called 0yum-hourly.cron but then I don't do automatic updates.
|
Quote:
|
Quote:
#!/bin/bash */30 * * * * root service tomcat restart # Only run if this flag is set. The flag is created by the yum-cron init # script when the service is started -- this allows one to use chkconfig and # the standard "service stop|start" commands to enable or disable yum-cron. if [[ ! -f /var/lock/subsys/yum-cron ]]; then exit 0 fi # Action! exec /usr/sbin/yum-cron /etc/yum/yum-cron-hourly.conf |
A cron task is not a executable command and does not belong in a bash script.
Remove that line from your 0yum-hourly.cron file and as suggested above add the below to your /etc/crontab file. You can use any text editor but you must be root. Code:
*/30 * * * * root /sbin/service tomcat restart |
Quote:
|
Quote:
man vi (or search for vi/vim cheat sheet). I'd also recommend using systemctl instead of service: Code:
*/30 * * * * root /bin/systemctl restart tomcat.service |
Quote:
How do I 'restart' this? It was working I think for about 6 hours then tomcat stopped. Webmin reported real memory used jumped to about 6GB out of 8 and cpu usage was at 71%. Normally its single digitals... |
Quote:
Reviewing the thread I see that you've never stated which version you're using. Others (including me) presumed it was 7, but you've never verified. systemctl is version 7 only. If you're not running CentOS 7, then changing to systemctl syntax will not work...go back to the service syntax. BUT, you really need to figure out why tomcat is not working. What do the tomcat and/or http logs contain? |
All times are GMT -5. The time now is 07:49 AM. |