From 4e52869f0f5b6eb5a46fe723f921a7a65a534674 Mon Sep 17 00:00:00 2001 From: ddavison Date: Wed, 21 Aug 2013 20:53:01 +0000 Subject: [PATCH] adding detachment functionality --- bin/jekyll | 1 + lib/jekyll/commands/serve.rb | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/bin/jekyll b/bin/jekyll index bfe13068..68d16bd4 100755 --- a/bin/jekyll +++ b/bin/jekyll @@ -82,6 +82,7 @@ command :serve do |c| c.option '--limit_posts MAX_POSTS', Integer, 'Limits the number of posts to parse and publish' c.option '-w', '--watch', 'Watch for changes and rebuild' c.option '--lsi', 'Use LSI for improved related posts' + c.option '--detach', 'Run this server in the background' c.option '-D', '--drafts', 'Render posts in the _drafts folder' c.option '-P', '--port [PORT]', 'Port to listen on' diff --git a/lib/jekyll/commands/serve.rb b/lib/jekyll/commands/serve.rb index ae28665b..8ff4ec6a 100644 --- a/lib/jekyll/commands/serve.rb +++ b/lib/jekyll/commands/serve.rb @@ -24,9 +24,17 @@ module Jekyll ) s.mount(options['baseurl'], HTTPServlet::FileHandler, destination, fh_option) - t = Thread.new { s.start } - trap("INT") { s.shutdown } - t.join() + + unless options['detach'] + t = Thread.new { s.start } + trap("INT") { s.shutdown } + t.join() + else + # they are detaching the server. + pid = Process.fork {s.start} + Process.detach(pid) + pid + end end end end