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

+ + diff --git a/site/docs/usage.md b/site/docs/usage.md index ac09c40a..0a72e3d3 100644 --- a/site/docs/usage.md +++ b/site/docs/usage.md @@ -31,8 +31,13 @@ preview what the generated site will look like in your browser locally. $ jekyll serve # => A development server will run at http://localhost:4000/ +$ jekyll serve --detach +# => Same as `jekyll serve` but will detach from the current terminal. +# If you need to kill the server, you can `kill -9 1234` where "1234" is the PID. +# If you cannot find the PID, then do, `ps aux | grep jekyll` and kill the instance. [Read more](http://unixhelp.ed.ac.uk/shell/jobz5.html). + $ jekyll serve --watch -# => As above, but watch for changes and regenerate automatically. +# => Same as `jekyll serve`, but watch for changes and regenerate automatically. {% endhighlight %} This is just a few of the available [configuration options](../configuration/).