require 'flydata/command_loggable' require 'flydata-core/errors' module Flydata class CompatibilityCheck include CommandLoggable def initialize(dp_hash, de_hash=nil, options={}) @dp = dp_hash @errors=[] end def check self.methods.grep(/^check_/).each do |m| begin send(m) rescue ArgumentError => e # ignore rescue FlydataCore::CompatibilityError => e @errors << e end end print_errors end def print_errors return if @errors.empty? log_error_stderr "There may be some compatibility issues with this current server : " @errors.each do |error| log_error_stderr " * #{error.message}" end raise "Please correct these errors if you wish to run FlyData Agent" end end # Collection of checks for initial sync module InitialSyncChecks # Checks permission of @dump_dir and @backup_dir # # Requires # @dump_dir # @backup_dir def check_writing_permissions write_errors = [] paths_to_check = [FLYDATA_HOME] paths_to_check << @dump_dir unless @dump_dir.to_s.empty? paths_to_check << @backup_dir unless @backup_dir.to_s.empty? paths_to_check.each do |path| full_path = File.expand_path(path) full_path = File.dirname(full_path) unless File.directory?(full_path) write_errors << full_path unless File.writable?(full_path) and File.executable?(full_path) end unless write_errors.empty? error_dir = write_errors.join(", ") raise FlydataCore::CompatibilityError, "We cannot access the directories: #{error_dir}" end end end class AgentCompatibilityCheck < CompatibilityCheck TCP_PORT=45326 SSL_PORT=45327 def check_outgoing_ports ports = [TCP_PORT] ports << SSL_PORT unless ENV['FLYDATA_ENV_KEY'] == 'development' url = @dp["servers"].first errors = {} ports.each do |port| begin e = TCPSocket.new(url, port) e.close rescue => e errors[port] = e end end unless errors.empty? message = "Cannot connect to outside ports. Please check to make sure you have these outgoing ports open." errors.each do |port, e| message += " Port #{port}, Error #{e.class.name}: #{e.to_s}" end raise FlydataCore::AgentCompatibilityError, message end end end end