2011-05-16 145 views
4

一直在與Capistrano玩耍,以獲得我的服務器和我的開發機器之間的自動部署。除了Capistrano似乎無法使用bundle exec命令啓動我的服務器外,我幾乎已經配置了它。我總是收到以下錯誤:Capistrano部署瘦服務器

編輯:配置文件現在居住在/var/www/apps/current/thin.yml

 
... 
    * executing "sudo -p 'sudo password: ' bundle exec thin start -C /var/www/thin.config.yml" 
    servers: ["85.255.206.157"] 
    [85.255.206.157] executing command 
** [out :: 85.255.206.157] Could not locate Gemfile 
    command finished in 216ms 
failed: "sh -c 'sudo -p '\\''sudo password: '\\'' bundle exec thin start -C /var/www/thin.config.yml'" on 85.255.206.157 

只有複製的最後一節與自己相關。整個文件的複製等工作正常。這只是啓動似乎失敗的集羣。 這裏是處理所有Capistrano的東西我deploy.rb文件:

編輯:該文件已被修改爲如下:

require "bundler/capistrano" 

# define the application and Version Control settings 
set :application, "ESCO Matching Demo" 
set :repository, "svn://192.168.33.70/RubyOnRails/ESCO" 
set :deploy_via, :copy 

# Set the login credentials for Capistrano 
set :user, "kurt" 

# Tell Capistrano where to deploy 
set :deploy_to, "/var/www/apps" 

# Tell Capistrano the servers it can play with 
server "85.255.206.157", :app, :web, :db, :primary => true 

# Generate an additional task to fire up the thin clusters 
namespace :deploy do 
    desc "Start the Thin processes" 
    task :start do 
    sudo "bundle exec thin start -C thin.yml" 
    end 

    desc "Stop the Thin processes" 
    task :stop do 
    sudo "bundle exec thin stop -C thin.yml" 
    end 

    desc "Restart the Thin processes" 
    task :restart do 
    sudo "bundle exec thin restart -C thin.yml" 
    end 

    desc "Create a symlink from the public/cvs folder to the shared/system/cvs folder" 
    task :update_cv_assets, :except => {:no_release => true} do 
    run "ln -s #{shared_path}/cvs #{latest_release}/public/cvs" 
    end 
end 

# Define all the tasks that need to be running manually after Capistrano is finished. 
after "deploy:finalize_update", "deploy:update_cv_assets" 
after "deploy", "deploy:migrate" 

編輯:這是我thin.yml文件

--- 
pid: tmp/pids/thin.pid 
address: 0.0.0.0 
timeout: 30 
wait: 30 
port: 4000 
log: log/thin.log 
max_conns: 1024 
require: [] 

environment: production 
max_persistent_conns: 512 
server: 4 
daemonize: true 
chdir: /var/www/apps/current 

編輯:現在 以下問題發生:

  1. 我收到了找不到的Gemfile錯誤從我的系統上的最後一個步驟運行帽部署命令時:

  2. 遷移不進行服務器的啓動

  3. 我可以」 t似乎已經手動啓動羣集了。只有一個瘦身實例正在啓動。

UPDATE: 這裏是我部署到服務器上的寶石ENV設置。該信息是通過使用帽殼,然後運行命令獲得:

 
==================================================================== 
Welcome to the interactive Capistrano shell! This is an experimental 
feature, and is liable to change in future releases. Type 'help' for 
a summary of how to use the shell. 
-------------------------------------------------------------------- 
cap> echo $PATH 
[establishing connection(s) to 85.255.206.157] 
Password: 
** [out :: 85.255.206.157] /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games 
cap> gem env 
** [out :: 85.255.206.157] RubyGems Environment: 
** [out :: 85.255.206.157] - RUBYGEMS VERSION: 1.3.6 
** [out :: 85.255.206.157] - RUBY VERSION: 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux] 
** [out :: 85.255.206.157] - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8 
** [out :: 85.255.206.157] - RUBY EXECUTABLE: /usr/bin/ruby1.8 
** [out :: 85.255.206.157] - EXECUTABLE DIRECTORY: /usr/bin 
** [out :: 85.255.206.157] - RUBYGEMS PLATFORMS: 
** [out :: 85.255.206.157] - ruby 
** [out :: 85.255.206.157] - x86_64-linux 
** [out :: 85.255.206.157] - GEM PATHS: 
** [out :: 85.255.206.157] - /usr/lib/ruby/gems/1.8 
** [out :: 85.255.206.157] - /home/kurt/.gem/ruby/1.8 
** [out :: 85.255.206.157] - GEM CONFIGURATION: 
** [out :: 85.255.206.157] - :update_sources => true 
** [out :: 85.255.206.157] - :verbose => true 
** [out :: 85.255.206.157] - :benchmark => false 
** [out :: 85.255.206.157] - :backtrace => false 
** [out :: 85.255.206.157] - :bulk_threshold => 1000 
** [out :: 85.255.206.157] - REMOTE SOURCES: 
** [out :: 85.255.206.157] - http://rubygems.org/ 

回答

10

終於解決了問題... 首先,以獲得捆綁應用程序與服務器environemnt發揮很好,下面的腳本做什麼它應該做的事情:

require "bundler/capistrano" 
default_run_options[:pty] = true 

# define the application and Version Control settings 
set :application, "ESCO Matching Demo" 
set :repository, "svn://192.168.33.70/RubyOnRails/ESCO" 
set :deploy_via, :copy 
set :user, "kurt" 
set :deploy_to, "/var/www/apps" 

# Tell Capistrano the servers it can play with 

server "85.255.206.157", :app, :web, :db, :primary => true 

# Generate an additional task to fire up the thin clusters 
namespace :deploy do 
    desc "Start the Thin processes" 
    task :start do 
    run <<-CMD 
     cd /var/www/apps/current; bundle exec thin start -C config/thin.yml 
    CMD 
    end 

    desc "Stop the Thin processes" 
    task :stop do 
    run <<-CMD 
     cd /var/www/apps/current; bundle exec thin stop -C config/thin.yml 
    CMD 
    end 

    desc "Restart the Thin processes" 
    task :restart do 
    run <<-CMD 
     cd /var/www/apps/current; bundle exec thin restart -C config/thin.yml 
    CMD 
    end 

    desc "Create a symlink from the public/cvs folder to the shared/system/cvs folder" 
    task :update_cv_assets, :except => {:no_release => true} do 
    run <<-CMD 
     ln -s /var/www/shared/cvs /var/www/apps/current/public 
    CMD 
    end 
end 

# Define all the tasks that need to be running manually after Capistrano is finished. 
after "deploy:finalize_update", "deploy:update_cv_assets" 
after "deploy", "deploy:migrate" 

該腳本可以瀏覽很好地進入所需的部署結構並執行控制精簡進程所需的命令。 問題在於,當以sudo方式運行這些命令時,cd命令沒有完成。這背後的原因是cv只存在於shell中,並不是sudo的已知命令。

第二個問題是瘦配置。由於thin.yml中有一個小型服務器,因此瘦服務器無法啓動。下面的腳本啓動了一個運行在端口4000 - > 4003上的4個瘦服務器集羣。

--- 
pid: tmp/pids/thin.pid 
address: 0.0.0.0 
timeout: 30 
wait: 30 
port: 4000 
log: log/thin.log 
max_conns: 1024 
require: [] 

environment: production 
max_persistent_conns: 512 
servers: 4 
daemonize: true 
chdir: /var/www/apps/current 
+4

也許它的確定只是做這樣的'運行「CD#{的current_path} &&捆綁高管薄啓動-C薄.yml「' – Shtirlic 2012-02-21 13:20:00

+0

可以讓它在下一個項目上旋轉,可能會使命令更具可讀性。 – 2012-02-21 13:40:39

-2

曼,找出是GEM_HOME或GEM_PATH指向。必須是它。

+0

沒有這些變量的定義變量系統 – 2011-05-19 06:47:50

+0

上定義,但仍然遇到了同樣的問題 – 2011-05-24 06:47:55