事象
Unicorn+Nginx+Rails サーバが起動できない
以下のコマンドでエラーとなった
bundle exec unicorn_rails -c config/unicorn.rb -E development -D
エラー内容は以下
F, [2017-06-14T16:45:08.020588 #20655] FATAL -- : error adding listener addr=/projects/scraping/tmp/development_unicorn.sock ArgumentError: socket=/projects/scraping/tmp/development_unicorn.sock specified but it is not a socket! /projects/scraping/vendor/bundle/ruby/2.4.0/gems/unicorn-5.3.0/lib/unicorn/socket_helper.rb:131:in `bind_listen' /projects/scraping/vendor/bundle/ruby/2.4.0/gems/unicorn-5.3.0/lib/unicorn/http_server.rb:241:in `listen' /projects/scraping/vendor/bundle/ruby/2.4.0/gems/unicorn-5.3.0/lib/unicorn/http_server.rb:852:in `block in bind_new_listeners!' /projects/scraping/vendor/bundle/ruby/2.4.0/gems/unicorn-5.3.0/lib/unicorn/http_server.rb:852:in `each' /projects/scraping/vendor/bundle/ruby/2.4.0/gems/unicorn-5.3.0/lib/unicorn/http_server.rb:852:in `bind_new_listeners!' /projects/scraping/vendor/bundle/ruby/2.4.0/gems/unicorn-5.3.0/lib/unicorn/http_server.rb:140:in `start' /projects/scraping/vendor/bundle/ruby/2.4.0/gems/unicorn-5.3.0/bin/unicorn_rails:209:in `<top (required)>' /projects/scraping/vendor/bundle/ruby/2.4.0/bin/unicorn_rails:23:in `load' /projects/scraping/vendor/bundle/ruby/2.4.0/bin/unicorn_rails:23:in `<top (required)>'
原因と対処法
ソケットファイルが通常ファイルになっていた。
なので、ソケットファイルを一度削除してからunicornの起動コマンドを実行する。
ソケットファイルを確認
$ ls -l /projects/scraping/tmp/development_unicorn.sock -rw-r--r— 1 root root 0 Jun 3 18:22 /projects/scraping/tmp/development_unicorn.sock
※「s」が付いておらず、通常のファイルになっている。
一度削除し、unicornを起動
$ rm /projects/scraping/tmp/development_unicorn.sock rm: remove regular empty file ‘/projects/scraping/tmp/development_unicorn.sock’? y $ bundle exec unicorn_rails -c config/unicorn.rb -E development -D
ソケットファイルを確認
$ ls -l /projects/scraping/tmp/development_unicorn.sock srwxrwxrwx 1 root root 0 Jun 15 00:29 /projects/scraping/tmp/development_unicorn.sock
※「s」が付いていて、ソケットファイルになっている。
unicornの再起動確認
$ ps -ef | grep unicorn root 22108 21797 0 00:29 pts/0 00:00:00 tail -f /projects/scraping/log/development_unicorn_error.log root 22178 1 0 00:29 ? 00:00:00 unicorn_rails master -c config/unicorn.rb -E development -D root 22181 22178 2 00:29 ? 00:00:01 unicorn_rails worker[0] -c config/unicorn.rb -E development -D root 22183 22178 2 00:29 ? 00:00:01 unicorn_rails worker[1] -c config/unicorn.rb -E development -D root 22203 21932 0 00:30 pts/1 00:00:00 grep —color=auto unicorn $ kill -9 22178 $ ls -l /projects/scraping/tmp/development_unicorn.sock srwxrwxrwx 1 root root 0 Jun 15 00:29 /projects/scraping/tmp/development_unicorn.sock $ bundle exec unicorn_rails -c config/unicorn.rb -E development -D
※正常起動できた。
ログに下記が出たときは、
ソケットファイルのパスにソケットファイルでない何かが作成されているようです。
ArgumentError: socket=/projects/scraping/tmp/development_unicorn.sock specified but it is not a socket!
...