Class GlassFish::Config
In: lib/config.rb
lib/gfraker.rb
Parent: Object

Methods

Constants

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"

Public Class methods

[Source]

     # File lib/config.rb, line 184
184:     def self.absolutize(base, path)
185:       if path.nil?
186:         return nil
187:       end
188:       p = Pathname.new path
189:       if(!p.absolute?)
190:         path = File.join(base, path)
191:       end
192:       path
193:     end

[Source]

     # File lib/config.rb, line 178
178:     def self.fail(message)
179:       STDERR.puts "ERROR: #{message}"
180:       STDERR.puts "Type 'glassfish -h' to get help"
181:       Kernel.exit -1
182:     end

[Source]

    # File lib/config.rb, line 48
48:     def self.init_opts
49:       {
50:         :runtimes     => 1,
51:         :runtimes_min => 1,
52:         :runtimes_max => 1,
53:         :contextroot  => '/',
54:         :environment  => "development",
55:         :app_dir      => Dir.pwd,
56:         :port         => 3000,
57:         :address      => "0.0.0.0",
58:         :pid          => nil,
59:         :log          => nil,
60:         :log_console  => false,
61:         :log_level    => 3,
62:         :daemon       => false,
63:         :jvm_options  => nil        
64:       }
65:     end

Public Instance methods

Validates the configuration options. If it can will revert to default else fail

[Source]

     # File lib/config.rb, line 70
 70:     def validate! config
 71:       # http configuration
 72:       # port
 73:       begin
 74:         server = TCPServer.new config[:port]
 75:       rescue
 76:         STDERR.puts "#{config[:address]}:#{config[:port]}: " + $!
 77:         #TODO: we should give an option of ephemeral port support
 78:         exit(1)
 79:       end
 80:       server.close
 81: 
 82:       # daemon
 83:       if(config[:daemon])
 84:         os = java.lang.System.getProperty("os.name").downcase
 85:         version = java.lang.System.getProperty("os.version")
 86:         #check the platform, Currently daemon mode works only on linux and
 87:         #solaris
 88:         if(!os.include?("linux") and !os.include?("sunos"))
 89:           Config.fail "You are running on #{java.lang.System.getProperty("os.name")}  #{version}. Currently daemon mode only works on Linux or Solaris platforms!"
 90:         end
 91: 
 92:         # In daemon mode you can't log to console. Let's fail and let user spcifiy the log file explicitly
 93:               if(config[:log_console])
 94:                 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."
 95:         end
 96: 
 97: 
 98:         if(config[:jvm_options].nil?)
 99:           config[:jvm_options] = DEFAULT_JVM_OPTS
100:         end
101:         if(config[:pid].nil?)
102:           config[:pid] = PID_FILE
103:               end
104: 
105:         Config.absolutize config[:app_dir], config[:pid]
106:       end
107: 
108:       # log_level
109:       if not (0..7).include?(config[:log_level])
110:         STDERR.puts "Invalid log level #{config[:log_level]}. Chose a number between 0 to 7."
111:         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"
112:       end
113: 
114:       if config[:runtimes] > config[:runtimes_max]
115:         puts "Initial number of runtimes #{config[:runtimes]} is > max runtime #{config[:runtimes_max]}.\nIncreasing runtimes-max to #{config[:runtimes]}"
116:         config[:runtimes_max] = config[:runtimes]
117:       end
118: 
119:       # JRuby runtime
120:       runtimes_err = " Invalid runtime configuration, initial:#{config[:runtimes]}, min:#{config[:runtimes_min]}, max:#{config[:runtimes_max]}."
121:       err = false
122:       if(config[:runtimes] < 1 || config[:runtimes] > config[:runtimes_max] || config[:runtimes] < config[:runtimes_min])
123:         err = true;
124:         runtimes_err +=  "\n\tinitial runtime must be > 0, <= runtimes-max and >= runtimes-min."
125:       end
126:       if(config[:runtimes_min] < 1 || config[:runtimes_min] > config[:runtimes] || config[:runtimes_min] > config[:runtimes_max])
127:         err = true;
128:         runtimes_err += "\n\truntimes-min must be > 0, <=runtimes-max and <= initial_runtmes"
129:       end
130:       if(config[:runtimes_max] < 1 || config[:runtimes_max] < config[:runtimes_min] || config[:runtimes_max] < config[:runtimes])
131:         err=true
132:         runtimes_err += "\n\truntimes-max must be > 0, >=runtimes-min and >= initial_runtmes"
133:       end
134:       if(err)
135:         Config.fail runtimes_err
136:       end
137: 
138: 
139:       # contextroot
140:       # There is not much to validate here. For now we leave it as it is
141: 
142:       # log configuration
143: 
144: 
145:       # log-file
146:       if(config[:log].nil? or config[:log].empty?)
147:         config[:log] = File.join(config[:app_dir], "log", config[:environment]+".log")
148:       end
149: 
150:       if !File.exists?(config[:log]) and !config[:log_console]
151:         puts "Log file #{config[:log]} does not exist. Creating a new one..."
152:         parent = File.dirname(config[:log])
153:         if(!File.exists?parent)
154:           FileUtils.mkdir_p parent
155:         end
156:         file = File.new(config[:log], "w")
157:         file.close
158:       end
159: 
160: 
161:       # pid file
162:       #
163:       if(!config[:pid].nil? and !config[:daemon])
164:             GlassFish::Config::fail("--pid option can only be used with --daemon.")
165:       end
166: 
167:       #TODO: validate JVM options?
168: 
169:       # By this time we know all is good. Now lets create the domain directory
170:       domaindir = File.join(config[:app_dir], "tmp", ".glassfish")
171:       config[:domain_dir] = File.expand_path(domaindir)
172: 
173:       if !check_domain_dir?domaindir
174:         exit -1
175:       end
176:     end

[Validate]