Merge pull request #1443 from ddavison/detachment

Detachment
This commit is contained in:
Matt Rogers 2013-08-24 20:16:42 -07:00
commit 4fa4ad2232
5 changed files with 28 additions and 4 deletions

View File

@ -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 '--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 '-w', '--watch', 'Watch for changes and rebuild'
c.option '--lsi', 'Use LSI for improved related posts' 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 '-D', '--drafts', 'Render posts in the _drafts folder'
c.option '-P', '--port [PORT]', 'Port to listen on' c.option '-P', '--port [PORT]', 'Port to listen on'

View File

@ -24,6 +24,12 @@ module Jekyll
) )
s.mount(options['baseurl'], HTTPServlet::FileHandler, destination, fh_option) s.mount(options['baseurl'], HTTPServlet::FileHandler, destination, fh_option)
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 } t = Thread.new { s.start }
trap("INT") { s.shutdown } trap("INT") { s.shutdown }
t.join() t.join()
@ -31,3 +37,4 @@ module Jekyll
end end
end end
end end
end

View File

@ -15,6 +15,7 @@ module Jekyll
'timezone' => nil, # use the local timezone 'timezone' => nil, # use the local timezone
'safe' => false, 'safe' => false,
'detach' => false, # default to not detaching the server
'show_drafts' => nil, 'show_drafts' => nil,
'limit_posts' => 0, 'limit_posts' => 0,
'lsi' => false, 'lsi' => false,

View File

@ -220,6 +220,16 @@ before your site is served.
<p><code class="flag">--baseurl URL</code></p> <p><code class="flag">--baseurl URL</code></p>
</td> </td>
</tr> </tr>
<tr class='setting'>
<td>
<p class='name'><strong>Detach</strong></p>
<p class='description'>Detach the server from the terminal</p>
</td>
<td class="align-center">
<p><code class="option">detach: BOOL</code></p>
<p><code class="flag">-B, --detach</code></p>
</td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>

View File

@ -31,8 +31,13 @@ preview what the generated site will look like in your browser locally.
$ jekyll serve $ jekyll serve
# => A development server will run at http://localhost:4000/ # => 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 $ jekyll serve --watch
# => As above, but watch for changes and regenerate automatically. # => Same as `jekyll serve`, but watch for changes and regenerate automatically.
{% endhighlight %} {% endhighlight %}
This is just a few of the available [configuration options](../configuration/). This is just a few of the available [configuration options](../configuration/).