如何从mina部署脚本运行自定义rake任务

时间:2013-12-10 06:40:16

标签: ruby-on-rails-3 mina

我正在使用mina来部署我的应用程序。我指定了我想部署应用程序的env(登台/制作)。

mina deploy on=staging --verbose

我已将deploy.rb中的app env保存为

app_env = ENV['on'] || 'staging'

我有一个需要生产数据库备份的rake任务。截至目前,我在我的控制台上明确地运行了rake任务

bundle exec rake deploy:backup_prod_db --trace

我想在每个生产部署上运行该任务。我该怎么做?

2 个答案:

答案 0 :(得分:1)

mina有特殊的语法。从mina控制台帮助页面:

Server tasks:
  ...
  mina rails[arguments]   # Execute a Rails command in the current deploy
  mina rake[arguments]    # Execute a Rake command in the current deploy
  mina run[command]       # Runs a command in the server
  ...

所以从命令行:

$ mina 'rake[deploy:backup_db]'

或者在mina deploy配置文件(config/deploy.rb)中定义任务:

task :backup_db do
  invoke :'rake[deploy:backup_db]'
end

答案 1 :(得分:0)

让它运转起来。变化是

...
app_env = ENV['on'] || 'staging'
...

desc "Deploys the current version to the server."
task :deploy => :environment do
  deploy do
    # Put things that will set up an empty directory into a fully set-up
    # instance of your project.
    invoke 'production_backup' if app_env == 'production'
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    invoke :'rails:assets_precompile'

    to :launch do
      invoke 'application:restart'
    end
  end
end

task :production_backup do
  queue "cd #{deploy_to}/current ; bundle exec rake deploy:backup_db"
end