[Capistrano, Unicorn] ArgumentError: directory for pid = / var / www / badsuru / current / shared / tmp / pids / unicorn.pid not writable was not a write permission issue

Introduction

During automatic deployment using Capistrano, I spent almost a day with a title error ... In conclusion, it's not a big deal and I'm disappointed in myself, but I hope it helps those who suffer from similar errors.

Target person

Development environment

What you can get through this article

--Cause and solution of title error

Conclusion (solution)

There is a mistake in the setting description of unicorn.rb. I changed it as follows. The / var / www / badsuru / current / shared / tmp / pids / directory that creates unicorn.pid was not found due to a different path for the app under development, spitting out a title error.

Change before

unicorn.rb


//Put the directory where the application code on the server is installed in a variable
app_path = File.expand_path('../../', __FILE__)

//Determine application server performance
worker_processes 1

//Specify the directory where the application is installed
working_directory app_path

(Omitted below)

After change

unicorn.rb


//Put the directory where the application code on the server is installed in a variable
app_path = File.expand_path('../../../', __FILE__)

//Determine application server performance
worker_processes 1

//Specify the directory where the application is installed
//Specify current
working_directory "#{app_path}/current"

(Omitted below)

Details

When I wrote the automatic configuration file of Capistarno and executed it, the following error was spit out.

00:44 unicorn:start
      01 $HOME/.rbenv/bin/rbenv exec bundle exec unicorn -c /var/www/myapp/current/config/unicorn.rb -E deployment -D 
      01 bundler: failed to load command: unicorn (/var/www/myapp/shared/bundle/ruby/2.7.0/bin/unicorn)
      01 ArgumentError: directory for pid=/var/www/myapp/current/shared/tmp/pids/unicorn.pid not writable
      01   /var/www/myapp/shared/bundle/ruby/2.7.0/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:100:in `block in reload'
      01   /var/www/myapp/shared/bundle/ruby/2.7.0/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:96:in `each'
      01   /var/www/myapp/shared/bundle/ruby/2.7.0/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:96:in `reload'
      01   /var/www/myapp/shared/bundle/ruby/2.7.0/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:77:in `initialize'
      01   /var/www/myapp/shared/bundle/ruby/2.7.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:77:in `new'
      01   /var/www/myapp/shared/bundle/ruby/2.7.0/gems/unicorn-5.4.1/lib/unicorn/http_server.rb:77:in `initialize'
      01   /var/www/myapp/shared/bundle/ruby/2.7.0/gems/unicorn-5.4.1/bin/unicorn:126:in `new'
      01   /var/www/myapp/shared/bundle/ruby/2.7.0/gems/unicorn-5.4.1/bin/unicorn:126:in `<top (required)>'
      01   /var/www/myapp/shared/bundle/ruby/2.7.0/bin/unicorn:23:in `load'
      01   /var/www/myapp/shared/bundle/ruby/2.7.0/bin/unicorn:23:in `<top (required)>'
      01 master failed to start, check stderr log for details
(abridgement)

Initially, there was a description of unicorn.pid not writable, so I thought it was an error around permissions, and even if I gave write permissions to various directories such as releases, current, shared ..., it was not resolved. I was at a loss.

Also, I googled the information that the directory must be created in advance with the `` `mkdir pids``` command etc. and tried it, but it did not work ... After carefully reviewing the description in the configuration file that I intended to review, I noticed a mistake in the conclusion.

It's a guess, but when unicorn starts up, the unicorn.pids file is created under the setting directory, but the directory setting of the application that runs unicorn is wrong. I want to create a unicorn.pids file, but I can't reach that directory, so instead of the message not found, it seems to spit out a title error. Certainly, even when I was looking for a solution to the error, there was an article pointing out the description of the configuration file ...

At the end

If an error occurs and the content is corrected as pointed out but still appears, there is a good possibility of a mistake different from the error statement. It was a lesson to review the files I wrote.

Recommended Posts

[Capistrano, Unicorn] ArgumentError: directory for pid = / var / www / badsuru / current / shared / tmp / pids / unicorn.pid not writable was not a write permission issue