Revision 75cbe7fd

View differences:

src/cloud/ec2/bin/econe-server
1
#! /bin/sh
1
#! /bin/sh -xv
2 2

  
3 3
# -------------------------------------------------------------------------- #
4 4
# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org)             #
src/cloud/ec2/lib/econe-server.rb
43 43

  
44 44
require 'EC2QueryServer'
45 45

  
46
require 'socket'
47
require 'timeout'
48

  
46 49
include OpenNebula
47 50

  
48 51
$econe_server = EC2QueryServer.new(CONFIGURATION_FILE,
49 52
    TEMPLATE_LOCATION, VIEWS_LOCATION)
50 53

  
54
def is_port_open?(ip, port)
55
  begin
56
    Timeout::timeout(1) do
57
      begin
58
        s = TCPSocket.new(ip, port)
59
        s.close
60
        return true
61
      rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
62
        return false
63
      end
64
    end
65
  rescue Timeout::Error
66
  end
67

  
68
  return false
69
end
70

  
71
if is_port_open?($econe_server.config[:server], $econe_server.config[:port])
72
    puts "Port busy, please shutdown the service or move econe server port."
73
    exit
74
end
75

  
51 76
##############################################################################
52 77
# Sinatra Configuration
53 78
##############################################################################

Also available in: Unified diff