Merge pull request #1683 from maxmeyer/feature/preview_server_daemon

Make middleman's preview server a daemon
feature/livereload-locales-data
Thomas Reynolds 2015-11-11 15:11:37 -08:00
commit 169b6f2c0a
3 changed files with 22 additions and 1 deletions

View File

@ -4,6 +4,8 @@ master
* Rather than applying layouts to all files which are not .txt, .css, .js, .json: the new behavior is to only default layouts to active for .html
* Switch from Ruby Sass to SassC.
* `relative_assets` extension overrides local `relative: false` option to stylesheet/javascript tag helpers.
* Add `before_server`-hook to the preview server which is run before the Webrick server is started
* Add `-d` to `middleman server` to make it run as daemon
# 4.0.0.rc.1

View File

@ -49,6 +49,11 @@ module Middleman::Cli
aliases: '-l',
default: 0.5,
desc: 'Set file watcher latency, in seconds'
class_option :daemon,
type: :boolean,
aliases: '-d',
default: false,
desc: 'Daemonize preview server'
# Start the server
def server
@ -73,7 +78,8 @@ module Middleman::Cli
disable_watcher: options['disable_watcher'],
reload_paths: options['reload_paths'],
force_polling: options['force_polling'],
latency: options['latency']
latency: options['latency'],
daemon: options['daemon']
}
puts '== The Middleman is loading'

View File

@ -58,6 +58,19 @@ module Middleman
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