Created
October 2, 2014 21:49
-
-
Save doughsay/4989697f2f2877991d22 to your computer and use it in GitHub Desktop.
Continuously listen for remote-pry sessions.
This file contains hidden or 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' | |
require 'timeout' | |
def is_port_open?(ip, port) | |
begin | |
Timeout::timeout(1) do | |
begin | |
s = TCPSocket.new(ip, port) | |
s.close | |
return true | |
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH | |
return false | |
end | |
end | |
rescue Timeout::Error | |
end | |
return false | |
end | |
puts 'Waiting for remote pry session to be available on port 9876' | |
while true do | |
if is_port_open?('127.0.0.1', 9876) | |
system('pry-remote') | |
puts 'Waiting for remote pry session to be available on port 9876' | |
else | |
sleep 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment