2
我做了一些研究,但是所有與cron和bundle exec有關的問題都沒有涵蓋如果討論過這個問題,我還有這麼多問題。bundle exec rake不能在cron中運行
我正在運行Ubuntu 13.10,並且每隔幾分鐘左右就有一個Ruby On Rails應用程序需要在Cron上運行少量rake任務。
我跑每當寶石,與這句法
every 3.minutes do
rake 'update_balance'
end
轉變這條線在crontab文件幫助
0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57 * * * * /bin/bash -l -c 'cd /var/fruby/releases/20140513091404 && RAILS_ENV=production bundle exec rake update_balance --silent'
當我複製此行正是
/bin/bash -l -c 'cd /var/fruby/releases/20140513091404 && RAILS_ENV=production bundle exec rake update_balance --silent'
並在其中運行控制檯,它運行得非常好,並更新數據庫中的幾個記錄,如suppos編輯。
但是,當設置爲cron時,我可以看到它在/ var/log/syslog文件中運行,但沒有任何執行。
May 13 13:06:01 sandbox2 CRON[9656]: (root) CMD (/bin/bash -l -c 'cd /var/fruby/releases/20140513091404 && RAILS_ENV=production bundle exec rake update_balance --silent')
May 13 13:06:01 sandbox2 CRON[9655]: (CRON) info (No MTA installed, discarding output)
May 13 13:09:01 sandbox2 CRON[9789]: (root) CMD (/bin/bash -l -c 'cd /var/fruby/releases/20140513091404 && RAILS_ENV=production bundle exec rake update_balance --silent')
即使當我添加&> /tmp/mycommand.log到crontab命令,每一次啓動cron命令的只是完全截斷這個文件,但再次,如果我手動啓動它,它工作得很好,並給我留下與此輸出。
2014-05-13T11:11:25Z 10292 TID-2asbo INFO: Sidekiq client with redis options {:url=>"redis://127.0.0.1"}
Sent task for updating 2 users
對這個問題的任何幫助是非常感謝。 謝謝。
您也可以[中設置環境變量的'crontab'本身(http://stackoverflow.com/questions/2229825/where -can-i-set-environment-variables-that-crontab-will-use)如果你想讓它們適用於所有任務。 – tadman
這聽起來更合理:) –
謝謝,它的工作。以後再看看環境變量。 這是我的crontab行現在看起來如何。 0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57 * * * */bin/bash - l -c'cd/var/fruby/releases/20140513091404 && RAILS_ENV = production/usr/local/bin/bundle exec/usr/bin/rake update_balance --silent' – Screatch