unicornがunicorn.pid not writable (ArgumentError)エラーで起動できない
bundle exec unicorn -E production -c config/unicorn.rb -D
で起動できない。
ps aux | grep unicornしてもプロセスは起動していない。
pidファイルも残ってない。
エラー
/home/username/appname/vendor/bundle/ruby/2.0.0/gems/unicorn-5.1.0/lib/unicorn/configurator.rb:88:in `block in reload': directory for pid=/home/username/appname/tmp/unicorn.pid not writable (ArgumentError)
from /home/username/appname/vendor/bundle/ruby/2.0.0/gems/unicorn-5.1.0/lib/unicorn/configurator.rb:84:in `each'
from /home/username/appname/vendor/bundle/ruby/2.0.0/gems/unicorn-5.1.0/lib/unicorn/configurator.rb:84:in `reload'
from /home/username/appname/vendor/bundle/ruby/2.0.0/gems/unicorn-5.1.0/lib/unicorn/configurator.rb:65:in `initialize'
from /home/username/appname/vendor/bundle/ruby/2.0.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:76:in `new'
from /home/username/appname/vendor/bundle/ruby/2.0.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:76:in `initialize'
from /home/username/appname/vendor/bundle/ruby/2.0.0/gems/unicorn-5.1.0/bin/unicorn:126:in `new'
from /home/username/appname/vendor/bundle/ruby/2.0.0/gems/unicorn-5.1.0/bin/unicorn:126:in `<top (required)>'
from /home/username/appname/vendor/bundle/ruby/2.0.0/bin/unicorn:23:in `load'
from /home/username/appname/vendor/bundle/ruby/2.0.0/bin/unicorn:23:in `<main>'
master failed to start, check stderr log for details
unicorn.rb
一応
rails_root = File.expand_path('../../', __FILE__)
worker_processes 2
working_directory rails_root
listen "#{rails_root}/tmp/unicorn.sock"
pid "#{rails_root}/tmp/unicorn.pid"
stderr_path "#{rails_root}/log/unicorn_error.log"
stdout_path "#{rails_root}/log/unicorn.log"
解決方法=>suでrootユーザーで実行
su
パスワード:XXXXXXX
でrootユーザーになったら
bundle exec unicorn -E production -c config/unicorn.rb -D
が実行できた。
まとめ
エラーで検索したら、unicorn.sockが存在しないからダメって回答しているサイトがあったけど、そもそも勝手に作られるしあんまり関係ないのかなと思う。実際sock作っても解決しなかった。
suでrootユーザーにならないと実行できなくなった理由は不明、、、