Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have an ec2 image created with cron jobs.

These jobs fail to run; I discovered the cron process in itself has not started. So, I included /usr/sbin/cron in /etc/rc.d/rc.local and created another image. But still for some reason the cron process does not start on bootup.

If I restart the machine, the cron process runs. It doesn't run when it boots up!

Any reason why this is happening? Also, is there any other alternatives for this ?

share|improve this question

migrated from stackoverflow.com Jul 1 '11 at 15:28

This question came from our site for professional and enthusiast programmers.

    
Can you give us an idea of what Linux distribution you're running? The output of uname -a would be sufficient. –  Handyman5 Jul 1 '11 at 18:01
add comment

2 Answers

Make sure the directory /etc/rc.d/init.d (or /etc/init.d for ubuntu) has crond in it.

If not, here's what our (open source) GNU/Linux contained out of the box. (sorry for long post, but it's not that long):

#! /bin/bash
#
# crond          Start/Stop the cron clock daemon.
#
# chkconfig: 2345 90 60
# description: cron is a standard UNIX program that runs user-specified \
#              programs at periodic scheduled times. vixie cron adds a \
#              number of features to the basic UNIX cron, including better \
#              security and more powerful configuration options.
# processname: crond
# config: /etc/crontab
# pidfile: /var/run/crond.pid

# Source function library.
. /etc/init.d/functions
. /etc/sysconfig/crond
t=${CRON_VALIDATE_MAILRCPTS:-UNSET}
[ "$t" != "UNSET" ] && export CRON_VALIDATE_MAILRCPTS="$t"

# See how we were called.

prog="crond"

start() {
    echo -n $"Starting $prog: " 
        if [ -e /var/lock/subsys/crond ]; then
        if [ -e /var/run/crond.pid ] && [ -e /proc/`cat /var/run/crond.pid` ]; then
        echo -n $"cannot start crond: crond is already running.";
        failure $"cannot start crond: crond already running.";
        echo
        return 1
        fi
    fi
    daemon crond $CRONDARGS
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/crond;
    return $RETVAL
}

stop() {
    echo -n $"Stopping $prog: "
        if [ ! -e /var/lock/subsys/crond ]; then
        echo -n $"cannot stop crond: crond is not running."
        failure $"cannot stop crond: crond is not running."
        echo
        return 1;
    fi
    killproc crond
    RETVAL=$?
    echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/crond;
    return $RETVAL
}   

rhstatus() {
    status crond
}   

restart() {
    stop
    start
}   

reload() {
    echo -n $"Reloading cron daemon configuration: "
    killproc crond -HUP
    RETVAL=$?
    echo
    return $RETVAL
}   

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    restart
    ;;
  reload)
    reload
    ;;
  status)
    rhstatus
    ;;
  condrestart)
    [ -f /var/lock/subsys/crond ] && restart || :
    ;;
  *)
    echo $"Usage: $0 {start|stop|status|reload|restart|condrestart}"
    exit 1
esac
share|improve this answer
    
there is no such file as /etc/rc.d/init.d in ubuntu :( –  vkris Jul 1 '11 at 3:30
    
ubuntu uses /etc/init.d instead. good luck –  Bohemian Jul 1 '11 at 3:48
    
well thats a folder. There are several boot scripts present in that folder and there is cron process as well ! –  vkris Jul 1 '11 at 12:51
add comment

Do you not see any cron log entries in /var/log/syslog?

# grep cron /var/log/syslog*
<grep output here>

Regardless, maybe cron got disabled. Make sure it's not actually running:

# status cron
cron start/running, process 1103

If the output of that command was cron stop/waiting, make sure your /etc/init/cron.conf file exists and is correct (it should be). Here are the contents on my 11.04 (same on 10.04) box:

# cron - regular background program processing daemon
#   
# cron is a standard UNIX program that runs user-specified programs at
# periodic scheduled times

description "regular background program processing daemon"

start on runlevel [2345]
stop on runlevel [!2345]

expect fork
respawn

exec cron

If everything looks good, try starting the daemon with start cron.

Otherwise, if all else fails you can try looking for cron errors in /var/log/*.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.