【问题标题】:cron service is running but not executing cron jobs in centoscron 服务正在运行但未在 centos 中执行 cron 作业
【发布时间】:2015-04-24 18:40:11
【问题描述】:

我创建了一个将 catalina.out 轮换出 tomcat 的策略,我的 cron 服务正在运行,我什至可以检查日志以验证作业,但我没有得到所需的输出。这是我的代码

/etc/logrotate.d/tomcat

/opt/tomcat7/logs/catalina.out {
    copytruncate
    rotate 7
    compress
    missingok
    size 1k
 }

/etc/crontab

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed
  01 * * * * root run-parts /etc/cron.hourly
  02 4 * * * root run-parts /etc/cron.daily
  22 4 * * 0 root run-parts /etc/cron.weekly
  42 4 1 * * root run-parts /etc/cron.monthly
  * * * * * root /usr/sbin/logrotate -v /etc/logrotate.conf
  * * * * * root env > /opt/env.output

/var/log/cron

Apr 24 14:49:01 staging2 CROND[30862]: (root) MAIL (mailed 5331 bytes of output but got status 0x004b#012)
Apr 24 14:50:01 staging2 CROND[30903]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Apr 24 14:50:01 staging2 CROND[30902]: (root) CMD (/usr/sbin/logrotate -v /etc/logrotate.conf)
Apr 24 14:50:01 staging2 CROND[30901]: (root) CMD (env > /opt/env.output)
Apr 24 14:50:01 staging2 CROND[30893]: (root) MAIL (mailed 5376 bytes of output but got status 0x004b#012)
Apr 24 14:51:01 staging2 CROND[30938]: (root) CMD (/usr/sbin/logrotate -v /etc/logrotate.conf)
Apr 24 14:51:01 staging2 CROND[30937]: (root) CMD (env > /opt/env.output)
Apr 24 14:51:01 staging2 CROND[30932]: (root) MAIL (mailed 5331 bytes of output but got status 0x004b#012)
Apr 24 14:52:01 staging2 CROND[30975]: (root) CMD (/usr/sbin/logrotate -v /etc/logrotate.conf)
Apr 24 14:52:01 staging2 CROND[30976]: (root) CMD (env > /opt/env.output)
Apr 24 14:52:01 staging2 CROND[30970]: (root) MAIL (mailed 5331 bytes of output but got status 0x004b#012)

我可以清楚地看到作业每分钟执行一次,它应该旋转 catalina 文件,但它没有这样做,如果我手动运行命令 /usr/sbin/logrotate -v /etc/logrotate.conf 它会完成这项工作。

【问题讨论】:

    标签: tomcat cron centos logrotate catalina


    【解决方案1】:

    我得到了解决方案。一切都很好,但你需要禁用 SELinux

    setenforce 0
    

    【讨论】:

    • 虽然这可能有效,但 SELinux 的存在是有原因的。您应该找出导致它的原因并正确配置 SELinux。
    猜你喜欢
    • 2014-05-27
    • 2018-11-18
    • 2016-12-18
    • 2019-05-13
    • 1970-01-01
    • 2013-07-31
    • 2018-02-14
    • 2014-04-04
    • 1970-01-01
    相关资源
    最近更新 更多