部署 使用 mina deploy 更新 crontab 遇到的一个问题

dddd1919 · July 03, 2014 · Last by huobazi replied at July 05, 2014 · 3790 hits

whenever写定时任务,每次部署完后会执行 whenever --update-crontab .... 但是由于 mina 部署的目录结构,current 是直接软链接到 releases/xx/ 目录下的,whenever的任务更新又是按照工程的绝对路径来识别的,结果实际更新的是releases/xx/下的任务,而不是current下的,crontab并没更新老任务,而是新建了一套任务,老的任务还在。 想问下使用mina部署的同学们有没有什么解决方法?我想过的方法就是能不能把releases/xx硬拷贝到current目录下?

不 require whenever 自带的代码,用以下代码,并且在 deploy 的时候设置一个 whenever 的唯一标记 在这里就是 app_name。

set :app_name, "app.domain.com"


namespace :whenever do
  desc "Clear crontab"
  task :clear do
    queue %{
      echo "-----> Clear crontab for #{app_name}"
      #{echo_cmd %[cd #{deploy_to!}/#{current_path!} ; bundle exec whenever --clear-crontab #{app_name} --set 'environment=production&path=#{deploy_to!}/#{current_path!}']}
    }
  end
  desc "Update crontab"
  task :update do
    queue %{
      echo "-----> Update crontab for #{app_name}"
      #{echo_cmd %[cd #{deploy_to!}/#{current_path!} ; bundle exec whenever --update-crontab #{app_name} --set 'environment=production&path=#{deploy_to!}/#{current_path!}']}
    }
  end
  desc "Write crontab"
  task :write do
    queue %{
      echo "-----> Update crontab for #{app_name}"
      #{echo_cmd %[cd #{deploy_to!}/#{current_path!} ; bundle exec whenever --write-crontab #{app_name} --set 'environment=production&path=#{deploy_to!}/#{current_path!}']}
    }
  end
end


task :deploy do
   deploy do
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    invoke :'rails:db_migrate'
    invoke :'rails:assets_precompile'

    to :launch do
      #.... ignore codes....
      invoke :'whenever:update'  if ENV['to'] == "production"
    end
  end
end

#1 楼 @yakjuly 非常感谢!解决

我用

invoke :'whenever:update'

没问题啊

see http://nadarei.co/mina/docs/lib/mina/whenever.html

require 'mina/whenever'

invoke :'whenever:update'

cool

You need to Sign in before reply, if you don't have an account, please Sign up first.