Capistrano使用瘦服务器进行部署

时间:2011-05-16 14:03:54

标签: ruby-on-rails deployment capistrano bundler thin

一直在玩Capistrano以在我的服务器和我的开发机器之间进行自动部署。我几乎已经配置了,除了Capistrano似乎无法使用bundle exec命令启动我的服务器。我总是收到以下错误:

编辑:配置文件现在位于/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

仅复制了相关的最后一部分。整个文件等的复制工作正常。它只是启动似乎失败的集群。 这是我的deploy.rb文件,它处理所有Capistrano的东西:

编辑:文件已修改为以下内容:

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. 我在最后一步从系统运行cap deploy命令时收到无法找到GemFile错误:启动服务器

  2. 未执行迁移

  3. 我似乎无法再手动启动集群。只有一个瘦身实例正在启动。

  4. 更新: 这是我正在部署的服务器的gem env设置。此信息是通过使用cap shell然后运行命令获得的:

    ====================================================================
    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/
    

2 个答案:

答案 0 :(得分:10)

终于解决了问题...... 首先,为了让bundle应用程序与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"

此脚本可以很好地导航到所需的部署结构,并执行控制Thin进程所需的命令。 问题是当将这些命令作为sudo运行时,cd命令没有完成。这背后的原因是cv只存在于shell中,并且不是sudo的已知命令。

第二个问题是瘦配置。因为thin.yml上有一个小类型,所以瘦服务器无法启动。下面的脚本将启动在端口4000上运行的4个瘦服务器集群 - &gt; 4003。

---
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

答案 1 :(得分:-2)

男人,找出GEM_HOME或GEM_PATH指向的位置。一定是它。