2 questions, cron job not running restart, kill not gracefully restarting - cron

I put the following cron job in my root crontab under var/spool/cron
*/5 * * * * service php-fpm-5.5.11 restart
I see it called in the cron logs every 5 minutes, so I know it is being called, but it is not restarting php-fpm.
Question 1:
Is there a different way to restart services when calling them in cron?
What would be the correct way to call this restart?
Another question and the root of the problem is I have another call that runs every night that sometimes kills my website altogether because php-fpm is not restarting correctly:
/bin/kill -SIGUSR1 `cat /opt/pifpm/php-5.5.11/var/run/php-fpm.pid 2>/dev/null` 2>/dev/null || true
I get:
[12-Jul-2015 00:52:29] ERROR: An another FPM instance seems to already listen on /opt/pifpm/fpmsockets/5.5.11.sock
[12-Jul-2015 00:52:29] ERROR: FPM initialization failed
Question 2
Is there a better way to call the kill statement? For instance:
[ ! -f /opt/pifpm/php-5.5.11/var/run/php-fpm.pid ] || kill -USR2 `cat /opt/pifpm/php-5.5.11/var/run/php-fpm.pid`
This is an nginx and centos setup.
Here is a portion of the cron log:
Jul 15 12:15:01 insp CROND[7325]: (root) CMD (service php-fpm-5.5.11 restart)
Jul 15 12:15:01 insp CROND[7326]: (root) CMD (/usr/local/cpanel/scripts/recoverymgmt >/dev/null 2>&1)
Jul 15 12:15:01 insp CROND[7327]: (root) CMD (/usr/local/cpanel/bin/dcpumon >/dev/null 2>&1)
Jul 15 12:15:01 insp CROND[7332]: (root) CMD (/usr/local/cpanel/scripts/autorepair recoverymgmt >/dev/null 2>&1)
Jul 15 12:15:01 insp CROND[7333]: (root) CMD (/usr/local/cpanel/bin/dbindex >/dev/null 2>&1)
Jul 15 12:16:53 insp /usr/bin/crontab[7530]: (root) BEGIN EDIT (root)
Jul 15 12:16:57 insp /usr/bin/crontab[7530]: (root) END EDIT (root)
Jul 15 12:20:01 insp CROND[7842]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 15 12:20:01 insp CROND[7845]: (root) CMD (/usr/local/cpanel/bin/dcpumon >/dev/null 2>&1)
Jul 15 12:20:01 insp CROND[7846]: (root) CMD (service php-fpm-5.5.11 restart)
Jul 15 12:20:01 insp CROND[7847]: (root) CMD (/usr/local/maldetect/maldet --mkpubpaths >> /dev/null 2>&1)

Answer to the Question number 1.
/etc/rc.d/init.d/php-fpm-5.5.11 restart is the correct path to use in cron.
The /etc/rc.d/init.d has most of the services in the directory including httpd

Related

How to send UDP packet from Debian 9 CRON?

I am trying with these 2 scripts:
test1,sh:
#!/bin/sh
NOW=$(date +"NOW;%Y;%m;%d;%H;%M;%S")
echo -n $NOW | nc -u -q 2 -w 2 192.168.0.252 4210
test2.sh:
#!/bin/sh
NOW=$(date +'NOW;%Y;%m;%d;%H;%M;%S')
echo -n $NOW > /dev/udp/192.168.0.252/4210
Both scripts works fine when directly execute on terminal, client successfully receiving the UDP packets.
*/5 * * * * root /etc/test/test1.sh
*/5 * * * * root /etc/test/test2.sh
But doesn't work when executing in CRON, client did not receive the UDP packets.
**sudo grep CRON /var/log/syslog**
Mar 10 16:40:01 localhost CRON[12281]: (CRON) info (No MTA installed, discarding output)
Mar 10 16:40:01 localhost CRON[12286]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Mar 10 16:40:01 localhost CRON[12287]: (root) CMD (root /etc/test/test1.sh)
Mar 10 16:40:01 localhost CRON[12289]: (root) CMD (root /etc/test/test2.sh)
Please help
Is the next to last block the output of crontab -l? Looks to me like there's an extra "root" in there.
The hint is in your syslog output:
Mar 10 16:40:01 localhost CRON[12289]: (root) CMD (root /etc/test/test2.sh)
Remove the root from your crontab and you'll have better luck.

Why the crontab run in duplicated times?

I have added an crontab like this:
*/15 * * * * /home/test/demo.py
However, it runs in two times. And, we can see that two logs are logged in /var/log/cron:
Jun 30 20:00:01 demo1.ops.dev CROND[29181]: (root) CMD (/home/test/a.py)
Jun 30 20:00:01 demo1.ops.dev CROND[29180]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jun 30 20:00:01 demo1.ops.dev CROND[29189]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jun 30 20:00:01 demo1.ops.dev CROND[29190]: (root) CMD (/home/test/a.py)
Answered by myself,
I restart the crond daemon. It can not resolve the problem,
I restart the machine. It can not be scheduled properly.

Command not found even crontab PATH is set

Even though I set the PATH in /etc/crontab as
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/lib/mailman/cron:/usr/lib/mailman/bin
commands found in /usr/lib/mailman/cron are still not found, Thus issuing a mail to root saying
/bin/sh: mailman: command not found
I've debugged the problem, setting up a cron entry
* * * * * /bin/echo "`/bin/date`: $PATH" >> /tmp/crontest.log 2>&1
using crontab -e which actually do write the PATH to /tmp/crontest.log, confirming that the path entered in /etc/crontab is not what cron think it should be.
Fri Feb 14 10:22:01 CET 2014: /usr/bin:/bin
I've also tried to solve it by re-start cron using (both) service crond restart and service crond stop;sleep 5;service crond start (which does the same, but to make absolutely certain that it has been restarted), but this doesn't change anything.
The /etc/crontab file is readable by everyone (permissions is 644 root root)
-rw-r--r-- 1 root root 500 10 feb 10:36 /etc/crontab
/var/log/cron does not show anything about the problem, just what's started and when I restarted the cron
grep -v CMD /var/log/cron
.
.
.
Feb 14 09:45:34 p1kitlst01l crond[12214]: (CRON) INFO (running with inotify support)
Feb 14 09:45:34 p1kitlst01l crond[12214]: (CRON) INFO (#reboot jobs will be run at computer's startup.)
Feb 14 09:48:07 p1kitlst01l crontab[12331]: (root) BEGIN EDIT (root)
Feb 14 09:48:45 p1kitlst01l crontab[12331]: (root) REPLACE (root)
Feb 14 09:48:45 p1kitlst01l crontab[12331]: (root) END EDIT (root)
Feb 14 09:49:01 p1kitlst01l crond[12214]: (root) RELOAD (/var/spool/cron/root)
Feb 14 10:01:01 p1kitlst01l run-parts(/etc/cron.hourly)[13010]: starting 0anacron
Feb 14 10:01:01 p1kitlst01l run-parts(/etc/cron.hourly)[13027]: finished 0anacron
Feb 14 10:01:01 p1kitlst01l run-parts(/etc/cron.hourly)[13010]: starting mcelog.cron
Feb 14 10:01:01 p1kitlst01l run-parts(/etc/cron.hourly)[13039]: finished mcelog.cron
Feb 14 10:19:16 p1kitlst01l crontab[13840]: (root) BEGIN EDIT (root)
Feb 14 10:19:23 p1kitlst01l crontab[13840]: (root) END EDIT (root)
Feb 14 10:27:17 p1kitlst01l crond[14170]: (CRON) STARTUP (1.4.4)
Feb 14 10:27:17 p1kitlst01l crond[14170]: (CRON) INFO (running with inotify support)
Feb 14 10:27:17 p1kitlst01l crond[14170]: (CRON) INFO (#reboot jobs will be run at computer's startup.)
Any suggestions to what I have to look in to?
Henrik
What I think is ,you have two ways to go (maybe others provide more).
1) set the absolute path for mailman in your script.
2) source the .profile, then run the script, such as:
0 1 * * * . ~/.profile; bash your_script.sh

crontab doesn't execute his jobs

I have a problem with executing crontab jobs. I guess I have everything configured properly but when i put:*/2 * * * * /var/www/site/executescript.sh in crontab -e My script is not being executed at all.. Only thing i get in cron.log is:
Feb 15 10:22:35 server crontab[2222]: (root) BEGIN EDIT (root)
Feb 15 10:22:45 server crontab[2222]: (root) REPLACE (root)
Feb 15 10:22:45 server crontab[2222]: (root) END EDIT (root)
Feb 15 10:26:24 server crontab[2329]: (root) BEGIN EDIT (root)
Feb 15 10:27:17 server crontab[2329]: (root) REPLACE (root)
Feb 15 10:27:17 server crontab[2329]: (root) END EDIT (root)
Feb 15 10:29:34 server crontab[2415]: (root) BEGIN EDIT (root)
Feb 15 10:29:53 server crontab[2415]: (root) REPLACE (root)
Feb 15 10:29:53 server crontab[2415]: (root) END EDIT (root)
What mean that cron doesn't even try to execute my script. Do anyone knew what is this related to? Does it mean there is an error in my script ( i don't see one..) Is there a place where i can check more accurate cron logs?
Version of my cron is v5.0
You need to define the binary executing the script. Try with this:
*/2 * * * * /bin/sh /var/www/site/executescript.sh in

Crontab is running command 3 times each run

I have the following crontab set up on a RHEL server ...
MAILTO=me#mydomain.com
*/2 * * * * wget --spider -q http://mydomain.com/cronjobs/importxml.php
As you can see this should run every 2 minutes, which it does, but it runs the command three times and I can't figure out why.
If I run
tail /var/log/cron
I get the following
Dec 12 13:56:01 msvsc02-g283nc crond[1431]: (root) RELOAD (cron/root)
Dec 12 13:56:01 msvsc02-g283nc crond[3224]: (root) CMD (wget --spider -q http://mydomain.com/cronjobs/importxml.php)
Dec 12 13:56:01 msvsc02-g283nc crond[2504]: (root) RELOAD (cron/root)
Dec 12 13:56:01 msvsc02-g283nc crond[3226]: (root) CMD (wget --spider -q http://mydomain.com/cronjobs/importxml.php)
Dec 12 13:56:01 msvsc02-g283nc crond[2472]: (root) RELOAD (cron/root)
Dec 12 13:56:01 msvsc02-g283nc crond[3228]: (root) CMD (wget --spider -q http://mydomain.com/cronjobs/importxml.php)
Can anyone shed any light on this?
You may have more than one cron process running in that server. This normally wont happen. But anyway confirm it with
ps aux | grep cron
You can stop it by,
/etc/init.d/cron stop
or
service cron stop
or use 'kill PID' ( not recommended ).
And to start use start - instead of stop in either of above two commands.

Resources