Address already in use - bind(2) (Errno::EADDRINUSE)

前端 未结 7 490
你的背包
你的背包 2020-12-04 04:47

I am trying to deploy Rails app with the Puma web server. When trying to start Puma server with a config file bundle exec puma -C config/puma.rb I get an error

相关标签:
7条回答
  • 2020-12-04 05:27

    You can find and kill the running processes: ps aux | grep puma Then you can kill it with kill PID

    0 讨论(0)
  • 2020-12-04 05:29

    It might be old but in my case, it was because of docker. Hope it will help others.

    0 讨论(0)
  • 2020-12-04 05:32

    To kill the puma process first run

        lsof -wni tcp:3000 
    

    to show what is using port 3000. Then use the PID that comes with the result to run the kill process.

    For example after running lsof -wni tcp:3000 you might get something like

        COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
        ruby    3366 dummy    8u  IPv4  16901      0t0  TCP 127.0.0.1:3000 (LISTEN)
    

    Now run the following to kill the process. (where 3366 is the PID)

    kill -9 3366
    

    Should resolve the issue

    0 讨论(0)
  • 2020-12-04 05:36

    You need to use kill -9 59780 with 59780 replaced with found PID number (use lsof -wni tcp:3000 to see which process used 3000 port and get the process PID).

    Or you can just modify your puma config change the tcp port tcp://127.0.0.1:3000 from 3000 to 9292 or other port that not been used.

    Or you can start your rails app by using:

    bundle exec puma -C config/puma.rb -b tcp://127.0.0.1:3001
    
    0 讨论(0)
  • 2020-12-04 05:38

    you can also try this trick:

    ps aux | grep puma
    

    sample output:

    myname           77921   0.0  0.0  2433828   1972 s000  R+   11:17AM   0:00.00 grep puma
    myname           67661   0.0  2.3  2680504 191204 s002  S+   11:00AM   0:18.38 puma 3.11.2 (tcp://localhost:3000) [my_proj]
    

    then:

    kill -9 67661
    
    0 讨论(0)
  • 2020-12-04 05:42

    Found the script below in this github issue. Works great for me.

    #!/usr/bin/env ruby
    port = ARGV.first || 3000
    system("sudo echo kill-server-on #{port}")
    
    pid = `sudo lsof -iTCP -sTCP:LISTEN -n -P | grep #{port} | awk '{ print $2 }' | head -n 1`.strip
    puts "PID: #{pid}"
    `kill -9 #{pid}` unless pid.empty?
    

    You can either run it in irb or inside a ruby file.

    For the latter, create server_killer.rb then run it with ruby server_killer.rb

    0 讨论(0)
提交回复
热议问题