Class: Middleman::PreviewServer
- Inherits:
-
Object
- Object
- Middleman::PreviewServer
- Extended by:
- Forwardable
- Defined in:
- middleman-core/lib/middleman-core/preview_server.rb,
middleman-core/lib/middleman-core/preview_server/checks.rb,
middleman-core/lib/middleman-core/preview_server/webrick.rb,
middleman-core/lib/middleman-core/preview_server/server_url.rb,
middleman-core/lib/middleman-core/preview_server/information.rb,
middleman-core/lib/middleman-core/preview_server/server_hostname.rb,
middleman-core/lib/middleman-core/preview_server/tcp_port_prober.rb,
middleman-core/lib/middleman-core/preview_server/server_ip_address.rb,
middleman-core/lib/middleman-core/preview_server/server_information.rb,
middleman-core/lib/middleman-core/preview_server/network_interface_inventory.rb,
middleman-core/lib/middleman-core/preview_server/server_information_validator.rb,
middleman-core/lib/middleman-core/preview_server/server_information_callback_proxy.rb
Defined Under Namespace
Modules: Checks Classes: AllInterfaces, AllIpv4Interfaces, AllIpv6Interfaces, BasicInformation, BasicServerIpAddress, BindAddressAndServerNameInformation, BindAddressInformation, DefaultInformation, NetworkInterfaceInventory, ServerHostname, ServerInformation, ServerInformationCallbackProxy, ServerInformationValidator, ServerIpAddress, ServerIpv4Address, ServerIpv6Address, ServerNameInformation, ServerNameIsIpInformation, ServerUrl, TcpPortProber, Webrick
Class Attribute Summary collapse
-
.app ⇒ Object
readonly
Returns the value of attribute app.
-
.environment ⇒ Object
readonly
Returns the value of attribute environment.
-
.server_information ⇒ Object
readonly
Returns the value of attribute server_information.
-
.ssl_information ⇒ Object
readonly
Returns the value of attribute ssl_information.
-
.web_server ⇒ Object
readonly
Returns the value of attribute web_server.
Class Method Summary collapse
-
.reload
Simply stop, then start the server.
-
.shutdown
Stop the current instance.
-
.start(options_hash = ::Middleman::EMPTY_HASH, cli_options_hash = ::Middleman::EMPTY_HASH)
Start an instance of Middleman::Application.
-
.stop
Stop web server.
- .stop_on_exit_thread ⇒ Object
Class Attribute Details
.app ⇒ Object (readonly)
Returns the value of attribute app.
16 17 18 |
# File 'middleman-core/lib/middleman-core/preview_server.rb', line 16 def app @app end |
.environment ⇒ Object (readonly)
Returns the value of attribute environment.
16 17 18 |
# File 'middleman-core/lib/middleman-core/preview_server.rb', line 16 def environment @environment end |
.server_information ⇒ Object (readonly)
Returns the value of attribute server_information.
16 17 18 |
# File 'middleman-core/lib/middleman-core/preview_server.rb', line 16 def server_information @server_information end |
.ssl_information ⇒ Object (readonly)
Returns the value of attribute ssl_information.
16 17 18 |
# File 'middleman-core/lib/middleman-core/preview_server.rb', line 16 def ssl_information @ssl_information end |
.web_server ⇒ Object (readonly)
Returns the value of attribute web_server.
16 17 18 |
# File 'middleman-core/lib/middleman-core/preview_server.rb', line 16 def web_server @web_server end |
Class Method Details
.reload
This method returns an undefined value.
Simply stop, then start the server
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'middleman-core/lib/middleman-core/preview_server.rb', line 112 def reload app.logger.info '== The Middleman is reloading' app.execute_callbacks(:reload) begin new_app = initialize_new_app rescue StandardError => e warn "Error reloading Middleman: #{e}\n#{e.backtrace.join("\n")}" app.logger.info '== The Middleman is still running the application from before the error' return end stop_webserver init_webserver(new_app) app.logger.info '== The Middleman has reloaded' web_server.start end |
.shutdown
This method returns an undefined value.
Stop the current instance
136 137 138 |
# File 'middleman-core/lib/middleman-core/preview_server.rb', line 136 def shutdown stop end |
.start(options_hash = ::Middleman::EMPTY_HASH, cli_options_hash = ::Middleman::EMPTY_HASH)
This method returns an undefined value.
Start an instance of Middleman::Application
20 21 22 23 24 25 26 27 28 29 30 31 32 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'middleman-core/lib/middleman-core/preview_server.rb', line 20 def start( = ::Middleman::EMPTY_HASH, = ::Middleman::EMPTY_HASH) # Do not buffer output, otherwise testing of output does not work $stdout.sync = true $stderr.sync = true @options = @cli_options = @server_information = ServerInformation.new @server_information.https = (@options[:https] == true) # New app evaluates the middleman configuration. Since this can be # invalid as well, we need to evaluate the configuration BEFORE # checking for validity app = initialize_new_app # And now comes the check unless server_information.valid? warn %(== Running Middleman failed: #{server_information.reason}. Please fix that and try again.) exit 1 end app.logger.debug %(== Server information is provided by #{server_information.handler}) app.logger.debug %(== The Middleman is running in "#{environment}" environment) app.logger.debug format('== The Middleman preview server is bound to %<url>s', url: ServerUrl.new(hosts: server_information.listeners, port: server_information.port, https: server_information.https?).to_bind_addresses.join(', ')) app.logger.info format('== View your site at %<url>s', url: ServerUrl.new(hosts: server_information.site_addresses, port: server_information.port, https: server_information.https?).to_urls.join(', ')) app.logger.info format('== Inspect your site configuration at %<url>s', url: ServerUrl.new(hosts: server_information.site_addresses, port: server_information.port, https: server_information.https?).to_config_urls.join(', ')) @initialized ||= false return if @initialized @initialized = true # Save the last-used @options so it may be re-used when # reloading later on. ::Middleman::Profiling.report('server_start') app.execute_callbacks(:before_server, [ServerInformationCallbackProxy.new(server_information)]) if @options[:daemon] # To output the child PID, let's make preview server a daemon by hand child_pid = fork if child_pid app.logger.info "== Middleman preview server is running in background with PID #{child_pid}" Process.detach child_pid exit 0 else $stdout.reopen('/dev/null', 'w') $stderr.reopen('/dev/null', 'w') $stdin.reopen('/dev/null', 'r') end end signals_thread = stop_on_exit_thread init_webserver(app) web_server.start signals_thread.join # wait after reload for real exit by signals end |
.stop
This method returns an undefined value.
Stop web server
100 101 102 103 104 105 106 107 108 |
# File 'middleman-core/lib/middleman-core/preview_server.rb', line 100 def stop begin app.logger.info '== The Middleman is shutting down' rescue StandardError # if the user closed their terminal STDOUT/STDERR won't exist end stop_webserver end |
.stop_on_exit_thread ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'middleman-core/lib/middleman-core/preview_server.rb', line 81 def stop_on_exit_thread signals_queue = Queue.new %w[INT HUP TERM QUIT].each do |sig| next unless Signal.list[sig] Signal.trap(sig) do signals_queue << sig # send to queue signal end end Thread.new do signals_queue.pop # waiting for kill signal stop # stop web server and app end end |