![](/img/trans.png)
[英]Rails, Capistrano, Nginx, Unicorn - Application has been already initialized (RuntimeError)
[英]Capistrano - rake assets:precompile - Application has been already initialized
我正在尝试使用Capistrano部署Rails 3.2.13应用程序。
我正在使用资产管道,因此尝试在部署期间预编译资产。
我收到以下错误:“应用程序已经初始化。” 在rake asset:precompile阶段。
这是堆栈跟踪:
执行“ cd-/sites/beta.myapp.com/releases/20130905192243 && RAILS_ENV = beta RAILS_GROUPS =资产捆绑exec rake资产:预编译”,执行命令rake中止了! 应用程序已被初始化。 /sites/beta.myapp.com/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:135:正在
initialize!' /sites/beta.myapp.com/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:95:in
initialize!' /sites/beta.myapp.com/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:95:in
在“(任务:TOP => asset:precompile:primary => asset:environment
有任何想法吗?
这是我的deploy.rb:
require "bundler/capistrano"
require 'capistrano/ext/multistage'
require "whenever/capistrano"
require './config/boot'
require 'airbrake/capistrano'
set :stages, %w(beta production)
set :application, "myapp...."
set :whenever_environment, defer { stage }
set :whenever_command, "bundle exec whenever"
set :user, "myuser...."
set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, "git"
set :repository, "myrepo....."
set :branch, $1 if `git branch` =~ /\* (\S+)\s/m
namespace :deploy do
task :cold do # Overriding the default deploy:cold
update
load_schema # My own step, replacing migrations.
start
end
task :load_schema, :roles => :app do
run "cd #{current_path}; rake db:schema:load RAILS_ENV=#{stage}"
end
desc "Tell Passenger to restart and restart workers."
task :restart, :roles => :web do
run "touch #{deploy_to}/current/tmp/restart.txt"
end
desc "Do nothing on startup so we don't get a script/spin error."
task :start do
puts "You may need to restart Apache."
end
desc "Symlink extra configs and folders."
task :symlink_extras do
run "ln -nfs #{shared_path}/config/database.yml #{latest_release}/config/database.yml"
run "ln -nfs #{shared_path}/assets #{latest_release}/public/assets"
end
desc "Setup shared directory."
task :setup_shared do
run "mkdir #{shared_path}/assets"
run "mkdir #{shared_path}/config"
run "mkdir #{shared_path}/tmp"
run "mkdir #{shared_path}/db"
put File.read("config/examples/database.yml"), "#{shared_path}/config/database.yml"
puts "Now edit the config files and fill assets folder in #{shared_path}."
end
desc "Seed the db with shipping options and a product"
task :seed do
run "cd #{current_path}; rake db:seed"
end
desc "Make sure there is something to deploy"
task :check_revision, :roles => :web do
unless `git rev-parse HEAD` == `git rev-parse origin/#{branch}`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
desc "Stop resque Workers."
task :stop_workers, :on_error => :continue do
run "cd #{current_path} && rake resque:stop_workers RAILS_ENV=#{stage}"
end
end
before "deploy", "deploy:check_revision"
after "deploy", "deploy:cleanup"
after "deploy:setup", "deploy:setup_shared"
before "deploy:assets:precompile", "deploy:symlink_extras"
after "deploy:update_code", "deploy:stop_workers"
我最终解决了这个问题:
在config / application.rb中,我必须注释掉以下行:
config.assets.initialize_on_precompile = true
我尝试将config.assets.initialize_on_precompile设置为false,也设置为true。在两种情况下,我都收到“应用程序已被初始化”错误。
但是,一旦我完全注释掉了该行,便可以部署我的应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.