本地一切正常,我设置了一个时间驱动的工作,以不同的间隔调用某些类方法(根据某些因素发送电子邮件):
set :output, "&>>/tmp/cron_debug.log"
every 2.days, :at => '4:00 am' do
runner "Listing.listing_weekly_activity_reminder"
end
every 2.days, :at => '5:00 am' do
runner "Listing.listing_biweekly_activity_reminder"
end
every 2.days, :at => '6:00 am' do
runner "Listing.listing_last_activity_reminder"
end
every 1.day, :at => '7:00 am' do
runner "Listing.process_unanswered_messages"
end
中显示的Whenever docs进行部署
Capfile:
require 'whenever/capistrano'
现在我已经进入我的prod服务器并按照THIS回答中列出的相同步骤进行操作。
crontab -l
:
# Begin Whenever generated tasks for: /data/nestie.co/releases/20160112014954/config/schedule.rb
0 4 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 * * /bin/bash -l -c 'cd /data/nestie.co/releases/20160112014954 && bin/rails runner -e production '\''Listing.listing_weekly_activity_reminder'\'' >> &>>/tmp/cron_debug.log 2>&1'
0 5 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 * * /bin/bash -l -c 'cd /data/nestie.co/releases/20160112014954 && bin/rails runner -e production '\''Listing.listing_biweekly_activity_reminder'\'' >> &>>/tmp/cron_debug.log 2>&1'
0 6 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 * * /bin/bash -l -c 'cd /data/nestie.co/releases/20160112014954 && bin/rails runner -e production '\''Listing.listing_last_activity_reminder'\'' >> &>>/tmp/cron_debug.log 2>&1'
0 7 * * * /bin/bash -l -c 'cd /data/nestie.co/releases/20160112014954 && bin/rails runner -e production '\''Listing.process_unanswered_messages'\'' >> &>>/tmp/cron_debug.log 2>&1'
# End Whenever generated tasks for: /data/nestie.co/releases/20160112014954/config/schedule.rb
更新
的输出
grep CRON /var/log/syslog
:
Jan 12 06:35:01 localhost CRON[10670]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 06:45:01 localhost CRON[10913]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 06:55:01 localhost CRON[11156]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 07:00:01 localhost CRON[11279]: (deploy) CMD (/bin/bash -l -c 'cd /data/nestie.co/releases/20160112014954 && bin/rails runner -e production '\''Listing.process_unanswered_messages'\'' >> &>>/tmp/cron_debug.log 2>&1')
Jan 12 07:00:02 localhost CRON[11278]: (CRON) info (No MTA installed, discarding output)
Jan 12 07:17:01 localhost CRON[11758]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jan 12 07:25:01 localhost CRON[11953]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 07:35:01 localhost CRON[12196]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Dec 24 15:05:01 localhost CRON[12438]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 07:45:01 localhost CRON[12439]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 08:17:01 localhost CRON[13219]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Dec 24 15:45:01 localhost CRON[13413]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 08:25:01 localhost CRON[13414]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Dec 24 15:55:01 localhost CRON[13656]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 08:35:01 localhost CRON[13657]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 08:45:01 localhost CRON[13900]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 08:55:01 localhost CRON[14143]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 09:05:01 localhost CRON[14527]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 09:15:01 localhost CRON[14770]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 09:17:01 localhost CRON[14821]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jan 12 09:25:01 localhost CRON[15016]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 09:35:01 localhost CRON[15259]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 09:45:01 localhost CRON[15502]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 09:55:01 localhost CRON[15745]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 10:05:01 localhost CRON[15993]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 10:15:01 localhost CRON[16236]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 10:17:01 localhost CRON[16287]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jan 12 10:25:01 localhost CRON[16482]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 10:35:01 localhost CRON[16725]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 10:45:01 localhost CRON[16968]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 10:55:01 localhost CRON[17211]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 11:05:01 localhost CRON[17454]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 11:15:01 localhost CRON[17697]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 11:17:01 localhost CRON[17748]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jan 12 11:25:01 localhost CRON[17943]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 11:35:01 localhost CRON[18186]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 11:45:01 localhost CRON[18429]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 11:55:01 localhost CRON[18672]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 12:05:01 localhost CRON[18915]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 12:15:01 localhost CRON[19158]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 12:17:01 localhost CRON[19209]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jan 12 12:25:01 localhost CRON[19404]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 12:35:01 localhost CRON[19647]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 12:45:01 localhost CRON[19890]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 12:55:01 localhost CRON[20133]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 13:35:01 localhost CRON[21108]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 13:45:01 localhost CRON[21351]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 13:55:01 localhost CRON[21594]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 14:05:01 localhost CRON[21837]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 14:15:01 localhost CRON[22080]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 14:17:01 localhost CRON[22131]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jan 12 14:25:01 localhost CRON[22326]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 14:35:01 localhost CRON[22610]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 14:45:01 localhost CRON[22853]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 14:55:01 localhost CRON[23096]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 15:05:01 localhost CRON[23339]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 15:15:01 localhost CRON[23582]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 15:17:01 localhost CRON[23633]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jan 12 15:25:01 localhost CRON[23828]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 15:35:01 localhost CRON[24071]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 15:45:01 localhost CRON[24314]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 15:55:01 localhost CRON[24557]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 16:05:01 localhost CRON[24805]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 16:15:01 localhost CRON[25048]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 16:17:01 localhost CRON[25099]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jan 12 16:25:01 localhost CRON[25294]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 16:35:01 localhost CRON[25537]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 16:45:01 localhost CRON[25781]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 16:55:01 localhost CRON[26026]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 17:05:01 localhost CRON[26269]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 17:15:01 localhost CRON[26512]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 17:17:01 localhost CRON[26563]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jan 12 17:25:01 localhost CRON[26758]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 17:35:01 localhost CRON[27001]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 17:45:01 localhost CRON[27244]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 17:55:01 localhost CRON[27487]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 18:05:01 localhost CRON[27730]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 18:15:01 localhost CRON[27973]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 18:17:01 localhost CRON[28024]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jan 12 18:25:01 localhost CRON[28219]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 18:35:01 localhost CRON[28668]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 18:55:01 localhost CRON[29183]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 19:15:01 localhost CRON[29670]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 19:17:01 localhost CRON[29721]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jan 12 19:25:01 localhost CRON[29916]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 19:35:01 localhost CRON[30159]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 19:45:01 localhost CRON[30402]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 19:55:01 localhost CRON[30671]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 20:05:01 localhost CRON[30914]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 20:15:01 localhost CRON[31157]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 20:17:01 localhost CRON[31208]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jan 12 20:25:01 localhost CRON[31643]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 20:35:01 localhost CRON[31887]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 20:45:01 localhost CRON[32131]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 20:55:01 localhost CRON[32375]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 21:05:01 localhost CRON[32618]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 21:15:01 localhost CRON[394]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 21:17:01 localhost CRON[446]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jan 12 21:25:01 localhost CRON[646]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 21:35:01 localhost CRON[898]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 21:45:01 localhost CRON[1141]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 21:55:01 localhost CRON[1389]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 22:05:01 localhost CRON[1651]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 22:15:01 localhost CRON[1894]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 22:17:01 localhost CRON[1945]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jan 12 22:25:01 localhost CRON[2281]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 22:55:01 localhost CRON[3040]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 23:15:01 localhost CRON[3554]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 4 17:25:01 localhost CRON[3607]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 23:17:01 localhost CRON[3607]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jan 12 23:25:01 localhost CRON[3802]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 12 23:59:01 localhost CRON[4633]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 60 2)
Jan 13 00:05:01 localhost CRON[4780]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 13 00:15:01 localhost CRON[5385]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 13 00:17:01 localhost CRON[5437]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jan 13 00:25:01 localhost CRON[5747]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 13 00:35:01 localhost CRON[6105]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 13 00:45:01 localhost CRON[6354]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 13 00:55:01 localhost CRON[6597]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 13 01:10:44 localhost cron[7009]: (CRON) DEATH (can't open or create /var/run/crond.pid: Permission denied)
Jan 13 01:10:56 localhost cron[7016]: (CRON) DEATH (can't lock /var/run/crond.pid, otherpid may be 3604: Resource temporarily unavailable)
Dec 26 07:25:01 localhost CRON[7026]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 13 01:11:36 localhost cron[7042]: (CRON) DEATH (can't open or create /var/run/crond.pid: Permission denied)
Jan 13 01:15:01 localhost CRON[7152]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 13 01:17:01 localhost CRON[7203]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jan 13 01:25:01 localhost CRON[7399]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 13 01:35:01 localhost CRON[7841]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 13 01:45:01 localhost CRON[8084]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 13 01:55:01 localhost CRON[8327]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 13 02:05:01 localhost CRON[8570]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 13 02:15:01 localhost CRON[8814]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Jan 13 02:17:01 localhost CRON[8865]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jan 13 02:25:01 localhost CRON[9060]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
deploy@localhost:~$ sudo grep CRON /var/log/syslog
经过2天的挖掘,我仍然无能为力......!
答案 0 :(得分:1)
查看journalctl
或/var/log/
目录中的cron登录(取决于发行版)。
另请查看与此'\''Listing.listing_weekly_activity_reminder'\''
答案 1 :(得分:1)
查看您的日志似乎运行crons的用户在权限/权限方面存在一些问题:
Jan 13 01:10:44 localhost cron[7009]: (CRON) DEATH (can't open or create /var/run/crond.pid: Permission denied)
Jan 13 01:10:56 localhost cron[7016]: (CRON) DEATH (can't lock /var/run/crond.pid, otherpid may be 3604: Resource temporarily unavailable)
尝试按照此解决方案查看是否有此帮助:https://serverfault.com/questions/274434/cron-permission-denied-on-everything
更改执行权限和用户权限可能会解决此问题。