Ruby on Rails应用程序仅以root用户身份运行,以ec2用户身份运行时会出错

xqk2d5yq  于 2022-12-22  发布在  Ruby
关注(0)|答案(1)|浏览(67)

背景:我在运行Amazon Linux 2的EC2示例中有一个Ruby应用程序。我的应用程序使用Ruby 2.7.6。我尝试以ec2-user运行应用程序。当我运行bundle install时,包加载正常,但当我运行rails s命令时,出现错误。

Traceback (most recent call last):
        40: from bin/rails:10:in `<main>'
        39: from bin/rails:10:in `require'
        38: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/railties-5.2.8.1/lib/rails/commands.rb:18:in `<top (required)>'
        37: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/railties-5.2.8.1/lib/rails/command.rb:46:in `invoke'
        36: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/railties-5.2.8.1/lib/rails/command/base.rb:69:in `perform'
        35: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
        34: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
        33: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
        32: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/railties-5.2.8.1/lib/rails/commands/server/server_command.rb:142:in `perform'
        31: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/railties-5.2.8.1/lib/rails/commands/server/server_command.rb:142:in `tap'
        30: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/railties-5.2.8.1/lib/rails/commands/server/server_command.rb:145:in `block in perform'
        29: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/railties-5.2.8.1/lib/rails/commands/server/server_command.rb:145:in `require'
        28: from /home/ec2-user/test/mvs_web/config/application.rb:9:in `<top (required)>'
        27: from /opt/rubies/ruby-2.7.6/lib/ruby/site_ruby/2.7.0/bundler.rb:187:in `require'
        26: from /opt/rubies/ruby-2.7.6/lib/ruby/site_ruby/2.7.0/bundler/runtime.rb:44:in `require'
        25: from /opt/rubies/ruby-2.7.6/lib/ruby/site_ruby/2.7.0/bundler/runtime.rb:44:in `each'
        24: from /opt/rubies/ruby-2.7.6/lib/ruby/site_ruby/2.7.0/bundler/runtime.rb:55:in `block in require'
        23: from /opt/rubies/ruby-2.7.6/lib/ruby/site_ruby/2.7.0/bundler/runtime.rb:55:in `each'
        22: from /opt/rubies/ruby-2.7.6/lib/ruby/site_ruby/2.7.0/bundler/runtime.rb:60:in `block (2 levels) in require'
        21: from /opt/rubies/ruby-2.7.6/lib/ruby/site_ruby/2.7.0/bundler/runtime.rb:60:in `require'
        20: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/savon-2.13.1/lib/savon.rb:27:in `<top (required)>'
        19: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
        18: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
        17: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `block in require'
        16: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
        15: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/savon-2.13.1/lib/savon/client.rb:2:in `<top (required)>'
        14: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
        13: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
        12: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `block in require'
        11: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
        10: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/savon-2.13.1/lib/savon/operation.rb:9:in `<top (required)>'
         9: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
         8: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
         7: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `block in require'
         6: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
         5: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/mail-2.8.0/lib/mail.rb:3:in `<top (required)>'
         4: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/mail-2.8.0/lib/mail.rb:14:in `<module:Mail>'
         3: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
         2: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
         1: from /opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `block in require'
/opt/rubies/ruby-2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require': cannot load such file -- mail/indifferent_hash (

但是当我以root运行应用程序时,我没有遇到这个错误,应用程序运行正常。
但我需要为ec2-userwebapp用户运行此命令,因为在部署期间,管道正在以webapp用户身份执行命令,并且它会出现类似的错误。

2022/12/16 21:32:38.034224 [INFO] Running command /bin/su webapp -c bundle exec /opt/elasticbeanstalk/config/private/checkforraketask.rb db:migrate
2022/12/16 21:32:42.299253 [INFO] rake aborted!
LoadError: cannot load such file -- mail/indifferent_hash
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `block in require'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/mail-2.8.0/lib/mail.rb:14:in `<module:Mail>'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/mail-2.8.0/lib/mail.rb:3:in `<top (required)>'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `block in require'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/savon-2.13.1/lib/savon/operation.rb:9:in `<top (required)>'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `block in require'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/savon-2.13.1/lib/savon/client.rb:2:in `<top (required)>'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `block in require'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
/var/app/staging/vendor/bundle/ruby/2.7.0/gems/savon-2.13.1/lib```

Please advice on how to bypass this.
oxalkeyp

oxalkeyp1#

此问题是mail gem(see here)中的已知错误。
您应该确保使用以前的版本- 2.7.1。

相关问题