Unicornを起動するコマンド
$ bundle exec unicorn -E production -c unicorn.rb -D
でエラーを吐いてハマったのでメモ。
エラーログ
/home/username/appname/vendor/bundle/ruby/2.3.0/gems/unicorn-5.4.0/lib/unicorn/configurator.rb:100:in `block in reload': directory for pid=/home/username/appname/tmp/pids/unicorn.pid not writable (ArgumentError)
from /home/username/appname/vendor/bundle/ruby/2.3.0/gems/unicorn-5.4.0/lib/unicorn/configurator.rb:96:in `each'
from /home/username/appname/vendor/bundle/ruby/2.3.0/gems/unicorn-5.4.0/lib/unicorn/configurator.rb:96:in `reload'
from /home/username/appname/vendor/bundle/ruby/2.3.0/gems/unicorn-5.4.0/lib/unicorn/configurator.rb:77:in `initialize'
from /home/username/appname/vendor/bundle/ruby/2.3.0/gems/unicorn-5.4.0/lib/unicorn/http_server.rb:77:in `new'
from /home/username/appname/vendor/bundle/ruby/2.3.0/gems/unicorn-5.4.0/lib/unicorn/http_server.rb:77:in `initialize'
from /home/username/appname/vendor/bundle/ruby/2.3.0/gems/unicorn-5.4.0/bin/unicorn:126:in `new'
from /home/username/appname/vendor/bundle/ruby/2.3.0/gems/unicorn-5.4.0/bin/unicorn:126:in `'
from /home/username/appname/vendor/bundle/ruby/2.3.0/bin/unicorn:22:in `load'
from /home/username/appname/vendor/bundle/ruby/2.3.0/bin/unicorn:22:in `'
master failed to start, check stderr log for details
重要なのはdirectory for pid=/home/username/appname/tmp/pids/unicorn.pid not writable (ArgumentError)
のところ。
ぱっと見、unicorn.pid
を書き込む権限がないんだろうな~って思ったが、パーミッション設定みてもきちんとusernameになっているし、他のサイトにあるようにroot権限でUnicornを起動しようとしても全く同じエラーが出るのでだいぶハマった。
解決策
ディレクトリ(appname/tmp/pid)を作る。
$ mkdir tmp
$ cd tmp
$ mkdir pid
$ cd tmp
$ mkdir pid
として
$ bundle exec unicorn -E production -c unicorn.rb -D
を実行。すんなり起動できた。
ハマってた時間はなんだったんだ…