Capistrano 2 - 权限被拒绝 - tmp / i18n-js.cache

时间:2014-04-08 21:57:27

标签: ruby-on-rails ruby ruby-on-rails-3 capistrano i18n-gem

我经常遇到Capistrano部署和i18n-js的问题。 基本上,我有一个rails 3.2.16应用程序,它使用i18n-js gem(版本2.1.2)内部化为2种语言(英语和日语)。当我部署应用程序时,该过程如下所示(我需要运行几个rake任务):

bundle exec rake i18n:js:export
bundle exec rake db:migrate
bundle exec rake assets:precompile

我在登台服务器上部署,这是Capistrano文件(capistrano gem版本是2.15.5):

server "ec2-bla-bla.compute-1.amazonaws.com", :app, :web, :db

set :branch, "staging"
set :rails_env, "staging"
after "deploy", "deploy:cleanup"
before "deploy:assets:precompile", "deploy:i18n_js_export"

namespace :deploy do
  desc "I18n export"
  task :i18n_js_export do

  run "ps aux | grep unicorn | grep -v grep | awk '{system(\"kill -9 \"$2)}'; true"
  run "ps aux | grep sidekiq | grep -v grep | awk '{system(\"sudo kill -TERM \"$2)}'; true"
  run "export RAILS_ENV=#{rails_env} && cd #{current_path} && bundle exec rake i18n:js:export"
  run "export RAILS_ENV=#{rails_env} && cd #{current_path} && bundle exec rake db:migrate" 
end

task :unicorn_restart do
  run "sudo service unicorn_myapp restart; true"
  end
end

namespace :deploy do
  desc "Recreate symlink"
  task :resymlink, :roles => :app do
    run "rm -f #{current_path} && ln -s #{release_path} #{current_path}"
  end
end

after "deploy:assets:symlink", "deploy:resymlink"
after "deploy:assets:precompile", "deploy:unicorn_restart"

有点好笑,有时脚本运行正常,但有时我会收到以下错误:

* executing "export RAILS_ENV=staging && cd /home/ubuntu/apps/myapp/current && bundle exec rake i18n:js:export"
    servers: ["staging.compute-a.aws.amazon.com"]
    [staging.compute-a.aws.amazon.com] executing command
** [out :: staging.compute-a.aws.amazon.com] [deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
 ** [out :: staging.compute-a.aws.amazon.com] 
 ** [out :: staging.compute-a.aws.amazon.com] rake aborted!
 ** [out :: staging.compute-a.aws.amazon.com] Permission denied - /home/ubuntu/apps/myapp/releases/20140407170608/tmp/i18n-js.cache
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/i18n-js-2.1.2/lib/i18n-js/engine.rb:52:in `initialize'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/i18n-js-2.1.2/lib/i18n-js/engine.rb:52:in `open'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/i18n-js-2.1.2/lib/i18n-js/engine.rb:52:in `write_hash!'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/i18n-js-2.1.2/lib/i18n-js/engine.rb:45:in `write_hash_if_changed'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/i18n-js-2.1.2/lib/i18n-js/engine.rb:33:in `block in <class:Engine>'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:440:in `_run__3095975217415606208__prepare__1788827297758520059__callbacks'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:405:in `__run_callback'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:81:in `run_callbacks'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.16/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.16/lib/rails/initializable.rb:30:in `instance_exec'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.16/lib/rails/initializable.rb:30:in `run'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.16/lib/rails/initializable.rb:55:in `block in run_initializers'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/railti
 ** [out :: staging.compute-a.aws.amazon.com] es-3.2.16/lib/rails/initializable.rb:54:in `each'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.16/lib/rails/initializable.rb:54:in `run_initializers'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.16/lib/rails/application.rb:136:in `initialize!'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.16/lib/rails/railtie/configurable.rb:30:in `method_missing'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/releases/20140407170608/config/environment.rb:8:in `<top (required)>'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:251:in `require'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:251:in `block in require'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:236:in `load_dependency'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/dependencies.rb:251:in `require'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.16/lib/rails/application.rb:103:in `require_environment!'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/shared/bundle/ruby/1.9.1/gems/railties-3.2.16/lib/rails/application.rb:305:in `block (2 levels) in initialize_tasks'
 ** [out :: staging.compute-a.aws.amazon.com] /home/ubuntu/apps/myapp/releases/20140407170608/config/application.rb:87:in `invoke'
 ** [out :: staging.compute-a.aws.amazon.com] Tasks: TOP => i18n:js:export => environment
 ** [out :: staging.compute-a.aws.amazon.com] (See full trace by running task with --trace)
    command finished in 90439ms

似乎i18n-js.cache文件有时被创建为写保护。

一些事情:     1. i18n-js.cache不仅在i18n:js:export中创建,而且在以下任何命令中创建(db:migrate,assets:precompile)     2.我尝试在rake调用之间更改权限,但它不起作用,因为它似乎是在rake调用中创建的,并且在同一rake调用期间拒绝访问:

    run "sudo chown ubuntu #{current_path}/tmp/i18n-js.cache"

非常感谢任何帮助。现在我必须手动查看它何时出现,所以我可以手动更改权限,这有点乏味

0 个答案:

没有答案