Octopress の preview
時に起動する Web サーバ WEBrick をより速度が速いと言われている(?) thin に変更する方法についての記録です。
0. 前提条件
- 作業する環境(OS)は、Linux Mint 13 Maya (64bit)
- Ruby 1.9.3-p194
- Octopress 2.0
1. Gemfile 編集
Gemfile
の group :development do
内に以下を追加する。
File: Gemfile
1 gem "thin", "~> 1.5.0"
2. thin パッケージインストール
RubyGems パッケージの thin をインストールする。
1
|
|
3. Rakefile 編集
今までどおり rake preview
で thin が起動するように、Rakefile
の task :preview do
部分を以下のように編集する。
(念の為、変更前の状態をコメントアウトして残している)
File: Gemfile
1 diff --git a/Rakefile b/Rakefile
2 index fd7e611..0e566a2 100644
3 --- a/Rakefile
4 +++ b/Rakefile
5 @@ -79,18 +79,22 @@ end
6 desc "preview the site in a web browser"
7 task :preview do
8 raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
9 - puts "Starting to watch source with Jekyll and Compass. Starting Rack on port #{server_port}"
10 + #puts "Starting to watch source with Jekyll and Compass. Starting Rack on port #{server_port}"
11 + puts "Starting to watch source with Jekyll and Compass. Starting Thin on port #{server_port}"
12 system "compass compile --css-dir #{source_dir}/stylesheets" unless File.exist?("#{source_dir}/stylesheets/screen.css")
13 jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll --auto")
14 compassPid = Process.spawn("compass watch")
15 - rackupPid = Process.spawn("rackup --port #{server_port}")
16 + #rackupPid = Process.spawn("rackup --port #{server_port}")
17 + thinPid = Process.spawn("thin start --port #{server_port}")
18
19 trap("INT") {
20 - [jekyllPid, compassPid, rackupPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
21 + #[jekyllPid, compassPid, rackupPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
22 + [jekyllPid, compassPid, thinPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
23 exit 0
24 }
25
26 - [jekyllPid, compassPid, rackupPid].each { |pid| Process.wait(pid) }
27 + #[jekyllPid, compassPid, rackupPid].each { |pid| Process.wait(pid) }
28 + [jekyllPid, compassPid, thinPid].each { |pid| Process.wait(pid) }
29 end
30
31 # usage rake new_post[my-new-post] or rake new_post['my new post'] or rake new_post (defaults to "new-post")
32 ~
4. preview 起動
今までどおり、preview
を起動してみる。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
thin で起動していることが分かる。
参考サイト
- OctopressのRake Previewにthinを利用してプレビューを高速化する - Glide Note - グライドノート
- thin | RubyGems.org | your community gem host
実際に、速度を測定してはいないのですが、若干早くなったようには感じます。
以上。