Cron 进程未启动

Cron 进程未启动

我有一个用 cron 作业创建的 ec2 图像。

这些作业无法运行;我发现 cron 进程本身尚未启动。因此,我将 /usr/sbin/cron 包含在 /etc/rc.d/rc.local 中并创建了另一个映像。但出于某种原因,cron 进程仍未在启动时启动。

如果我重启机器,cron 进程就会运行。它在启动时不会运行!

发生这种情况的原因是什么?此外,还有其他替代方案吗?

答案1

您在 /var/log/syslog 中看不到任何 cron 日志条目吗?

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

无论如何,也许 cron 已被禁用。确保它实际上没有运行:

# status cron
cron start/running, process 1103

如果该命令的输出是cron stop/waiting,请确保您的/etc/init/cron.conf文件存在并且正确(应该是)。以下是我在 11.04(10.04 上也一样)机器上的内容:

# 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

如果一切正常,请尝试使用 启动守护进程start cron

否则,如果其他方法都失败了,您可以尝试在中寻找 cron 错误/var/log/*

答案2

确保该目录/etc/rc.d/init.d(或/etc/init.d对于 ubuntu)包含crond在其中。

如果没有,以下是我们(开源)GNU/Linux 开箱即用的功能。(抱歉这篇文章很长,但事实并非如此)长的):

#! /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

相关内容