LoginSignup
shotam27
@shotam27

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

unicorn_rails -c config/unicorn.conf.rb -E production -D を実行するとエラーになる

解決したいこと

EC2 + docker-compose + railsで、
unicorn_rails -c config/unicorn.conf.rb -E production -D
を実行するとエラーになるのですが、
原因がわかりません。

発生している問題・エラー

Capistranoを利用せず
EC2にrailsアプリ(caleapp)をデプロイしたく
https://qiita.com/naoki_mochizuki/items/5a1757d222806cbe0cd1#nginx%E3%81%AE%E8%B5%B7%E5%8B%95
を参考に進めていたところ、
nginx起動後
image.png

このようなエラーがでた為記事に記載されていた通り

 unicorn_rails -c config/unicorn.conf.rb -E production -D

を実行したところ、

/usr/local/bundle/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:592:in `working_directory': config_file=config/unicorn.conf.rb would not be accessible in working_directory=/var/www/caleapp (ArgumentError)
master failed to start, check stderr log for details

このようなエラーが出てしまいます。

var/www/caleapp/config/unicorn.conf.rb の内容

  # set lets
  $worker  = 2
  $timeout = 30
  $app_dir = "/var/www/caleapp"
  $listen  = File.expand_path 'tmp/sockets/.unicorn.sock', $app_dir
  $pid     = File.expand_path 'tmp/pids/unicorn.pid', $app_dir
  $std_log = File.expand_path 'log/unicorn.log', $app_dir
  # set config
  worker_processes  $worker
  working_directory $app_dir
  stderr_path $std_log
  stdout_path $std_log
  timeout $timeout
  listen  $listen
  pid $pid
  # loading booster
  preload_app true
  # before starting processes
  before_fork do |server, worker|
    defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
    old_pid = "#{server.config[:pid]}.oldbin"
    if old_pid != server.pid
      begin
        Process.kill "QUIT", File.read(old_pid).to_i
      rescue Errno::ENOENT, Errno::ESRCH
      end
    end
  end
  # after finishing processes
  after_fork do |server, worker|
    defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
  end
~                                                                                                                                                                       ~                           

自分で試したこと

bundle exec unicorn_rails -c config/unicorn.conf.rb -E production -D

bundle exec をつけて実行しましたが、結果変わらず。

stderr logを確認しようにも
なぜかunicornのものがlogファイル内にありません。

[shota@ip-10-0-0-190 log]$ dir
development.log  nginx.access.log  nginx.error.log  production.log

補足

Rails 6.0.3.4
ruby 2.6.6p146
unicorn_rails v5.4.1

参考記事にはありませんがDocker-composeを使ってます。
docker-compose runではなく、
docker-compose exec web bashでrailsに入った上で実行してます。
(runで実行してもエラーになりました)

0

1Answer

/usr/local/bundle/gems/unicorn-5.4.1/lib/unicorn/configurator.rb:592:in `working_directory': config_file=config/unicorn.conf.rb would not be accessible in working_directory=/var/www/caleapp (ArgumentError)

would not be accessible と言っているので, config/unicorn.conf.rb ファイルのパーミッションを調べてみるのはどうでしょうか?

0

Comments

  1. @shotam27

    Questioner
    回答ありがとうございます!
    config/unicorn.conf.rb のパーミッションを確認したところ
    -rw-rw-r-- となっていたので、
    試しにchmod 777で-rwxrwxrwxに変更して実行しましたが
    同じエラーが出てきてしまいます。
  2. `config` ディレクトリには,読み取り / 実行権限はありますか?

    `unicorn` の実行ユーザで確認すると良いかと思います.
  3. @shotam27

    Questioner
    うまくいきました!
    理由はわかりませんが
    unicorn.conf.rb → unicorn.rb
    に修正して中身を変更したところ動くようになりました。
  4. 解決したなら良かったです

Your answer might help someone💌