diff --git a/bin/jekyll b/bin/jekyll index 403bfbd9..b2b34b5d 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 '-B', '--detach', 'Run the server in the background (detach)' 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..406d3ef7 100644 --- a/lib/jekyll/commands/serve.rb +++ b/lib/jekyll/commands/serve.rb @@ -24,9 +24,16 @@ module Jekyll ) s.mount(options['baseurl'], HTTPServlet::FileHandler, destination, fh_option) - t = Thread.new { s.start } - trap("INT") { s.shutdown } - t.join() + + if options['detach'] # detach the server + pid = Process.fork {s.start} + Process.detach(pid) + pid + else # create a new server thread, then join it with current terminal + t = Thread.new { s.start } + trap("INT") { s.shutdown } + t.join() + end end end end diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index e00db8b1..05a097c7 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -15,6 +15,7 @@ module Jekyll 'timezone' => nil, # use the local timezone 'safe' => false, + 'detach' => false, # default to not detaching the server 'show_drafts' => nil, 'limit_posts' => 0, 'lsi' => false, diff --git a/site/docs/configuration.md b/site/docs/configuration.md index b001c65a..381ba43d 100644 --- a/site/docs/configuration.md +++ b/site/docs/configuration.md @@ -220,6 +220,16 @@ before your site is served.
--baseurl URL
Detach
+Detach the server from the terminal
+detach: BOOL
-B, --detach