Class: TaskJuggler::WebServer
- Includes:
- DaemonConnectorMixin
- Defined in:
- lib/taskjuggler/daemon/WebServer.rb
Overview
The WebServer class provides a self-contained HTTP server that can serve HTML versions of Report objects that are generated on the fly.
Instance Attribute Summary collapse
-
#authKey ⇒ Object
Returns the value of attribute authKey.
-
#port ⇒ Object
Returns the value of attribute port.
-
#uriFile ⇒ Object
Returns the value of attribute uriFile.
-
#webServerPort ⇒ Object
Returns the value of attribute webServerPort.
Attributes inherited from Daemon
Instance Method Summary collapse
-
#initialize ⇒ WebServer
constructor
Create a web server object that runs in a separate thread.
- #start ⇒ Object
-
#stop ⇒ Object
Stop the web server.
Methods included from DaemonConnectorMixin
#connectDaemon, #disconnectDaemon
Methods included from MessageHandler
#critical, #debug, #error, #fatal, #info, #warning
Constructor Details
#initialize ⇒ WebServer
Create a web server object that runs in a separate thread.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/taskjuggler/daemon/WebServer.rb', line 33 def initialize super # For security reasons, this will probably not change. All DRb # operations are limited to localhost only. The client and the sever # must have access to the identical file system. @host = '127.0.0.1' # The default TCP/IP port. ASCII code decimals for 'T' and 'J'. @port = 8474 # The file with the server URI in case port is 0. @uriFile = File.join(Dir.getwd, '.tj3d.uri') # We don't have a default key. The user must provice a key in the config # file. Otherwise the daemon will not start. @authKey = nil # Reference to WEBrick object. @webServer = nil # Port used by the web server @webServerPort = 8080 Kernel.trap('TERM') do debug('webserver_term_signal', 'TERM signal received. Exiting...') # When the OS sends us a TERM signal, we try to exit gracefully. stop end end |
Instance Attribute Details
#authKey ⇒ Object
Returns the value of attribute authKey.
30 31 32 |
# File 'lib/taskjuggler/daemon/WebServer.rb', line 30 def authKey @authKey end |
#port ⇒ Object
Returns the value of attribute port.
30 31 32 |
# File 'lib/taskjuggler/daemon/WebServer.rb', line 30 def port @port end |
#uriFile ⇒ Object
Returns the value of attribute uriFile.
30 31 32 |
# File 'lib/taskjuggler/daemon/WebServer.rb', line 30 def uriFile @uriFile end |
#webServerPort ⇒ Object
Returns the value of attribute webServerPort.
30 31 32 |
# File 'lib/taskjuggler/daemon/WebServer.rb', line 30 def webServerPort @webServerPort end |
Instance Method Details
#start ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 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 |
# File 'lib/taskjuggler/daemon/WebServer.rb', line 60 def start # In daemon mode, we fork twice and only the 2nd child continues here. super() debug('', "Starting web server") config = { :Port => @webServerPort } begin @server = WEBrick::HTTPServer.new(config) info('webserver_port', "Web server is listening on port #{@webServerPort}") rescue fatal('webrick_start_failed', "Cannot start WEBrick: #{$!}") end begin @server.mount('/', WelcomePage, nil) rescue fatal('welcome_page_mount_failed', "Cannot mount WEBrick welcome page: #{$!}") end begin @server.mount('/taskjuggler', ReportServlet, [ @authKey, @host, @port, @uri ]) rescue fatal('broker_page_mount_failed', "Cannot mount WEBrick broker page: #{$!}") end # Serve some directories via the FileHandler servlet. %w( css icons scripts ).each do |dir| unless (fullDir = AppConfig.dataDirs("data/#{dir}")[0]) error('dir_not_found', <<"EOT" Cannot find the #{dir} directory. This is usually the result of an improper TaskJuggler installation. If you know the directory, you can use the TASKJUGGLER_DATA_PATH environment variable to specify the location. The variable should be set to the path without the /data at the end. Multiple directories must be separated by colons. EOT ) end begin @server.mount("/#{dir}", WEBrick::HTTPServlet::FileHandler, fullDir) rescue fatal('dir_mount_failed', "Cannot mount directory #{dir} in WEBrick: #{$!}") end end # Install signal handler to exit gracefully on CTRL-C. intHandler = Kernel.trap('INT') do stop end begin @server.start rescue fatal('web_server_error', "Web server error: #{$!}") end end |
#stop ⇒ Object
Stop the web server.
123 124 125 126 127 128 129 |
# File 'lib/taskjuggler/daemon/WebServer.rb', line 123 def stop if @server @server.shutdown @server = nil end super end |