Class Dsadmin::Webfe::WebFrontend
In: lib/dsadmin/webfe/WebFrontend.rb
Parent: Object

The "main" class of the dsadmin web frontend.

This handles mostly startup and shutdown, and kicks off the processing between those.

Methods

Included Modules

Dsadmin::Contractor

Constants

ConfigSection = Dsadmin::ConfigSection   convenience alias
ConfigValue = Dsadmin::ConfigValue   convenience alias

Attributes

cfg  [R] 
log  [R] 
sys  [R] 

Public Class methods

[Source]

     # File lib/dsadmin/webfe/WebFrontend.rb, line 103
103:       def initialize()
104:         @in_shutdown = false
105:         @running     = false
106:         
107:         @sys = Dsadmin::System.instance
108:       end

Public Instance methods

[Source]

    # File lib/dsadmin/webfe/WebFrontend.rb, line 43
43:       def run(options)
44:         return if @running
45:         return if @in_shutdown
46:         @running = true
47:         
48:         startCoreServices(options)
49:         
50:         daemonize if options.do_daemonize
51:         initSigHandler
52:         
53:         startWebrick(options)
54:         
55:         # If we're already shutting down, keep running until shutdown()
56:         # calls exit(). Otherwise call shutdown(). This ensures that we
57:         # always exit properly via shutdown().
58:         # Actually, we only wait for at most 120 seconds for the background
59:         # shutdown to finish -- if it takes longer, something's gone wrong
60:         # and we do an abnormal exit.
61:         if(@in_shutdown)
62:           sleep(120)
63:           exit(1)
64:         else
65:           shutdown
66:           exit(0)
67:         end
68:       end

[Source]

    # File lib/dsadmin/webfe/WebFrontend.rb, line 72
72:       def shutdown()
73:         return if @in_shutdown
74:         return unless @running
75:         @in_shutdown = true
76:         @running     = false
77:         
78:         log.notice("Shutting down ...")
79:         
80:         shutdownWebrick
81:         shutdownCoreServices
82:       end

Private Instance methods

[Source]

     # File lib/dsadmin/webfe/WebFrontend.rb, line 211
211:       def daemonize()
212:         if (fork() != nil)
213:           # end parent process
214:           #$stderr.puts("Exiting parent")
215:           exit
216:         end
217:         
218:         # A little delay to allow the parent process to exit. Not
219:         # strictly necessary, but IMHO safer
220:         sleep(0.2)
221:         
222:         #$stderr.puts("Starting child")
223:         Process.setsid()
224:         Dir.chdir("/")
225:         File.umask(0)
226:       end

[Source]

     # File lib/dsadmin/webfe/WebFrontend.rb, line 180
180:       def getSSLConfig
181:         csect = cfg.net_config.ssl
182:         return Hash.new unless csect
183:         
184:         use_ssl = csect.enable
185:         return Hash.new unless(use_ssl && use_ssl.to_b)
186:         
187:         config = Hash.new
188:         config[:SSLEnable] = true
189:         config[:SSLVerifyClient] = ::OpenSSL::SSL::VERIFY_NONE
190:         
191:         certsect   = csect.get('certificate', String)
192:         cacertsect = csect.ca_certificate
193:         pkeysect   = csect.get('private_key', String)
194:         
195:         certpath = cfg.localpath(certsect)
196:         cert = File.open(certpath) { |file| file.read }
197:         config[:SSLCertificate] = ::OpenSSL::X509::Certificate.new(cert)
198:         
199:         pkeypath = cfg.localpath(pkeysect)
200:         pkey = File.open(pkeypath) { |file| file.read }
201:         config[:SSLPrivateKey] = ::OpenSSL::PKey::RSA.new(pkey)
202:         
203:         if(cacertsect)
204:           config[:SSLCACertificateFile] = cacertsect
205:         end
206:         
207:         return config
208:       end

[Source]

     # File lib/dsadmin/webfe/WebFrontend.rb, line 141
141:       def initServlets
142:         @webrick.mount("/", DispatchServlet)
143:       end

[Source]

     # File lib/dsadmin/webfe/WebFrontend.rb, line 135
135:       def initSigHandler
136:         Kernel.trap("TERM") { self.shutdown ; exit(0) }
137:         Kernel.trap("INT")  { self.shutdown ; exit(0) }
138:       end

[Source]

     # File lib/dsadmin/webfe/WebFrontend.rb, line 130
130:       def shutdownCoreServices
131:         @log.shutdown
132:       end

[Source]

     # File lib/dsadmin/webfe/WebFrontend.rb, line 174
174:       def shutdownWebrick
175:         @webrick.shutdown
176:         @wlog.shutdown
177:       end

[Source]

     # File lib/dsadmin/webfe/WebFrontend.rb, line 111
111:       def startCoreServices(options)
112:         begin
113:           ConfigManager.setup(options.cfgfile || 'config/webfe.xml')
114:           @cfg = ConfigManager.instance
115:         rescue StandardError => xcept
116:           $stderr.puts("Unable to read config file: " + xcept.message)
117:           exit(-1)
118:         end
119:         
120:         begin
121:           @log = Dsadmin::Logger.instance
122:           @log.run
123:         rescue StandardError => xcept
124:           $stderr.puts("Unable to initialize logger: " + xcept.message)
125:           exit(-2)
126:         end
127:       end

[Source]

     # File lib/dsadmin/webfe/WebFrontend.rb, line 146
146:       def startWebrick(options)
147:         @wlog = LoggerAdapter.new(WEBrick::Log::DEBUG)
148:         alog_stream = log.getAccesslogStream
149:         host = cfg.root.net.listen.host      || options.ip
150:         port = cfg.root.net.listen.port.to_i || options.port
151:         
152:         config = {
153:           :Port        => port,
154:           :BindAddress => host,
155:           :Logger      => @wlog,
156:           :AccessLog   => [[alog_stream, WEBrick::AccessLog::COMBINED_LOG_FORMAT]]
157:         }
158:         
159:         config = config.merge(getSSLConfig)
160:         
161:         @webrick = WEBrick::HTTPServer.new(config)
162:         
163:         initServlets
164:         
165:         # No idea why this has to be in a seperate thread, but otherwise
166:         # it hangs at shutdown...
167:         wr_thread = Thread.new { @webrick.start }
168:         
169:         sys.dropPrivileges if(Process.uid == 0)
170:         wr_thread.join
171:       end

[Validate]