rake 部署问题

悬赏:30 发布时间:2008-08-08 提问人:caocao12 (初级程序员)

我看了WEB开发敏捷之道这本书后,准备搭建一个ROR环境,没想到其中遇到这样的问题:
1.配置好Mongrel后,用Capistrano部署:
cap --apply-to /local/project/path
之前在这里就遇到问题了,不过后来解决了,是因为版本太老的问题,导致找不到--apply-to这个参数.
执行这个命令后,生成两个文件: config/deploy.rb  Capfile
config/deploy.rb的文件内容如下:

require 'mongrel_cluster/recipes'
set :application, "test_app"
set :repository,  "http://localhost/svn/test/#{application}"

set :deploy_to, "/var/rails_app/#{application}"

set :mongrel_conf, "#{application}/current/config/mongrel_cluster.yml"

role :app, "http://localhost"
role :web, "http://localhost"
role :db,  "http://localhost", :primary => true

不知道:app  :web :db是否有填错?

2. 按书上说的做: 在服务器上建立部署基本目录结构:
rake remote:setup
就会提示:
(in /var/rails_app/test_app)
rake aborted!
Don't know how to build task 'remote:setup'

(See full trace by running task with --trace)
不过我所有东西全装在本地,好像不用这样做吧, 到网上找到一篇文章是这样说的:

第一次部署需要运行下面的命令:

cap deploy:setup
显示:  Password:
    [192.168.13.243] executing command
    command finished
当执行:
cap deploy:check
问题来了,运行这个命令后,又出现如下错误信息:
Password: 
    [192.168.13.243] executing command
    command finished
  * executing "test -w /var/rails_app/test_app"
    servers: ["192.168.13.243"]
    [192.168.13.243] executing command
    command finished
  * executing "test -w /var/rails_app/test_app/releases"
    servers: ["192.168.13.243"]
    [192.168.13.243] executing command
    command finished
  * executing "which svn"
    servers: ["192.168.13.243"]
    [192.168.13.243] executing command
192.168.13.243: which: no svn in (/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin)

    command finished
The following dependencies failed. Please check them and try again:
--> `svn' could not be found in the path (192.168.13.243)


请问这个问题如何解决? 谢谢!


问题补充:
我最开始就是写的localhost,不过我后来改成IP地址也可了,刚执行
cap deploy:check
又遇到错误了,这个不知道什么问题,麻烦你帮看看。谢谢你了
问题补充:
这个什么意思呢?
The following dependencies failed. Please check them and try again:
--> `svn' could not be found in the path on the local host

无法在本机找到这个路径,哪个路径呢? 谢谢你回答我的问题!
问题补充:
现在还有问题:
The following dependencies failed. Please check them and try again:
--> `svn' could not be found in the path (192.168.13.243)

以下是deploy.rb的相关信息:
role :app, "192.168.13.243"
role :web, "192.168.13.243"
role :db,  "192.168.13.243", :primary => true


set :deploy_via, :remote_cache
#set :deploy_via, :copy
set :copy_strategy, :export
set :copy_compression, :bz2

哪还有问题吗?
问题补充:
另外,下面这个路径好像也不对:
set :mongrel_conf, "#{application}/current/config/mongrel_cluster.yml"
我的路径中好像没有current这个目录,但网上的文章说好像又要这个,不知道什么意思
问题补充:
网上找不到LINUX下SVN的客户端哦,装完SVN后,不是有客户端命令吗? svn checkout
svn add/delete之类的命令。
问题补充:
执行:  cap deploy:start 出现如下错误:

[root@redhgg test_app]# cap deploy:start
  * executing `deploy:start'
  * executing `mongrel:cluster:start'
  * executing "mongrel_rails cluster::start -C /var/rails_app/test_app/config/mongrel_cluster.yml"
    servers: ["192.168.13.243"]
    [192.168.13.243] executing command
*** [err :: 192.168.13.243] /usr/local/ruby/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/lib/mongrel_cluster/init.rb:188:in `chdir'
*** [err :: 192.168.13.243] :
*** [err :: 192.168.13.243] No such file or directory - /var/rails_app/test_app/current
*** [err :: 192.168.13.243] (
*** [err :: 192.168.13.243] Errno::ENOENT
*** [err :: 192.168.13.243] )
*** [err :: 192.168.13.243] from /usr/local/ruby/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/lib/mongrel_cluster/init.rb:188:in `chdir_cwd'
*** [err :: 192.168.13.243] from /usr/local/ruby/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/lib/mongrel_cluster/init.rb:161:in `pid_file_exists?'
*** [err :: 192.168.13.243] from /usr/local/ruby/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/lib/mongrel_cluster/init.rb:89:in `start'
*** [err :: 192.168.13.243] from /usr/local/ruby/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/lib/mongrel_cluster/init.rb:80:in `each'
*** [err :: 192.168.13.243] from /usr/local/ruby/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/lib/mongrel_cluster/init.rb:80:in `start'
*** [err :: 192.168.13.243] from /usr/local/ruby/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/lib/mongrel_cluster/init.rb:239:in `run'
*** [err :: 192.168.13.243] from /usr/local/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/command.rb:212:in `run'
*** [err :: 192.168.13.243] from /usr/local/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:281
*** [err :: 192.168.13.243] from /usr/local/ruby/bin/mongrel_rails:19:in `load'
*** [err :: 192.168.13.243] from /usr/local/ruby/bin/mongrel_rails:19
    command finished
command "mongrel_rails cluster::start -C /var/rails_app/test_app/config/mongrel_cluster.yml" failed on 192.168.13.243

说找不到current, 不过current在我有rails应该目录目录下面确实没有这个文件或目录,手工创建一个这个的文件也不行的.
问题补充:
现在改了下,出现下面这种情况:
[root@redhgg test_app]# cap deploy:start
  * executing `deploy:start'
  * executing "cd /var/rails_app/test_app/current &&  nohup script/spin"
    servers: ["192.168.13.243"]
    [192.168.13.243] executing command
*** [err :: 192.168.13.243] sh: line 0: cd: /var/rails_app/test_app/current: 娌℃湁閭d釜鏂囦欢鎴栫洰褰?
                                                                                                             command finished
command "cd /var/rails_app/test_app/current &&  nohup script/spin" failed on 192.168.13.243

而执行 cap deploy:cold 时,出现下面的情况:

[root@redhgg test_app]# cap deploy:cold
  * executing `deploy:cold'
  * executing `deploy:update'
** transaction: start
  * executing `deploy:update_code'
  * getting (via checkout) revision 1 to /tmp/20080811002122
    executing locally: svn checkout -q  -r1 http://192.168.13.243/svn/test/test_app /tmp/20080811002122
    compressing /tmp/20080811002122 to /tmp/20080811002122.tar.gz
    executing locally: tar czf 20080811002122.tar.gz 20080811002122
    servers: ["192.168.13.243"]
** sftp upload /tmp/20080811002122.tar.gz -> /tmp/20080811002122.tar.gz
    [192.168.13.243] /tmp/20080811002122.tar.gz
    [192.168.13.243] done
  * sftp upload complete
  * executing "cd /var/rails_app/test_app/releases && tar xzf /tmp/20080811002122.tar.gz && rm /tmp/20080811002122.tar.gz"
    servers: ["192.168.13.243"]
    [192.168.13.243] executing command
*** [err :: 192.168.13.243]
*** [err :: 192.168.13.243] gzip:
*** [err :: 192.168.13.243] stdin: unexpected end of file
*** [err :: 192.168.13.243] tar:
*** [err :: 192.168.13.243] Child returned status 1
*** [err :: 192.168.13.243]
*** [err :: 192.168.13.243] tar:
*** [err :: 192.168.13.243] Error exit delayed from previous errors
*** [err :: 192.168.13.243]
    command finished
*** [deploy:update_code] rolling back
  * executing "rm -rf /var/rails_app/test_app/releases/20080811002122; true"
    servers: ["192.168.13.243"]
    [192.168.13.243] executing command
    command finished
command "cd /var/rails_app/test_app/releases && tar xzf /tmp/20080811002122.tar.gz && rm /tmp/20080811002122.tar.gz" failed on 192.168.13.243

麻烦帮忙解决一下,谢谢了
该问题已经关闭: 超过15天由系统自动关闭,悬赏平分给所有参与回答的会员

回答

归根结底你现在只有一个问题,就是 role :xxx 后面的值写错了,应该只填写主机名,例如 localhost,而不是 http://localhost。

参考 http://www.javaeye.com/topic/130853。
rainux (中级程序员) 2008-08-08
connection failed for: http://localhost (SocketError: getaddrinfo: Name or service not known)

这个错误就是因为 capistrano 把你填写的 http://localhost 当成了域名去解析,这样当然无法解析出 IP 地址来。
rainux (中级程序员) 2008-08-08
capistrano 的工作原理是通过 SSH 登录远程服务器,在上面自动执行一系列预设的 shell 命令来进行项目发布的操作。其中一个重要的环节就是将项目源代码发布到服务器上,默认的行为是使用 svn 客户端直接从 svn 仓库中 checkout 出项目源代码来,因此需要远程服务器上有安装 svn 客户端。你的错误信息也清晰的显示了这一点。

# The following dependencies failed. Please check them and try again:  
# --> `svn' could not be found in the path (192.168.13.243)  


最好的解决方法仍然是在服务器上安装 svn 客户端,如果实在不方便,可以使用折衷的发布策略,在本机 svn export 出项目源代码并打包压缩通过 scp/sftp 复制到服务器上。只需要在 deploy.rb 里设置

# 必须的,使用 scp/sftp 复制源代码到服务器上。
set :deploy_via, :copy
# 可选,使用 svn export 而不是 svn checkout 获取源代码,得到的源代码里没有 .svn 目录,体积小一些。
set :copy_strategy, :export
# 可选,使用可选压缩方式中压缩率最高的 bz2。
set :copy_compression, :bz2
rainux (中级程序员) 2008-08-08
但如果在服务器端安装 svn 客户端,并且服务器端可以直接访问 svn 仓库,则可以使用 remote_cache 方式得到最快的发布速度。这种方式 capistrano 会在服务器端 "#{shared_path}/cached_copy}" 目录下维护一份项目源代码的 svn working copy,每次发布时更新这个 working copy,然后将其复制到 relase_path 目录下成为新发布的版本。

set :deploy_via, :remote_cache
rainux (中级程序员) 2008-08-08
服了……

楼主看清楚我说的两种设置的说明,remote_cache 是需要服务器上有安装  svn 客户端。

引用
The following dependencies failed. Please check them and try again:
--> `svn' could not be found in the path on the local host


这说明你把发布目标服务器设置为本机 localhost 了,而且本机上也没有安装 svn 客户端,难道你的项目没有用 svn 进行版本控制?那么你在上面用 set :repository 配置的 svn 仓库 URL 又是怎么回事?

引用
另外,下面这个路径好像也不对:
set :mongrel_conf, "#{application}/current/config/mongrel_cluster.yml"
我的路径中好像没有current这个目录,但网上的文章说好像又要这个,不知道什么意思


capistrano 的工作原理是在服务器端 deploy_to 目录下创建一个 releases 目录,每次发布都在这个目录里创建一个以当前时间戳命名的目录来存放项目源代码,然后在 deploy_to 目录下创建一个名为 current 的符号链接指向 releases 目录里当前发布的版本。这样做的好处时你可以随时切换到以前发布的版本。
rainux (中级程序员) 2008-08-08