使用Capistrano部署Thin服务器

4
我一直在使用Capistrano尝试自动化部署我的服务器和开发机之间的流程。我已经几乎配置好了,但是Capistrano似乎无法使用bundle exec命令启动我的服务器。我一直收到以下错误信息:
...
  * 执行 "sudo -p 'sudo password: ' bundle exec thin start -C /var/www/thin.config.yml"
    服务器: ["85.255.206.157"]
    [85.255.206.157] 正在执行命令
 ** [out :: 85.255.206.157] Could not locate Gemfile
    命令在 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. 当在我的系统上运行cap deploy命令时,在服务器启动的最后一步时,我收到了Cannot find GemFile错误。

  2. 迁移未执行

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

更新: 以下是我要部署到的服务器上的gem env设置。通过使用cap shell并运行以下命令获取此信息:

====================================================================
欢迎使用Capistrano交互式shell!这是一个实验性功能,可能会在未来的版本中发生变化。输入“help”以获取如何使用shell的摘要。
--------------------------------------------------------------------
cap> echo $PATH
[正在连接85.255.206.157]
密码: 
 ** [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环境:
 ** [out :: 85.255.206.157] - RUBYGEMS版本:1.3.6
 ** [out :: 85.255.206.157] - RUBY版本:1.8.7(2010-01-10修订版249)[x86_64-linux]
 ** [out :: 85.255.206.157] - 安装目录:/usr/lib/ruby/gems/1.8
 ** [out :: 85.255.206.157] - RUBY可执行文件:/usr/bin/ruby1.8
 ** [out :: 85.255.206.157] - 可执行文件目录:/usr/bin
 ** [out :: 85.255.206.157] - RUBYGEMS平台:
 ** [out :: 85.255.206.157] - ruby
 ** [out :: 85.255.206.157] - x86_64-linux
 ** [out :: 85.255.206.157] - GEM路径:
 ** [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配置:
 ** [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] - 远程来源:
 ** [out :: 85.255.206.157] - http://rubygems.org/
2个回答

10

问题终于解决了... 首先,为了使捆绑应用程序与环境服务器良好协作,下面的脚本执行了它应该执行的操作:

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命令未能执行。原因是cd只存在于shell中,而不是sudo所知道的命令。

第二个问题出在thin配置上。由于thin.yml文件中有一个小错误,所以thin服务器无法启动。下面的脚本将启动一个由4个thin服务器组成的集群,这些服务器在端口4000到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

4
也许这样做没问题,运行以下命令:"cd #{current_path} && bundle exec thin start -C thin.yml" - Shtirlic
可以在下一个项目中试一试,这可能会使命令更易读。 - codingbunny

-2

找出 GEM_HOME 或 GEM_PATH 指向的位置,一定是这个问题。


已经定义了变量,但仍然遇到相同的问题。 - codingbunny

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接