Ruby 1.8.7
thin 1.5

thinのインストール

thinをインストールするには「gem install thin」とコマンドを叩きます。
C:\Users\main>gem install thin
Fetching: rack-1.4.1.gem (100%)
Fetching: eventmachine-1.0.0-x86-mingw32.gem (100%)
Fetching: daemons-1.1.9.gem (100%)
Fetching: thin-1.5.0.gem (100%)
ERROR:  Error installing thin:
        The 'thin' native gem requires installed build tools.
 
Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
 
エラーが出ました、ビルドツールがないからPathにDevKitを入れろと言ってるように聞こえます。

DevKitのインストール

RubyInstaller - Downloadから「DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe」をダウンロードし、実行、好きな所に解凍します。

後は「http://github.com/oneclick/rubyinstaller/wiki/Development-Kit」の支持に従いDevKitを解凍したディレクトリに移動して、
「ruby dk.rb init」「ruby dk.rb review」「ruby dk.rb install」とコマンドを叩きます。

コマンドログ

C:\ruby\devkit>ruby dk.rb init
[INFO] found RubyInstaller v1.8.7 at C:/ruby
 
Initialization complete! Please review and modify the auto-generated
'config.yml' file to ensure it contains the root directories to all
of the installed Rubies you want enhanced by the DevKit.
 
C:\ruby\devkit>ruby dk.rb review
Based upon the settings in the 'config.yml' file generated
from running 'ruby dk.rb init' and any of your customizations,
DevKit functionality will be injected into the following Rubies
when you run 'ruby dk.rb install'.
 
C:/ruby
 
C:\ruby\devkit>ruby dk.rb install
[INFO] Updating convenience notice gem override for 'C:/ruby'
[INFO] Installing 'C:/ruby/lib/ruby/site_ruby/devkit.rb'
 

再びthinインストール

C:\ruby\devkit>gem install thin
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Successfully installed thin-1.5.0
1 gem installed
Installing ri documentation for thin-1.5.0...
Installing RDoc documentation for thin-1.5.0...
 
今度は上手く行ったようです。


ruファイル作成

とりあえず「C:\thin\fart.ru」を作成しました。
app = proc do |env|
  [
    200,          # Status code
    {             # Response headers
      'Content-Type' => 'text/html',
      'Content-Length' => '2',
    },
    ['hi']        # Response body
  ]
end
 
# You can install Rack middlewares
# to do some crazy stuff like logging,
# filtering, auth or build your own.
use Rack::CommonLogger
 
run app
 

thin実行

先ほどfart.ruを作成したディレクトリに移動し、「thin start -R fart.ru」コマンドを実行します。
C:\apache2\htdocs>cd \thin
 
C:\thin>thin start -R fart.ru
>> Thin web server (v1.5.0 codename Knife)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop
 

http://localhost:3000/にアクセス


fart.ruに記述してある「hi」が表示されたのはいいのですが、どんなアドレスにアクセスしてもhiしか出ません…
それもそのはず、「fart.ru」の中身はrubyスクリプトで、その内容はステータスコード200とコンテンツ「hi」を返すウェブアプリだったのです。

「fart.ru」のruは「Rackup」の略のようで、「Rack」というRubyのウェブアプリとサーバを繋ぐ規格に「thin」が対応しているらしいです。

コメント

タグ:

ruby thin
最終更新:2013年03月20日 20:45
添付ファイル