部署 Capistrano 部署网站错误

autumnwolf · 2013年11月06日 · 最后由 autumnwolf 回复于 2013年11月07日 · 3739 次阅读

部署网站的时候老有这个 rvm path 的问题

>cap deploy:cold   
    triggering load callbacks
  * 2013-11-06 17:44:09 executing `deploy'
    triggering before callbacks for `deploy'
  * 2013-11-06 17:44:09 executing `rvm:install_rvm'
  * executing "__LAST_STATUS=0; export CURL_HOME=\"${TMPDIR:-${HOME}}/.rvm-curl-config.$$\"; mkdir ${CURL_HOME}/; { [[ -r ${HOME}/.curlrc ]] && cat ${HOME}/.curlrc; echo \"silent\"; echo \"show-error\"; } > $CURL_HOME/.curlrc; curl -L https://get.rvm.io | bash -s stable --path $HOME/.rvm || __LAST_STATUS=$?; rm -rf $CURL_HOME; exit ${__LAST_STATUS}"
    servers: ["162.243.xx.187"]
    [162.243.xx.187] executing command
 ** [out :: 162.243.xx.187] Downloading RVM branch stable
 ** [out :: 162.243.xx.187] Downloading https://github.com/wayneeseguin/rvm/archive/stable.tar.gz to rvm-stable.tgz.
 ** [out :: 162.243.xx.187] 
 ** [out :: 162.243.xx.187] Upgrading the RVM installation in /home/william/.rvm/
 ** [out :: 162.243.xx.187]     RVM PATH line found in /home/william/.bashrc /home/william/.zshrc.
 ** [out :: 162.243.xx.187]     RVM sourci$1}$2ng line found in /home/william/.bash_profile /home/william/.zlogin.
 ** [out :: 162.243.xx.187] Upgrade of RVM in /home/william/.rvm/ is complete.
 ** [out :: 162.243.xx.187] 
 ** [out :: 162.243.xx.187] # william,
 ** [out :: 162.243.xx.187] #
 ** [out :: 162.243.xx.187] #   Thank you for using RVM!
 ** [out :: 162.243.xx.187] #   We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
 ** [out :: 162.243.xx.187] #
 ** [out :: 162.243.xx.187] # ~Wayne, Michal & team.
 ** [out :: 162.243.xx.187] 
 ** [out :: 162.243.xx.187] In case of problems: http://rvm.io/help
 ** [out :: 162.243.xx.187]        Help RVM 2.0: https://www.bountysource.com/fundraisers/489-rvm-2-0
 ** [out :: 162.243.xx.187] 
 ** [out :: 162.243.xx.187] Upgrade Notes:
 ** [out :: 162.243.xx.187] 
 ** [out :: 162.243.xx.187] * No new notes to display.
 ** [out :: 162.243.xx.187] 
    command finished in 3337ms
  * 2013-11-06 17:44:15 executing `rvm:install_ruby'
  * executing "__LAST_STATUS=0; export CURL_HOME=\"${TMPDIR:-${HOME}}/.rvm-curl-config.$$\"; mkdir ${CURL_HOME}/; { [[ -r ${HOME}/.curlrc ]] && cat ${HOME}/.curlrc; echo \"silent\"; echo \"show-error\"; } > $CURL_HOME/.curlrc; $HOME/.rvm/bin/rvm --autolibs=2 install ruby-2.0.0-p247 || __LAST_STATUS=$?; rm -rf $CURL_HOME; exit ${__LAST_STATUS}"
    servers: ["162.243.xx.187"]
    [162.243.xx.187] executing command
 ** [out :: 162.243.xx.187] Already installed ruby-2.0.0-p247.
 ** [out :: 162.243.xx.187] To reinstall use:
 ** [out :: 162.243.xx.187] 
 ** [out :: 162.243.xx.187] rvm reinstall ruby-2.0.0-p247
 ** [out :: 162.243.xx.187] 
    command finished in 1319ms
  * 2013-11-06 17:44:17 executing `rvm:create_alias'
  * executing "$HOME/.rvm/bin/rvm alias create clinic ruby-2.0.0-p247"
    servers: ["162.243.xx.187"]
    [162.243.xx.187] executing command
 ** [out :: 162.243.xx.187] Creating alias clinic for ruby-2.0.0-p247.
 ** [out :: 162.243.xx.187] Recording alias clinic for ruby-2.0.0-p247.
    command finished in 1461ms
  * 2013-11-06 17:44:18 executing `rvm:create_wrappers'
  * executing "$HOME/.rvm/bin/rvm wrapper ruby-2.0.0-p247 --no-prefix --all"
    servers: ["162.243.xx.187"]
    [162.243.xx.187] executing command
 ** [out :: 162.243.xx.187] Saving wrappers to '/home/william/.rvm/bin'.
 ** [out :: 162.243.xx.187] .
 ** [out :: 162.243.xx.187] .
 ** [out :: 162.243.xx.187] .
 ** [out :: 162.243.xx.187] .
 ** [out :: 162.243.xx.187] .
 ** [out :: 162.243.xx.187] .
 ** [out :: 162.243.xx.187] .
 ** [out :: 162.243.xx.187] .
 ** [out :: 162.243.xx.187] 
    command finished in 1793ms
  * 2013-11-06 17:44:20 executing `deploy:update'
 ** transaction: start
  * 2013-11-06 17:44:20 executing `deploy:update_code'
    updating the cached checkout on all servers
    executing locally: "git ls-remote [email protected]:whu/clinic.git master"
    command finished in 4283ms
  * executing "if [ -d /home/william/apps/clinic/shared/cached-copy ]; then cd /home/william/apps/clinic/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard 030b85f1e20508d615d940cb75749604644a1d37 && git clean -q -d -x -f; else git clone -q -b master [email protected]:whu/clinic.git /home/william/apps/clinic/shared/cached-copy && cd /home/william/apps/clinic/shared/cached-copy && git checkout -q -b deploy 030b85f1e20508d615d940cb75749604644a1d37; fi"
    servers: ["162.243.xx.187"]
    [162.243.xx.187] executing command
    command finished in 3391ms
    copying the cached version to /home/william/apps/clinic/releases/20131106094427
  * executing "cp -RPp /home/william/apps/clinic/shared/cached-copy /home/william/apps/clinic/releases/20131106094427 && (echo 030b85f1e20508d615d940cb75749604644a1d37 > /home/william/apps/clinic/releases/20131106094427/REVISION)"
    servers: ["162.243.xx.187"]
    [162.243.xx.187] executing command
    command finished in 1376ms
  * 2013-11-06 17:44:29 executing `deploy:finalize_update'
    triggering before callbacks for `deploy:finalize_update'
  * 2013-11-06 17:44:29 executing `bundle:install'
  * executing "cd /home/william/apps/clinic/releases/20131106094427 && bundle install --gemfile /home/william/apps/clinic/releases/20131106094427/Gemfile --path /home/william/apps/clinic/shared/bundle --deployment --quiet --without development test"
    servers: ["162.243.xx.187"]
    [162.243.xx.187] executing command
 ** [out :: 162.243.xx.187] You are trying to install in deployment mode after changing
 ** [out :: 162.243.xx.187] your Gemfile. Run `bundle install` elsewhere and add the
 ** [out :: 162.243.xx.187] updated Gemfile.lock to version control.
 ** [out :: 162.243.xx.187] 
 ** [out :: 162.243.xx.187] You have added to the Gemfile:
 ** [out :: 162.243.xx.187] * therubyracer
 ** [out :: 162.243.xx.187] * rvm-capistrano
    command finished in 1627ms
*** [deploy:update_code] rolling back
  * executing "rm -rf /home/william/apps/clinic/releases/20131106094427; true"
    servers: ["162.243.xx.187"]
    [162.243.xx.187] executing command
    command finished in 1287ms
failed: "rvm_path=$HOME/.rvm $HOME/.rvm/bin/rvm-shell 'ruby-2.0.0-p247' -c 'cd /home/william/apps/clinic/releases/20131106094427 && bundle install --gemfile /home/william/apps/clinic/releases/20131106094427/Gemfile --path /home/william/apps/clinic/shared/bundle --deployment --quiet --without development test'" on 162.243.xx.187

但是我看这句 executing "rm -rf /home/william/apps/xxx/releases/20131106094427; true" 已经删除了 20131106094427 是不是 cd /home/william/apps/xxx/releases/20131106094427 这句发生了错误呢?

新手求指点!!

PS: deploy.rb

require "bundler/capistrano"
require "rvm/capistrano"
require "rvm/capistrano/alias_and_wrapp"
require 'capistrano-unicorn'
require "capistrano-file_db"
load 'deploy/assets'

set :scm, :git 
set :branch, "master"
set :repository,  "[email protected]:xxx/xxx.git"
#set :keep_releases, 5

set :application, "clinic"
set :user, "william"
set :port, 22
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :rails_env, "production"
set :normalize_asset_timestamps, false #for Solve the probem: Not precomplie assets

role :web, "xxx.xxx.xxx.xxx"                          # Your HTTP server, Apache/etc
role :app, "xxx.xxx.xxx.xxx"                          # This may be the same as your `Web` server
role :db,  "xxx.xxx.xxx.xxx", :primary => true # This is where Rails migrations will run

set :rvm_ruby_string, :local
set :unicorn_pid, "#{shared_path}/pids/unicorn.pid"

default_run_options[:pty] = true
ssh_options[:forward_agent] = true

before 'deploy:restart', 'deploy:migrate'
before 'deploy',         'rvm:install_rvm'
before 'deploy',         'rvm:install_ruby'
before 'deploy',         'rvm:create_alias'
before 'deploy',         'rvm:create_wrappers'
after  'deploy',         'deploy:cleanup'

我的解决方法是将服务器环境从 rvm 换到 rbenv,然后问题就没有了……

日志要看再前一点位置的。

#2 楼 @Rei 嗯 全贴出来了

#3 楼 @autumnwolf

** [out :: 162.243.xx.187] You are trying to install in deployment mode after changing
** [out :: 162.243.xx.187] your Gemfile. Run `bundle install` elsewhere and add the
** [out :: 162.243.xx.187] updated Gemfile.lock to version control.
** [out :: 162.243.xx.187] 
** [out :: 162.243.xx.187] You have added to the Gemfile:
** [out :: 162.243.xx.187] * therubyracer
** [out :: 162.243.xx.187] * rvm-capistrano

这段已经提示你怎么做了吧,照着做应该能解决问题。

#4 楼 @chunlea 你好 谢谢!我删除了 Gemfile.lock 重新 bundle install 了下。然后发现说 dvm 的路径不对然后 set :rvm_bin_path, "$HOME/.rvm/bin" 设置了下路径: 现在的问题是:

command finished in 1053ms
failed: "rvm_path=/usr/local/rvm $HOME/.rvm/bin/rvm-shell 'ruby-2.0.0-p247' -c 'cd -- /home/william/apps/clinic/releases/20131106141509 && RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile'"

可能服务器上不能编译 assets 吧,可以安装 nodejs,或者使用 therubyracer

#6 楼 @zhangyuan 现在问题好奇怪 服务器上我安装了 ruby-2.0.0-p247,但是 cap deploy:cold 时候还是提示这个错误

   [162.243.45.187] executing command
** [out :: 162.243.45.187] ruby-2.0.0-p247 is not installed.
** [out :: 162.243.45.187] To install do: 'rvm install ruby-2.0.0-p247'
** [out :: 162.243.45.187] Error: RVM was unable to use 'ruby-2.0.0-p247'

#7 楼 @autumnwolf sorry. 没有在服务器上使用过 rvm……

#8 楼 @zhangyuan 这个问题搞定了,启动 unicorn 的时候,这个权限是怎么给呢 我的用户给了 root 权限。然后 deploy

/home/william/apps/clinic/shared/bundle/ruby/2.0.0/gems/unicorn-4.7.0/lib/unicorn/socket_helper.rb:149:in `unlink': Operation not permitted - /tmp/unicorn.clinic.sock (Errno::EPERM)

话说部署一个 rails 这么费劲的...

#9 楼 @autumnwolf 我没有使用过 root 用户部署。都是用普通用户的。

capistrano 脚本设置

set :use_sudo, false

#10 楼 @zhangyuan 我也是用的普通用户。。。依旧是这个错误

仍旧挣扎中,目前的情况是放在 root 用户下可以访问首页,只是没有样式,nginx 的日志:

2013/11/07 05:30:49 [error] 23376#0: *58 open() "/home/root/apps/clinic/current/public/assets/application.js.gz" failed (13: Permission denied), client: 124.93.197.4, server: domain.com, request: "GET /assets/application.js HTTP/1.1", host: "domain.com", referrer: "http://domain.com/"
2013/11/07 05:30:49 [error] 23376#0: *58 open() "/home/root/apps/clinic/current/public/assets/application.js" failed (13: Permission denied), client: 124.93.197.4, server: domain.com, request: "GET /assets/application.js HTTP/1.1", host: "domain.com", referrer: "http://domaincom/"

这个关了吧。nginx 里面改成运行网站的用户就解决了问题。只是想说这个好耗费时间。

第一次先 cp 上去玩玩。

#14 楼 @smallX 是啊 折腾了这两天也算是入门了

需要 登录 后方可回复, 如果你还没有账号请 注册新账号