在本主题中,我遵循@Coward的回答:我如何运行从卡皮斯特拉诺的耙任务?在我的deploy.rb中添加一个自定义任务rake:invoke,以便能够远程调用rake任务。
它本身的工作原理非常完美,但当我的cap deploy处理正在执行assets:precompile时,我会得到以下错误
[mydomain.com] rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell '1.9.2@ziya' -c 'cd /var/deploy/ziya/releases/20120223100338 && #<Capistrano::Configuration::Namespaces::Namespace:0x007ff2b4a4bad8> RAILS_ENV=staging RAILS_GROUPS=assets assets:precompile'
** [out :: my domain.com] bash: -c: line 1: syntax error: unexpected end of file
command finished in 1265ms就像注射某种东西,但我就是找不出我的deploy.rb到底出了什么问题
deploy.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@ziya'
set :use_sudo, true
require "bundler/capistrano"
set :stages, %w(staging production)
set :default_stage, "production"
require 'capistrano/ext/multistage'
set :application, "my application"
# ssh to the deploy server
default_run_options[:pty] = true
# setup scm:
set :repository, "mygiturl"
set :deploy_via, :remote_cache
set :scm_username, "myusernmae"
set :scm, :git
set :scm_verbose, "true"
set :branch, "master"
ssh_options[:forward_agent] = true
set(:releases_path) { File.join(deploy_to, version_dir) }
set(:shared_path) { File.join(deploy_to, shared_dir) }
set(:current_path) { File.join(deploy_to, current_dir) }
set(:release_path) { File.join(releases_path, release_name) }
set :deploy_to, "/var/deploy/#{application}"
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
task :bootstrap do
run "cd #{release_path}; rake bootstrap:all RAILS_ENV=#{rails_env}"
end
task :import_all do
run "cd #{release_path}; rake import:pages RAILS_ENV=#{rails_env}"
run "cd #{release_path}; rake import:legacy_all RAILS_ENV=#{rails_env}"
end
task :import_pages do
run "cd #{release_path}; rake import:pages RAILS_ENV=#{rails_env}"
end
end
namespace :rake do
desc "Run a task on a remote server."
# run like: cap staging rake:invoke task=a_certain_task
task :invoke do
run("cd #{deploy_to}/current; /usr/bin/env rake #{ENV['task']} RAILS_ENV=#{rails_env}")
end
end但是如果我把task :invoke移到namespace :deploy里,放下namespace :rake,那么一切都好了,太让人困惑了..
发布于 2012-03-25 13:53:07
这种情况发生在Capistrano的源声明rake为内部变量中,通过这种方式,使用部署文件中的set :rake指令将你可以覆盖作为rake命令行使用。
但是,由于capistrano内部,当您声明一个rake名称空间时,它将优先于声明的rake变量。因此,当capistrano执行其预编译资产的配方时,它将构建所需的命令行 rake变量,而不是返回"rake"字符串,返回转换为字符串的声明命名空间。您可以在构建的命令行的这一部分中看到它:
... && #<Capistrano::Configuration::Namespaces::Namespace:0x007ff2b4a4bad8> RAILS_ENV=staging RAILS_GROUPS=assets assets:precompile'这显然会导致shell语法错误,这也是为什么更改名称空间可以解决问题的原因。
https://stackoverflow.com/questions/9414569
复制相似问题