0%

Rails 4 unicorn 8080 无法启动解决方法

新站上线,无法启动,提示8080端口被占用,下面这两种方法都不能关闭8080的ruby端口。

将私钥传入,要注册的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
I, [2015-09-06T11:18:31.745020 #15908]  INFO -- : Refreshing Gem list
I, [2015-09-06T11:18:34.940713 #15908] INFO -- : listening on addr=/home/wwwroot/rails/xxx/.unicorn.sock fd=12
E, [2015-09-06T11:18:34.941792 #15908] ERROR -- : adding listener failed addr=0.0.0.0:8080 (in use)
E, [2015-09-06T11:18:34.941856 #15908] ERROR -- : retrying in 0.5 seconds (4 tries left)
E, [2015-09-06T11:18:35.442229 #15908] ERROR -- : adding listener failed addr=0.0.0.0:8080 (in use)
E, [2015-09-06T11:18:35.442379 #15908] ERROR -- : retrying in 0.5 seconds (3 tries left)
E, [2015-09-06T11:18:35.942744 #15908] ERROR -- : adding listener failed addr=0.0.0.0:8080 (in use)
E, [2015-09-06T11:18:35.942888 #15908] ERROR -- : retrying in 0.5 seconds (2 tries left)
E, [2015-09-06T11:18:36.443246 #15908] ERROR -- : adding listener failed addr=0.0.0.0:8080 (in use)
E, [2015-09-06T11:18:36.443387 #15908] ERROR -- : retrying in 0.5 seconds (1 tries left)
E, [2015-09-06T11:18:36.943768 #15908] ERROR -- : adding listener failed addr=0.0.0.0:8080 (in use)
E, [2015-09-06T11:18:36.952894 #15908] ERROR -- : retrying in 0.5 seconds (0 tries left)
E, [2015-09-06T11:18:37.453366 #15908] ERROR -- : adding listener failed addr=0.0.0.0:8080 (in use)
/usr/local/rvm/gems/ruby-2.2.3/gems/unicorn-4.9.0/lib/unicorn/socket_helper.rb:185:in `bind': Address already in use - bind(2) for 0.0.0.0:8080 (Errno::EADDRINUSE)
from /usr/local/rvm/gems/ruby-2.2.3/gems/unicorn-4.9.0/lib/unicorn/socket_helper.rb:185:in `new_tcp_server'
from /usr/local/rvm/gems/ruby-2.2.3/gems/unicorn-4.9.0/lib/unicorn/socket_helper.rb:165:in `bind_listen'
from /usr/local/rvm/gems/ruby-2.2.3/gems/unicorn-4.9.0/lib/unicorn/http_server.rb:242:in `listen'
from /usr/local/rvm/gems/ruby-2.2.3/gems/unicorn-4.9.0/lib/unicorn/http_server.rb:813:in `block in bind_new_listeners!'
from /usr/local/rvm/gems/ruby-2.2.3/gems/unicorn-4.9.0/lib/unicorn/http_server.rb:813:in `each'
from /usr/local/rvm/gems/ruby-2.2.3/gems/unicorn-4.9.0/lib/unicorn/http_server.rb:813:in `bind_new_listeners!'
from /usr/local/rvm/gems/ruby-2.2.3/gems/unicorn-4.9.0/lib/unicorn/http_server.rb:138:in `start'
from /usr/local/rvm/gems/ruby-2.2.3/gems/unicorn-4.9.0/bin/unicorn_rails:209:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.2.3/bin/unicorn_rails:23:in `load'
from /usr/local/rvm/gems/ruby-2.2.3/bin/unicorn_rails:23:in `<main>'
from /usr/local/rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `eval'
from /usr/local/rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `<main>'
1
2
ps aux | grep unicron
sudo netstat -lpn |grep :8080
1
2
rake assets:precompile RAILS_ENV=production
RAILS_ENV=production bundle exec unicorn_rails -c config/unicorn.rb -E production -D

解决方法

1
lsof -i:8080

This will give the app that occupies it.
If apache, stop it using:

1
sudo /etc/init.d/apache2 stop

If nginx, stop it using:

1
sudo nginx -s stop