Unicorn Error Deploying Rails App in Capistrano

Asked 2 years ago, Updated 2 years ago, 94 views

Thank you for your continued support.

This is the first time I've created a Rails app and I'm about to deploy it to VPS.

Until you sign up for vps and deploy the Rails app on capistrano3 [that 1 server configuration]
Until you sign up to vps and deploy the Rails app on Capistrano 3 [2 Local Settings]

I will refer to the above page for instructions.
I'm currently running 4-2 deployment for that 2, but I'm having trouble with an error that I can't solve.

First of all, when you run bundle exec cap production deployment --trace on a terminal, the following errors appear:
It's too long, so I'll post only the relevant parts.

/Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/command.rb:97:in `exit_status=': bundle exit status: 1 (SSHKit::Command::Failed)
bundle stdout: Nothing written
bundle stderr: master failed to start, check stderr log for details
        1: from /Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as [email protected]: bundle exit status: 1 (SSHKit::Runner::ExecuteError)
bundle stdout: Nothing written
bundle stderr: master failed to start, check stderr log for details
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as [email protected]: bundle exit status: 1
bundle stdout: Nothing written
bundle stderr: master failed to start, check stderr log for details
/Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute'
/Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'

Caused by:
SSHKit::Command::Failed: bundle exit status: 1
bundle stdout: Nothing written
bundle stderr —master failed to start, check stderr log for details
/Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/command.rb:97:in`exit_status='
/Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/netssh.rb:170:in `execute_command'
/Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb: 148: in `block create_command_and_execute'
/Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:148:in`tap'
/Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb: 148:in`create_command_and_execute'
/Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:80:in `execute'
/Users/user/Products/blog/lib/capistrano/tasks/unicorn.rb:11:in `block in start_unicorn'
/Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:92:in `within'
/Users/user/Products/blog/lib/capistrano/tasks/unicorn.rb:10:in`start_unicorn'
/Users/user/Products/blog/lib/capistrano/tasks/unicorn.rb:53:in`block(3 levels) in<top(required)>'
/Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:31:in`instance_exec'
/Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/backends/abstract.rb:31:in `run'
/Users/user/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:12:in `block(2 levels) in execute'
Tasks: TOP=>unicorn:restart
The deploy has failed with an error: Exception while executing as user @150.95.152.189: bundle exit status:1
bundle stdout —Nothing write
bundle stderr —master failed to start, check stderr log for details
** Invoke deploy: failed(first_time)
** Execute deploy: failed

The following are the VPS unicorn.log errors:

 [fog] [DEPRECATION] Fog::Storage::AWS is deprecated, please use Fog::AWS::Storage.
[fog] [WARNING] Unrecognized arguments: region, aws_access_key_id, aws_secret_access_key
bundleer: failed to load command: unicorn(/var/www/app/shared/bundle/ruby/2.6.0/bin/unicorn)
TypeError: no implicit conversion of nil into String
  /var/www/app/shared/bundle/ruby/2.6.0/gems/fog-aws-3.5.2/lib/fog/aws/signaturev4.rb:12:in`+'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/fog-aws-3.5.2/lib/fog/aws/signaturev4.rb:12:in `initialize'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/fog-aws-3.5.2/lib/fog/aws/storage.rb:544:in `new'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/fog-aws-3.5.2/lib/fog/aws/storage.rb:544:in `setup_credentials'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/fog-aws-3.5.2/lib/fog/aws/storage.rb:527:in `initialize'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/fog-core-2.1.0/lib/fog/core/service.rb:115:in`new'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/fog-core-2.1.0/lib/fog/core/service.rb:115:in`new'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/fog-aws-3.5.2/lib/fog/aws/storage.rb: 788: in `new'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/fog-core-2.1.0/lib/fog/core/services_mixin.rb: 16:in `new'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/fog-core-2.1.0/lib/fog/storage.rb:22:in `new'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/carrierwave-2.0.0/lib/carrierwave/storage/fog.rb:68:in `eager_load'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/carrierwave-2.0.0/lib/carrierwave.rb:77:in`block in<class:Railty>'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/lazy_load_hooks.rb: 69:in `block in execute_hook'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/lazy_load_hooks.rb:52:in`block in run_load_hooks'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/lazy_load_hooks.rb:51:in `each'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/rails-6.0.0/lib/rails/application/finisher.rb:118:in `block in<module:Finisher>'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/rails-6.0.0/lib/rails/initialized.rb:32:in`instance_exec'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/rails-6.0.0/lib/rails/initializable.rb:32:in `run'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/rails-6.0.0/lib/rails/initializable.rb: 61: in `block in run_initializers'
  /home/user/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb: 228:in`block intsort_each'
  /home/user/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:350:in `block(2 levels) in each_strongly_connected_component'
  /home/user/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
  /home/user/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:349:in`block in each_strongly_connected_component'
  /home/user/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each'
  /home/user/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in`call'
  /home/user/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
  /home/user/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb:226:in`tsort_each'
  /home/user/.rbenv/versions/2.6.3/lib/ruby/2.6.0/tsort.rb: 205:in`tsort_each'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/rails-6.0.0/lib/rails/initialized.rb:60:in `run_initializers'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/rails-6.0.0/lib/rails/application.rb:363:in `initialize!'
  /var/www/app/releases/20191008231529/config/environment.rb:5:in`<top(required)>'
  config.ru:4:in `require_relative'
  config.ru:4:in `block in<main>'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/builder.rb:55:in `instance_eval'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/builder.rb:55:in `initialize'
  config.ru:1:in `new'
  config.ru:1:in `<main>'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/unicorn-5.5.1/lib/unicorn.rb:54:in `eval'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/unicorn-5.5.1/lib/unicorn.rb:54:in `block in builder'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/unicorn-5.5.1/lib/unicorn/http_server.rb:794:in`build_app!'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/unicorn-5.5.1/lib/unicorn/http_server.rb:141:in `start'
  /var/www/app/shared/bundle/ruby/2.6.0/gems/unicorn-5.5.1/bin/unicorn: 128: in `<top(required)>'
  /var/www/app/shared/bundle/ruby/2.6.0/bin/unicorn:23:in `load'
  /var/www/app/shared/bundle/ruby/2.6.0/bin/unicorn:23:in `<top(required)>'

About fog errors in line 1 and 2
Configuring AWS in config/initializers/carrier_wave.rb.
Each value is set to an environment variable using Gem called dotenv.
I created config/master.key for the VPS and set the same value as the local one.

About errors after line 3
I think Unicorn should enter with Gemfile's gem'unicorn'
After running gem install unicorn on the VPS and then redeploying it, the situation remains the same.

It's my first time doing things like Capistrano, Unicorn, and Nginx, so I'd appreciate it if someone could give me a solution.

ruby-on-rails nginx capistrano unicorn

2022-09-29 22:38

1 Answers

[Self-solving]

I added the following to config/deploy.rb.

 set: default_env, {
  rbenv_root: "/home/user/.rbenv",
  path: "/home/user/.rbenv/bin:$PATH",
  region: ENV["S3_REGION",
  aws_access_key_id:ENV["S3_ACCESS_KEY"],
  aws_secret_access_key:ENV["S3_SECRET_KEY"]
}

Deployment with Capistrano runs without reading the environment variable .bash_profile.
Therefore, you must explicitly set the environment variables in the Capistrano (Unicorn?) configuration file.

See also: Rails issue on cap production deploy

There seems to be a way to set it to .bashrc (not verified).
Resolving Errors Using Capistrano+carrierwave


2022-09-29 22:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.