Capistrano 无法部署到远程服务器
解决方案
解决方案是将以下内容添加到 production.rb 的顶部:
$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Add RVM's lib directory to the load path.
require "rvm/capistrano" # Load RVM's capistrano plugin.
set :rvm_ruby_string, '1.9.2@rails31dataserver' # Or whatever env you want it to run in.
set :rvm_bin_path, '/usr/local/rvm/bin'
我之前缺少的部分是 set :rvm_bin_path, '/usr/local/rvm/bin'
因为我以前从未在 Capistrano 部署中使用过该配置设置,而且我已经做了一些。哦,好吧,一天的工作。感谢 irc.freenode.net 上 #rvm 频道的 tonyflint!
原始帖子
悬崖笔记
- 的 RVM 的系统安装,
- 我正在运行通过 Capistrano 部署
目前我很困惑。基本上发生的事情是我试图通过 Capistrano 进行部署,但失败了,很难。这是我的 deploy.rb 和 production.rb 文件的粘贴(我正在做一个多阶段环境并省略 staging.rb 文件,因为它工作正常)。 http://pastie.org/2523675
以下是 cap production deploy:setup
:
$ cap production deploy:setup
* executing `production'
triggering start callbacks for `deploy:setup'
* executing `multistage:ensure'
* executing `deploy:setup'
* executing "sudo -p 'sudo password: ' mkdir -p /var/www/html/dataserver /var/www/html/dataserver/releases /var/www/html/dataserver/shared /var/www/html/dataserver/shared/system /var/www/html/dataserver/shared/log /var/www/html/dataserver/shared/pids"
servers: ["omitted"]
Password:
[omitted] executing command
*** [err :: omitted] sudo
*** [err :: omitted] :
*** [err :: omitted] sorry, you must have a tty to run sudo
*** [err :: omitted]
command finished in 60ms
failed: "sh -c 'sudo -p '\\''sudo password: '\\'' mkdir -p /var/www/html/dataserver /var/www/html/dataserver/releases /var/www/html/dataserver/shared /var/www/html/dataserver/shared/system /var/www/html/dataserver/shared/log /var/www/html/dataserver/shared/pids'" on omitted
现在,我明白为什么会发生这种情况了。我正在远程尝试使用 sudo,但这是安全禁忌。因此,这意味着我需要使用 default_run_options[:pty] = true
。因此,我取消注释并再次运行 cap production deploy:setup
,一切都运行得很好。部署的目录结构获取设置和所有内容。惊人的。现在,我尝试运行 cap production deploy
,输出如下:
$ cap production deploy
* executing `production'
triggering start callbacks for `deploy'
* executing `multistage:ensure'
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "hg log -r default --template '{node|short}'"
command finished in 52ms
* executing "if [ -d /var/www/html/dataserver/shared/cached-copy ]; then hg pull --repository /var/www/html/dataserver/shared/cached-copy https://cowfish.unh.edu/hg/DataServerApp && hg update --repository /var/www/html/dataserver/shared/cached-copy --clean 6979cec4fc00; else hg clone --noupdate https://cowfish.unh.edu/hg/DataServerApp /var/www/html/dataserver/shared/cached-copy && hg update --repository /var/www/html/dataserver/shared/cached-copy --clean 6979cec4fc00; fi"
servers: ["omitted"]
Password:
[omitted] executing command
** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
** [omitted :: out] http authorization required
** [omitted :: out] realm: Mercurial Project Repository
** [omitted :: out] user:
** [omitted :: out] d
** [omitted :: out] e
** [omitted :: out] p
** [omitted :: out] l
** [omitted :: out] o
** [omitted :: out] y
** [omitted :: out]
** [omitted :: out] password:
** [omitted :: out]
** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
** [omitted :: out] requesting all changes
** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
** [omitted :: out] adding changesets
** [omitted :: out] adding manifests
** adding file changes
** [omitted :: out] added 11 changesets with 187 changes to 125 files
** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
** [omitted :: out] 114 files updated, 0 files merged, 0 files removed, 0 files unresolved
command finished in 1332ms
copying the cached version to /var/www/html/dataserver/releases/20110912233835
* executing "cp -RPp /var/www/html/dataserver/shared/cached-copy /var/www/html/dataserver/releases/20110912233835 && (echo 6979cec4fc00 > /var/www/html/dataserver/releases/20110912233835/REVISION)"
servers: ["omitted"]
[omitted] executing command
command finished in 23ms
* executing `deploy:finalize_update'
* executing "chmod -R g+w /var/www/html/dataserver/releases/20110912233835"
servers: ["omitted"]
[omitted] executing command
command finished in 7ms
* executing "rm -rf /var/www/html/dataserver/releases/20110912233835/log /var/www/html/dataserver/releases/20110912233835/public/system /var/www/html/dataserver/releases/20110912233835/tmp/pids &&\\\n mkdir -p /var/www/html/dataserver/releases/20110912233835/public &&\\\n mkdir -p /var/www/html/dataserver/releases/20110912233835/tmp &&\\\n ln -s /var/www/html/dataserver/shared/log /var/www/html/dataserver/releases/20110912233835/log &&\\\n ln -s /var/www/html/dataserver/shared/system /var/www/html/dataserver/releases/20110912233835/public/system &&\\\n ln -s /var/www/html/dataserver/shared/pids /var/www/html/dataserver/releases/20110912233835/tmp/pids"
servers: ["omitted"]
[omitted] executing command
command finished in 8ms
* executing "find /var/www/html/dataserver/releases/20110912233835/public/images /var/www/html/dataserver/releases/20110912233835/public/stylesheets /var/www/html/dataserver/releases/20110912233835/public/javascripts -exec touch -t 201109122338.35 {} ';'; true"
servers: ["omitted"]
[omitted] executing command
** [out :: omitted] find: /var/www/html/dataserver/releases/20110912233835/public/images: No such file or directory
** [out :: omitted] find: /var/www/html/dataserver/releases/20110912233835/public/stylesheets: No such file or directory
** [out :: omitted] find: /var/www/html/dataserver/releases/20110912233835/public/javascripts: No such file or directory
command finished in 6ms
* executing `deploy:symlink'
* executing "rm -f /var/www/html/dataserver/current && ln -s /var/www/html/dataserver/releases/20110912233835 /var/www/html/dataserver/current"
servers: ["omitted"]
[omitted] executing command
command finished in 6ms
** transaction: commit
* executing `deploy:restart'
* executing "sudo -p 'sudo password: ' touch /var/www/html/dataserver/current/tmp/restart.txt"
servers: ["omitted"]
[omitted] executing command
command finished in 10ms
triggering after callbacks for `deploy'
* executing `deploy:migrate'
triggering before callbacks for `deploy:migrate'
* executing `sqlite3:link_configuration_file'
* executing "ln -nsf /var/www/html/dataserver/shared/sqlite_config.yml /var/www/html/dataserver/releases/20110912233835/config/database.yml"
servers: ["omitted"]
[omitted] executing command
command finished in 6ms
* executing "cd /var/www/html/dataserver/releases/20110912233835 && rake RAILS_ENV=production db:migrate"
servers: ["omitted"]
[omitted] executing command
** [out :: omitted] sh: rake: command not found
command finished in 5ms
failed: "sh -c 'cd /var/www/html/dataserver/releases/20110912233835 && rake RAILS_ENV=production db:migrate'" on omitted
因此,无论它加载什么环境,都无法看到 rake
。要查看我创建的部署任务的路径中加载的内容,输出如下:
$ cap production test_path
* executing `production'
triggering start callbacks for `test_path'
* executing `multistage:ensure'
* executing `test_path'
* executing "echo $PATH"
servers: ["omitted"]
Password:
[omitted] executing command
** [out :: omitted] /usr/local/bin:/bin:/usr/bin
command finished in 11ms
* executing "echo $rvm_path"
servers: ["omitted"]
[omitted] executing command
** [out :: omitted]
command finished in 5ms
现在您会注意到该路径肯定不正确。对于建立会话的用户,它应该是以下内容:
/usr/local/rvm/gems/ruby-1.9.2-p290@rails31dataserver/bin:/usr/local/rvm/gems/ruby-1.9.2-p290@global/bin:/usr/local/rvm/rubies/ruby-1.9.2-p290/bin:/usr/local/rvm/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/lpeabody/bin
再次,我明白为什么这不起作用。这是因为自从我运行 default_run_options[:pty] = true
我的环境就被加载了,至少这是我目前的理论。所以,毕竟,我得出了结论 - 我需要以某种方式加载我的环境,以便 rake 可以在不远程启用 sudo 的情况下运行。
现在,我知道我不是唯一的人曾经需要这样做,所以任何指示或提示将不胜感激。我已经绞尽脑汁花了 8 个小时的大部分时间,我需要尽快部署这个应用程序。
SOLUTION
The solution was to add the following to the top of production.rb:
$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Add RVM's lib directory to the load path.
require "rvm/capistrano" # Load RVM's capistrano plugin.
set :rvm_ruby_string, '1.9.2@rails31dataserver' # Or whatever env you want it to run in.
set :rvm_bin_path, '/usr/local/rvm/bin'
The part I was missing before was set :rvm_bin_path, '/usr/local/rvm/bin'
as I've never used that configuration setting in a Capistrano deployment before, and I've done a few. Oh well, all in a days work. Credit goes to tonyflint in the #rvm channel on irc.freenode.net!
Original Post
Cliff notes
- I'm running a system install of RVM
- I'm deploying via Capistrano
I'm currently dumbfounded. Basically what's happening is I'm trying to do a deployment via Capistrano and it's failing, hard. Here's the pastie of my deploy.rb and production.rb files (I'm doing a multi-stage environment and omitting the staging.rb file as that's working fine). http://pastie.org/2523675
Here is the output of cap production deploy:setup
:
$ cap production deploy:setup
* executing `production'
triggering start callbacks for `deploy:setup'
* executing `multistage:ensure'
* executing `deploy:setup'
* executing "sudo -p 'sudo password: ' mkdir -p /var/www/html/dataserver /var/www/html/dataserver/releases /var/www/html/dataserver/shared /var/www/html/dataserver/shared/system /var/www/html/dataserver/shared/log /var/www/html/dataserver/shared/pids"
servers: ["omitted"]
Password:
[omitted] executing command
*** [err :: omitted] sudo
*** [err :: omitted] :
*** [err :: omitted] sorry, you must have a tty to run sudo
*** [err :: omitted]
command finished in 60ms
failed: "sh -c 'sudo -p '\\''sudo password: '\\'' mkdir -p /var/www/html/dataserver /var/www/html/dataserver/releases /var/www/html/dataserver/shared /var/www/html/dataserver/shared/system /var/www/html/dataserver/shared/log /var/www/html/dataserver/shared/pids'" on omitted
Now, I get why this is happening. I'm remotely trying to use sudo and that's a security no-no. So, that means I need to use default_run_options[:pty] = true
. So I uncomment it and run cap production deploy:setup
again and all runs nice and dandy. The directory structure for the deployment get's setup and everything. Awesome. Now I try to run cap production deploy
and here's the output:
$ cap production deploy
* executing `production'
triggering start callbacks for `deploy'
* executing `multistage:ensure'
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "hg log -r default --template '{node|short}'"
command finished in 52ms
* executing "if [ -d /var/www/html/dataserver/shared/cached-copy ]; then hg pull --repository /var/www/html/dataserver/shared/cached-copy https://cowfish.unh.edu/hg/DataServerApp && hg update --repository /var/www/html/dataserver/shared/cached-copy --clean 6979cec4fc00; else hg clone --noupdate https://cowfish.unh.edu/hg/DataServerApp /var/www/html/dataserver/shared/cached-copy && hg update --repository /var/www/html/dataserver/shared/cached-copy --clean 6979cec4fc00; fi"
servers: ["omitted"]
Password:
[omitted] executing command
** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
** [omitted :: out] http authorization required
** [omitted :: out] realm: Mercurial Project Repository
** [omitted :: out] user:
** [omitted :: out] d
** [omitted :: out] e
** [omitted :: out] p
** [omitted :: out] l
** [omitted :: out] o
** [omitted :: out] y
** [omitted :: out]
** [omitted :: out] password:
** [omitted :: out]
** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
** [omitted :: out] requesting all changes
** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
** [omitted :: out] adding changesets
** [omitted :: out] adding manifests
** adding file changes
** [omitted :: out] added 11 changesets with 187 changes to 125 files
** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
** [omitted :: out] warning: certificate for omitted can't be verified (Python too old)
** [omitted :: out] 114 files updated, 0 files merged, 0 files removed, 0 files unresolved
command finished in 1332ms
copying the cached version to /var/www/html/dataserver/releases/20110912233835
* executing "cp -RPp /var/www/html/dataserver/shared/cached-copy /var/www/html/dataserver/releases/20110912233835 && (echo 6979cec4fc00 > /var/www/html/dataserver/releases/20110912233835/REVISION)"
servers: ["omitted"]
[omitted] executing command
command finished in 23ms
* executing `deploy:finalize_update'
* executing "chmod -R g+w /var/www/html/dataserver/releases/20110912233835"
servers: ["omitted"]
[omitted] executing command
command finished in 7ms
* executing "rm -rf /var/www/html/dataserver/releases/20110912233835/log /var/www/html/dataserver/releases/20110912233835/public/system /var/www/html/dataserver/releases/20110912233835/tmp/pids &&\\\n mkdir -p /var/www/html/dataserver/releases/20110912233835/public &&\\\n mkdir -p /var/www/html/dataserver/releases/20110912233835/tmp &&\\\n ln -s /var/www/html/dataserver/shared/log /var/www/html/dataserver/releases/20110912233835/log &&\\\n ln -s /var/www/html/dataserver/shared/system /var/www/html/dataserver/releases/20110912233835/public/system &&\\\n ln -s /var/www/html/dataserver/shared/pids /var/www/html/dataserver/releases/20110912233835/tmp/pids"
servers: ["omitted"]
[omitted] executing command
command finished in 8ms
* executing "find /var/www/html/dataserver/releases/20110912233835/public/images /var/www/html/dataserver/releases/20110912233835/public/stylesheets /var/www/html/dataserver/releases/20110912233835/public/javascripts -exec touch -t 201109122338.35 {} ';'; true"
servers: ["omitted"]
[omitted] executing command
** [out :: omitted] find: /var/www/html/dataserver/releases/20110912233835/public/images: No such file or directory
** [out :: omitted] find: /var/www/html/dataserver/releases/20110912233835/public/stylesheets: No such file or directory
** [out :: omitted] find: /var/www/html/dataserver/releases/20110912233835/public/javascripts: No such file or directory
command finished in 6ms
* executing `deploy:symlink'
* executing "rm -f /var/www/html/dataserver/current && ln -s /var/www/html/dataserver/releases/20110912233835 /var/www/html/dataserver/current"
servers: ["omitted"]
[omitted] executing command
command finished in 6ms
** transaction: commit
* executing `deploy:restart'
* executing "sudo -p 'sudo password: ' touch /var/www/html/dataserver/current/tmp/restart.txt"
servers: ["omitted"]
[omitted] executing command
command finished in 10ms
triggering after callbacks for `deploy'
* executing `deploy:migrate'
triggering before callbacks for `deploy:migrate'
* executing `sqlite3:link_configuration_file'
* executing "ln -nsf /var/www/html/dataserver/shared/sqlite_config.yml /var/www/html/dataserver/releases/20110912233835/config/database.yml"
servers: ["omitted"]
[omitted] executing command
command finished in 6ms
* executing "cd /var/www/html/dataserver/releases/20110912233835 && rake RAILS_ENV=production db:migrate"
servers: ["omitted"]
[omitted] executing command
** [out :: omitted] sh: rake: command not found
command finished in 5ms
failed: "sh -c 'cd /var/www/html/dataserver/releases/20110912233835 && rake RAILS_ENV=production db:migrate'" on omitted
So it appears that whatever environment it has loaded cannot see rake
. To see what is loaded in the path I created a deploy task, here's the output:
$ cap production test_path
* executing `production'
triggering start callbacks for `test_path'
* executing `multistage:ensure'
* executing `test_path'
* executing "echo $PATH"
servers: ["omitted"]
Password:
[omitted] executing command
** [out :: omitted] /usr/local/bin:/bin:/usr/bin
command finished in 11ms
* executing "echo $rvm_path"
servers: ["omitted"]
[omitted] executing command
** [out :: omitted]
command finished in 5ms
Now you'll notice that path is definitely not correct. For the user that is establishing the session, it should be the following:
/usr/local/rvm/gems/ruby-1.9.2-p290@rails31dataserver/bin:/usr/local/rvm/gems/ruby-1.9.2-p290@global/bin:/usr/local/rvm/rubies/ruby-1.9.2-p290/bin:/usr/local/rvm/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/lpeabody/bin
And again, I get why this isn't working. It's because since I'm running default_run_options[:pty] = true
my environment is getting loaded, at least that is my current theory. So, after all that, I'm left with the conclusion - I need to somehow get my environment loaded so that rake can run without enabling sudo remotely.
Now, I know I'm not the only person to ever have needed to do this, so any pointers or tips will be greatly appreciated. I've racked my brain for the greater portion of 8 hours now and I need to get this app deployed ASAP.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
解决方案是将以下内容添加到 production.rb 的顶部:
我之前缺少的部分是
set :rvm_bin_path, '/usr/local/rvm/bin'
因为我从未使用过它之前在 Capistrano 部署中进行过配置设置,我已经完成了一些。哦,好吧,一天的工作。感谢 irc.freenode.net 上 #rvm 频道的 tonyflint!The solution was to add the following to the top of production.rb:
The part I was missing before was
set :rvm_bin_path, '/usr/local/rvm/bin'
as I've never used that configuration setting in a Capistrano deployment before, and I've done a few. Oh well, all in a days work. Credit goes to tonyflint in the #rvm channel on irc.freenode.net!确保你运行:
在你放置之后
在我这样做之后,它起作用了。
Make sure you run:
before you put
After I do that, it works.
在 capfile 中尝试一些事情(这些适用于系统范围的 RVM 安装,不适用于每用户安装。)
Some things to try in your capfile (these are for a system-wide RVM install and will not work for a per-user install.)
就我而言,添加
解决了问题。
In my case, adding
resolved the issue.