Last active
August 17, 2020 17:51
-
-
Save KonnorRogers/9a67307ce332bf7b197e6c852e455528 to your computer and use it in GitHub Desktop.
Check if a port is being used.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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