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

前端 未结 7 512
你的背包
你的背包 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: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

提交回复
热议问题