The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Crond just die and needs a restart

Discussion in 'General Discussion' started by jeroman8, May 30, 2005.

  1. jeroman8

    jeroman8 Well-Known Member

    Joined:
    Mar 14, 2003
    Messages:
    410
    Likes Received:
    0
    Trophy Points:
    16
    Hi!

    On one server crond stop working.
    I need to restart crond and then it's ok again.

    I have crond in chkconfig and/but the server is not being rebooted
    while it happens.

    I did edit the root cronfile and after that crond stoped working.
    At least it looks like that when checking the cron log file.

    But it has happened a few times now with 10-30 days in between.

    Any ideas ?
    or is there a monitor script where you can add crond and have it
    restarted if it fails ?

    thanks
     
  2. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    When you say that you edited the root cron file, what do you mean? Did you actually edit the file directly in /var/spool/cron/root or did you use crontab?
     
  3. twhiting9275

    twhiting9275 Well-Known Member

    Joined:
    Sep 26, 2002
    Messages:
    538
    Likes Received:
    15
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    Twitter:
    I've noticed this as well, for some reason crond simply fails. My solution? There's not much you can do but develop a cron check script that validates the cron PID and makes sure it's running, restarting it if it's not, emailing on restart just in case you have to do it manually. The following script is what I use, and it works, hasn't let me down so far:
    Code:
    #!/bin/bash
    DATE=`date "+%m%d%y [%k:%M]"`
    LOGDATE=`date "+%m-%d-%y [%k:%M:%S]"`
    mail=/bin/mail 
    sysadmin=YOUREMAILHERE
    cronfile=/tmp/cron.txt
    logfile=/var/log/croncheck.log
    echo "$LOGDATE - Cron Check Service starting up " >> $logfile
    function stopcron
    {
    /sbin/service crond stop
    }
    function startcron
    {
    DATE=`date "+%m%d%y [%k:%M]"`
    LOGDATE=`date "+%m-%d-%y [%k:%M:%S]"`
    stopcron
    echo "Cron Service Down, attempting to restart on $DATE" >> $cronfile
    cat $cronfile | $mail -s 'Cron Restart' $sysadmin
    /sbin/service crond start
    rm $cronfile
    }
    function checkpid
    {
    DATE=`date "+%m%d%y [%k:%M]"`
    LOGDATE=`date "+%m-%d-%y [%k:%M:%S]"`
    cronfile=/var/run/crond.pid
    #get the pid, if it exists
    if [ ! -f $cronfile ];then
    echo "$LOGDATE - Dead PID" >> $logfile
    startcron
    fi
    thispid=`cat $cronfile`
    if [ ! -d /proc/$thispid ];then
    #startcron
    echo "$LOGDATE - Cron Stopped. Restarting" >> $logfile
    startcron
    else
    echo "$LOGDATE - Normal Cron Running" >> $logfile
    fi
    
    }
    function quit {
    exit
    }
    function hello {
    echo $1
    }
     COUNTER=0
    while [  $COUNTER -lt 10 ]; do
    checkpid
    sleep 30s
     done
    
    Save this as something like croncheck.sh , add the following to /etc/rc.local
    Code:
    /bin/sh /usr/bin/nohup /bin/croncheck.sh &
    
    and run the same code once , to avoid restarting the server to get it to check.
    Code:
    /bin/sh /usr/bin/nohup /bin/croncheck.sh  >> /dev/null &
    
    Enjoy
     
  4. jeroman8

    jeroman8 Well-Known Member

    Joined:
    Mar 14, 2003
    Messages:
    410
    Likes Received:
    0
    Trophy Points:
    16
    No, I used crontab -u root -e

    Thanks for the script man, will test it!
     
Loading...

Share This Page