Sha256: 402629c4d39eab63a00730bf9cc7902094a7f398608bb2ce99c36f28aee7690a
Contents?: true
Size: 1.33 KB
Versions: 2
Compression:
Stored size: 1.33 KB
Contents
require 'socket' require 'timeout' module Orats module Commands module New module Server def server_start @options[:skip_server_start] ? message = 'Start your' : message = 'Starting' puts '', '='*80 log_status_top 'action', "#{message} server with the following commands", :cyan log_status_bottom 'command', "cd #{@active_path}", :magenta, true log_status_bottom 'command', 'bundle exec foreman start', :magenta puts '='*80, '' attempt_to_start end private def attempt_to_start while port_taken? do log_status_top 'error', "Another application is using port 3000\n", :red exit 1 if no?('Would you like to try running the server again? (y/N)', :cyan) end puts run_from @active_path, 'bundle exec foreman start' end def port_taken? begin Timeout::timeout(5) do begin s = TCPSocket.new('localhost', 3000) s.close return true rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH return false end end rescue Timeout::Error false end false end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
orats-0.6.4 | lib/orats/commands/new/server.rb |
orats-0.6.3 | lib/orats/commands/new/server.rb |