CentOSThis forum is for the discussion of CentOS Linux. Note: This forum does not have any official participation.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
I put it in an existing con but it just isn't working.
HOW exactly did you put it in? There are various cron files. The ones in /var/spool/crontab are per user crontabs but should not be directly edited. Instead you should use "crontab -e <user>" (or if you're already the user just "crontab -e". This insures the cron daemon will pick up your changes. If you directly edit the file instead you have to restart cron for it to see the changes.
HOW exactly did you put it in? There are various cron files. The ones in /var/spool/crontab are per user crontabs but should not be directly edited. Instead you should use "crontab -e <user>" (or if you're already the user just "crontab -e". This insures the cron daemon will pick up your changes. If you directly edit the file instead you have to restart cron for it to see the changes.
I put it in 0yum-hourly.cron
crontab -e brings up a VERY confusing editor so not sure how to use taht
I assume that 0yum-hourly.cron is a file. What directory did you place the file?
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
One addition to the above is to use the absolute path to the service command.
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:
-e Edits the current crontab using the editor specified by the VIS‐
UAL or EDITOR environment variables. After you exit from the
editor, the modified crontab will be installed automatically.
Were it me I'd run crontab -e as root and add the entry. But I'd leave out the root since any job run by /var/spool/cron/root is automatically running as user root:
Code:
*/30 * * * * service tomcat restart
Finally if this is 7 as I suspect you should be using systemctl rather than service. 7 runs Systemd rather than init. Service was used for init scripts and systemctl is used for Systemd scripts. Some things can still be run with service but you should get in the habit of using the correct tools.
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".
I assume that 0yum-hourly.cron is a file. What directory did you place the file?
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
One addition to the above is to use the absolute path to the service command.
Hmm... I'm just running a basic VM CentOS 7 install and I don't anything any file called 0yum-hourly.cron
Here is the file
#!/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
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.
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
Hmm ok. But for some reason tomcat has maintained for over two hours now...
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...
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...
"Restart" of a cron isn't necessary, but have you run the command in the cron from the command line to see if it does what you want?
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?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.