Class: GlassFish::Config
- Inherits:
-
Object
- Object
- GlassFish::Config
- Defined in:
- lib/config.rb,
lib/gfraker.rb
Defined Under Namespace
Classes: RakeApp
Constant Summary collapse
- LOG_LEVELS =
(0..7)
- PID_FILE =
Dir.pwd+File::SEPARATOR+"tmp"+File::SEPARATOR+"pids"+File::SEPARATOR+"glassfish"
- DEFAULT_JVM_OPTS =
"-server -Xmx512m -XX:MaxPermSize=192m -XX:NewRatio=2 -XX:+DisableExplicitGC -Dhk2.file.directory.changeIntervalTimer=6000"
- FILE =
"config/glassfish.yml"
Class Method Summary collapse
Instance Method Summary collapse
-
#validate!(config) ⇒ Object
Validates the configuration options.
Class Method Details
.absolutize(base, path) ⇒ Object
168 169 170 171 172 173 174 175 176 177 |
# File 'lib/config.rb', line 168 def self.absolutize(base, path) if path.nil? return nil end p = Pathname.new path if(!p.absolute?) path = File.join(base, path) end path end |
.fail(message) ⇒ Object
162 163 164 165 166 |
# File 'lib/config.rb', line 162 def self.fail() STDERR.puts "ERROR: #{}" STDERR.puts "Type 'glassfish -h' to get help" Kernel.exit -1 end |
.init_opts ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/config.rb', line 49 def self.init_opts { :runtimes => 1, :runtimes_min => 1, :runtimes_max => 1, :contextroot => '/', :environment => "development", :app_dir => Dir.pwd, :port => 3000, :address => "0.0.0.0", :pid => nil, :log => nil, :log_console => false, :log_level => 3, :daemon => false, :jvm_options => nil } end |
Instance Method Details
#validate!(config) ⇒ Object
Validates the configuration options. If it can will revert to default else fail
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/config.rb', line 71 def validate! config # http configuration # port begin server = TCPServer.new config[:port] rescue STDERR.puts "#{config[:address]}:#{config[:port]}: " + $! #TODO: we should give an option of ephemeral port support exit(1) end server.close # daemon if(config[:daemon]) os = java.lang.System.getProperty("os.name").downcase version = java.lang.System.getProperty("os.version") validate_os_for_daemon_support(os) # In daemon mode you can't log to console. Let's fail and let user spcifiy the log file explicitly if(config[:log_console]) Config.fail "Daemon mode detected, console logging is disabled in daemon mode. You must provide path to log file with --log|-l option in daemon mode." end if(config[:jvm_options].nil?) config[:jvm_options] = DEFAULT_JVM_OPTS end if(config[:pid].nil?) config[:pid] = PID_FILE end Config.absolutize config[:app_dir], config[:pid] end unless dir_has_app? config[:app_dir] raise RuntimeError, "#{config[:app_dir]} does not contain supported application" end # log_level if not (0..7).include?(config[:log_level]) STDERR.puts "Invalid log level #{config[:log_level]}. Chose a number between 0 to 7." Config.fail "\t0 OFF\n\t1 SEVERE \n\t2 WARNING\n\t3 INFO(default)\n\t4 FINE\n\t5 FINER\n\t6 FINEST\n\t7 ALL\n" end if config[:runtimes] > config[:runtimes_max] puts "Initial number of runtimes #{config[:runtimes]} is > max runtime #{config[:runtimes_max]}.\nIncreasing runtimes-max to #{config[:runtimes]}" config[:runtimes_max] = config[:runtimes] end validate_runtimes_params(config) # contextroot # There is not much to validate here. For now we leave it as it is # log configuration # log-file if(config[:log].nil? or config[:log].empty?) config[:log] = File.join(config[:app_dir], "log", config[:environment]+".log") end if !File.exists?(config[:log]) and !config[:log_console] puts "Log file #{config[:log]} does not exist. Creating a new one..." parent = File.dirname(config[:log]) if(!File.exists?parent) FileUtils.mkdir_p parent end file = File.new(config[:log], "w") file.close end # pid file # if(!config[:pid].nil? and !config[:daemon]) GlassFish::Config::fail("--pid option can only be used with --daemon.") end #TODO: validate JVM options? # By this time we know all is good. Now lets create the domain directory domaindir = File.join(config[:app_dir], "tmp", ".glassfish") config[:domain_dir] = File.(domaindir) if !check_domain_dir?domaindir exit -1 end end |