我在rails应用程序中随时使用并使用capistrano进行部署.
麻烦的是,因为我只将它用于一个项目没有问题,但是当我在同一服务器上使用更多项目时,每次部署我的项目时,我都会销毁并重新创建cron文件.我需要每个项目都更新它或附加新指令,以便在同一台服务器上共存.
我只是部署
deploy.rb
set :whenever_command, "bundle exec whenever"
require "whenever/capistrano"
...
after "deploy:create_symlink", "deploy:update_crontab"
....
Run Code Online (Sandbox Code Playgroud)
有人可以教我怎么办?
deployment capistrano ruby-on-rails whenever whenever-capistrano
我一直在Slicehost的2岁以上的切片上使用随时随地的宝石.然而,我不能在我的新片上做同样的事情.
主要区别在于我现在在我的MBP和切片上运行RVM.我也在运行Rails 3.我有Rubygems v 1.5.0和最新版本的RVM,Ruby 1.9.2p136,Capistrano以及其他所有包.
我已经尝试了一百万件事,阅读了所有的文档,截至目前我正在使用随时随地的0.6版本.我还查看了关于SO和Google相关主题的所有问题.
以下是deploy.rb中的代码:
namespace :deploy do
...
desc "Update the crontab file"
task :update_crontab, :roles => :db do
run "cd #{release_path} && whenever --update-crontab #{application}"
end
end
after 'deploy:update_code', 'deploy:update_crontab'
Run Code Online (Sandbox Code Playgroud)
以下是运行'cap deploy'后出现的错误消息
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.2' -c 'cd /home/deploy/public_html/lasource/releases/20110209201551 && /home/deploy/.rvm/gems/ruby-1.9.2-p136/bin/whenever --write-crontab'" on lasource.ohlalaweb.com
Run Code Online (Sandbox Code Playgroud)
欢迎任何建议.
顺便说一下,capistrano的日志在哪里?
由于Simone的建议添加了'捆绑exec',我设法完成了帽部署例程,因为一切顺利.然而,新问题是我的crontab文件仍然没有任务,并且没有使用其4个任务创建我的部分.
在我们的登台服务器上,我们在生产环境中运行Rails应用程序,以便尽可能与我们的生产服务器相似.我们正在使用何时创建我们的crontab.但是,我们需要为我们的站点地图生成运行稍微不同的rake任务,因此它不会ping Google和Bing.
在deploy.rb中,我们有:
set :stages, %w(production staging)
,但是在deploy/staging.rb和deploy/production.rb中我们都:rails_env, "production"
设置了,所以我无法使用Rails.env
.
在schedule.rb
,我想做的事情如下:
every :day, at: '1am' do
if @stage == 'production'
rake 'sitemap:refresh'
else
rake 'sitemap:refresh:no_ping'
end
end
Run Code Online (Sandbox Code Playgroud)
如何使该变量可用?
更新
我能够通过推杆解决它
set :whenever_variables, defer { "stage=#{stage}" }
进入我的deploy/staging.rb.然后我可以访问@stage
schedule.rb
我正在尝试通过rails项目创建我的第一个cron作业.运行时cap deploy
,我收到此错误:
...
* 2013-01-01 22:29:00 executing `whenever:update_crontab'
* executing "cd /var/www/vhosts/famnfo.com/releases/20130102042834 && bundle exec whenever --update-crontab FamNFo --set environment=production --roles db"
servers: ["famnfo.com"]
[famnfo.com] executing command
** [out :: famnfo.com] /var/www/vhosts/famnfo.com/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/core_ext/numeric/time.rb:49:in `days': wrong number of arguments (1 for 0) (ArgumentError)
** [out :: famnfo.com] from config/schedule.rb:23:in `initialize'
** [out :: famnfo.com] from /var/www/vhosts/famnfo.com/shared/bundle/ruby/1.9.1/gems/whenever-0.8.1/lib/whenever/job_list.rb:25:in `instance_eval'
** [out :: famnfo.com] from /var/www/vhosts/famnfo.com/shared/bundle/ruby/1.9.1/gems/whenever-0.8.1/lib/whenever/job_list.rb:25:in `initialize'
** [out :: famnfo.com] from /var/www/vhosts/famnfo.com/shared/bundle/ruby/1.9.1/gems/whenever-0.8.1/lib/whenever.rb:15:in `new'
** [out :: famnfo.com] from /var/www/vhosts/famnfo.com/shared/bundle/ruby/1.9.1/gems/whenever-0.8.1/lib/whenever.rb:15:in `cron'
** [out …
Run Code Online (Sandbox Code Playgroud) cron ruby-on-rails whenever ruby-on-rails-3 whenever-capistrano
我正在尝试部署一个随时使用的项目.
但得到:
sh: whenever: not found
rolling back
executing "rm -rf /var/www/rails_apps/portal/releases/20130627122943; true"
failed: "sh -c 'cd /var/www/rails_apps/portal/releases/20130627122943 && whenever --update-crontab iconnect_portal --set environment=production --roles db'" on ...
Run Code Online (Sandbox Code Playgroud)
gem 'whenever', :require => false
Run Code Online (Sandbox Code Playgroud)
require "bundler/capistrano"
require 'capistrano/ext/multistage'
require "whenever/capistrano"
require "delayed/recipes"
........
Run Code Online (Sandbox Code Playgroud)
问题出在哪儿?
如何运行cron job
从每天8:00 AM
到8:00 PM
20分钟时的间隔例如cron作业应在开始8:00 AM
每一天,然后在运行8:20 AM
,然后8:40 AM
再9:00 AM
达到8:00 PM
。谢谢。
编辑:如何使用 ruby whenever
gem实现它。