def Iowa.checkConfiguration
raise "A socket specification must be provided in the configuration file." unless @@config.has_key? 'socket'
raise "Iowa supports both TCP and Unix domain sockets. Please specify the socket to use within the 'socket' section of the configuration file." unless (@@config['socket'].class.to_s == 'Hash' and (@@config['socket'].has_key? 'path' or @@config['socket'].has_key? 'port'))
raise "Please define only one of a TCP or a Unix domain socket in the configuration file." if @@config['socket'].has_key? 'path' and @@config['socket'].has_key? 'port'
raise "The socket hostname contains illegal characters." unless @@config['socket'].has_key? 'hostname' and @@config['socket']['hostname'] =~ /^[a-zA-Z0-9\.\-]*$/
if @@config['socket'].has_key? 'path'
begin
File.unlink @@config['socket']['path'] if FileTest.exist? @@config['socket']['path']
sf = File.open(@@config['socket']['path'],'w')
@@config['socket']['basename'] = File.basename(@@config['socket']['path'])
sf.close
File.unlink @@config['socket']['path']
rescue Exception => exception
puts "The path for a Unix socket must be writeable."
raise
end
end
if @@config.has_key? 'logging'
if @@config['logging'].has_key? 'basedir'
raise "The logging basedir (#{@@config['logging']['basedir']}) must be a directory." unless FileTest.directory? @@config['logging']['basedir']
raise "The logging basedir #{@@config['logging']['basedir']}) must be writeable." unless FileTest.writable? @@config['logging']['basedir']
end
raise "The minimum logging level (minlevel) must be an integer between 0 to 7, inclusively." if @@config['logging'].has_key? 'minlevel' and (@@config['logging']['minlevel'] < 0 or @@config['logging']['minlevel'] > 7)
raise "The maximum log file size (maxsize) must be greater than zero." if @@config.has_key? 'maxsize' and @@config['maxsize'] <= 0
raise "The maximum log file age (maxage) must be greater than zero." if @@config.has_key? 'maxage' and @@config['maxage'] <= 0
end
@@config['logging'] = Hash.new unless @@config.has_key? 'logging'
@@config['logging']['basedir'] = '/tmp' unless @@config['logging'].has_key? 'basedir'
@@config['logging']['minlevel'] = 'info' unless @@config['logging'].has_key? 'minlevel'
@@config['logging']['maxsize'] = 1024 * 1024 unless @@config['logging'].has_key? 'maxsize'
@@config['logging']['maxage'] = 86400 unless @@config['logging'].has_key? 'maxage'
if @@config['socket'].has_key? 'path'
@@config['logging']['filename'] = "#{@@config['logging']['basedir']}/#{@@config['socket']['basename']}.log"
else
@@config['logging']['filename'] = "#{@@config['logging']['basedir']}/#{@@config['socket']['hostname']}:#{@@config['socket']['port']}.log"
end
end