Merge pull request #1683 from maxmeyer/feature/preview_server_daemon

Make middleman's preview server a daemon
This commit is contained in:
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 * 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. * Switch from Ruby Sass to SassC.
* `relative_assets` extension overrides local `relative: false` option to stylesheet/javascript tag helpers. * `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 # 4.0.0.rc.1

View file

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

View file

@ -58,6 +58,19 @@ module Middleman
app.execute_callbacks(:before_server, [ServerInformationCallbackProxy.new(server_information)]) 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 loop do
@webrick.start @webrick.start