问题描述
我正在尝试部署我的应用程序,并且不断获得
I'm trying to deploy my application and I keep getting
*** [err :: xxx.xxx.xx.xxx] bash: line 1: 9953 Killed bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile
top 没有显示任何异常。我设法从日志中删除的内容是杀死它的过程似乎是 application.js
编译。
I think the issue is that the process is taking too long. There are no errors in the logs and top
didn't show anything abnormal. What I did manage to get out of the log is that the process that it's killing seems to be the application.js
compilation.
当我在本地运行 rake asset:precompile
时,没有错误/警告。
When I ran rake assets:precompile
locally, there were no errors/warnings.
我可以延长capistrano在终止进程之前等待的时间吗?这真的是问题吗?我还能在哪里看?
Can I extend the length that capistrano waits before killing the process? Is that actually the problem? Where else can I look?
更新
运行时
bundle exec rake assets:precompile RAILS_ENV=production RAILS_GROUPS=assets --trace
我得到以下输出
** Invoke assets:precompile (first_time)
** Execute assets:precompile
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
Killed
当我运行
bundle exec rake assets:precompile RAILS_ENV=production --trace
我得到
**执行资产:预编译
** Execute assets:precompile
.../.rvm/rubies/ruby-1.9.3-p374/bin/ruby path/to/app/production/shared/bundle/ruby/1.9.1/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
rake aborted!
Command failed with status (): [/home/user/.rvm/rubies/ruby-1.9.3-p374...]
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/file_utils.rb:53:in `block in create_shell_runner'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/file_utils.rb:45:in `call'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/file_utils.rb:45:in `sh'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/file_utils_ext.rb:40:in `sh'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/file_utils.rb:80:in `ruby'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/file_utils_ext.rb:40:in `ruby'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.11/lib/sprockets/assets.rake:12:in `ruby_rake_task'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.11/lib/sprockets/assets.rake:21:in `invoke_or_reboot_rake_task'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.11/lib/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/home/user/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
path/to/app/production/shared/bundle/ruby/1.9.1/bin/rake:23:in `load'
path/to/app/production/shared/bundle/ruby/1.9.1/bin/rake:23:in `<main>'
Tasks: TOP => assets:precompile
这在暂存目录中不会发生。我觉得这就像盯着我一样
This doesn't happen in the staging directory. I feel like it's staring me in the face
推荐答案
所以我认为我们的问题是bootstrap-sass是资产预编译的一部分。因此,它炸毁了所有css,然后将其全部编译。当这与大量的sass / css结合使用时,该进程将使用大量内存,而OS会杀死它。经过大量研究,我遇到了一个相当不错的解决方案。在本地编译,压缩,上传,在服务器上解压缩,在服务器上进行符号链接,然后删除所有已创建的额外文件(本地资产/压缩文件)。
So I think our problem was that bootstrap-sass was part of the asset precompilation. So it was blowing up all the css, and then compiling it all down. When this is combined with lots of sass/css, the process uses tons of memory, and the OS kills it. After much research, I came across a pretty decent solution. Compile locally, compress it, upload it, decompress it on the server, symlink it on the server, and then delete all the extra files that were created (local assets/compressed files).
这是脚本
namespace :deploy do
namespace :assets do
task :precompile, :roles => :web do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ lib/assets/ app/assets/ | wc -l").to_i > 0
run_locally("RAILS_ENV=#{rails_env} rake assets:clean && RAILS_ENV=#{rails_env} rake assets:precompile")
run_locally "cd public && tar -jcf assets.tar.bz2 assets"
top.upload "public/assets.tar.bz2", "#{shared_path}", :via => :scp
run "cd #{shared_path} && tar -jxf assets.tar.bz2 && rm assets.tar.bz2"
run_locally "rm public/assets.tar.bz2"
run_locally("rake assets:clean")
else
logger.info "Skipping asset precompilation because there were no asset changes"
end
end
task :symlink, roles: :web do
run ("rm -rf #{latest_release}/public/assets &&
mkdir -p #{latest_release}/public &&
mkdir -p #{shared_path}/assets &&
ln -s #{shared_path}/assets #{latest_release}/public/assets")
end
end
# other stuff...
end
在这里。
编辑:
更新有问题Rails部署。我不确定确切的版本,但似乎会影响rails4。资产需要指定要针对其编译的环境,否则生产/暂存环境将找不到它们。
There was an issue with newer rails deployments. I'm not sure the exact version, but it seemed to affect rails 4. The assets need to specify what environment they are being compiled for, otherwise the production/staging environments won't find them.
这篇关于Capistrano杀死资产:预编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!