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