class Middleman::PreviewServer
def start(opts={})
-
(void)
-
def start(opts={}) # Do not buffer output, otherwise testing of output does not work $stdout.sync = true $stderr.sync = true @options = opts @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 the_app = initialize_new_app # And now comes the check unless server_information.valid? $stderr.puts %(== Running Middleman failed: #{server_information.reason}. Please fix that and try again.) exit 1 end mount_instance(the_app) 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 %s', 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 %s', 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 %s', 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 register_signal_handlers # 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 if child_pid = fork 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 loop do @webrick.start # $mm_shutdown is set by the signal handler if $mm_shutdown shutdown exit elsif $mm_reload $mm_reload = false reload end end end