2009-06-08 68 views
4

我有一套rake任務,我需要在某個時候調用capistrano。埃德溫Goei的blog建議通過「sh」炮擊capistrano。有沒有更好的方法從耙內運行一個capistrano任務?

有沒有更簡單的方法?看起來你應該能夠以編程方式調用適當的任務。提前致謝。

+1

我得知使用的「系統」,優選在我的情況下,通過「sh」的返回非零退出代碼「sh」的使耙「系統」允許它繼續時立即退出。 – 2009-06-09 05:37:06

回答

7

是的,Capistrano可以通過編程訪問命令行組件。但是,如果你想從耙子任務中調用它們,你需要做一些額外的工作。 (:外殼,假)停止Capistrano的正在運行的任務在子SH-殼

task :deploy 
    require 'rubygems' 
    require 'capistrano' 
    require 'capistrano/cli' 

    parameters = ["deploy"] # this is an array of the strings that come after 
          # cap on the command line. e.g., 
          # ["deploy", "-S", "revision=1024"] gives you local var 
          # revision in your deploy.rb. 

    # The following is required ONLY when you run Capistrano 2+ from Rake, 
    # because Rake adds the methods from FileUtils to Object. FileUtils includes 
    # a method called symlink which interferes with Capistrano's symlink task. 
    Capistrano::Configuration::Namespaces::Namespace.class_eval { undef :symlink } 

    Capistrano::CLI.parse(parameters).execute! 
end 
+0

請注意我上面有關「sh」和「system」的評論。似乎capistrano通過「sh」在遠程服務器上執行我的命令,並且非零返回值導致我的rake任務比我想要的更早退出。 我的情況是否有任何程序化決議? 謝謝你的幫助;我已經提前將這個問題標記爲答案,因爲我認爲我的特例是一個邊緣案例。 – 2009-06-09 05:52:04

-1

喬納森,你的里程可能通過做類似設置不同而不同。

只是一個想法,如果你需要一隻手,請隨時ping我。

3

對於Capistrano的3:

http://capistranorb.com/documentation/advanced-features/capistrano-pure-ruby/

require 'capistrano/all' 

    stages = "production" 
    set :application, 'my_app_name' 
    set :repo_url, '[email protected]:capistrano/capistrano.git' 
    set :deploy_to, '/var/www/' 
    set :stage, :production 
    role :app, %w{} 

    require 'capistrano/setup' 
    require 'capistrano/deploy' 
    Dir.glob('capistrano/tasks/*.cap').each { |r| import r } 

    Capistrano::Application.invoke("production") 
    Capistrano::Application.invoke("deploy")