Skip to content

Instantly share code, notes, and snippets.

@KonnorRogers
Last active August 17, 2020 17:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KonnorRogers/9a67307ce332bf7b197e6c852e455528 to your computer and use it in GitHub Desktop.
Save KonnorRogers/9a67307ce332bf7b197e6c852e455528 to your computer and use it in GitHub Desktop.
Check if a port is being used.
require "socket"
def detect_port!
hostname = Snowpacker.config.hostname || "localhost"
port = Snowpacker.config.port || 4035
server = TCPServer.new(hostname, port)
server.close
rescue Errno::EADDRINUSE
puts "#{port} is currently being used"
exit!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment