LoginSignup
5
5

More than 5 years have passed since last update.

WEBrick をサービスとして動かすスクリプトを書いた

Last updated at Posted at 2015-09-02

はじめに

WEBrick を Nginx の reverse proxy のバックエンドにしたくて、サービス化するためのスクリプトを書いた

動作環境

# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.7 (Santiago)
# ruby --version
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
# rails -v
Rails 4.2.3
# ls
redmine-3.1.0.tar.gz

スクリプト

実際のスクリプトは、以下の Gist を確認して欲しい。
https://gist.github.com/takuyaohashi/c49117930473487dc020

使い方

# set rails application path
APPLICATION_ROOT="/path/to/webrick/dir"

# add path to bundle
export PATH=/usr/local/bin/:$PATH

# set configuration
PORT="3000"
BINDING_IP="0.0.0.0"
ENVIRONMENT="production"
RAILS_RELATIVE_URL_ROOT="/hoge/hoge"

基本的に上記設定を個々の環境にあわせて変更してもらえれば、使用できるはず。
特に説明は不要かと思いますが、1点だけ注意。
RAILS_RELATIVE_URL_ROOT を使う時は、config.ru を下記のような修正が必要。

config.ru
4c4,14
< run WEBrickApp::Application
---
> if ENV['RAILS_RELATIVE_URL_ROOT']
>   map ENV['RAILS_RELATIVE_URL_ROOT'] do
>     run WEBrickApp::Application
>   end
> else
>   run WEBrickApp::Application
> end

(参考URL: http://chroju89.hatenablog.jp/entry/2015/01/05/222205)

サービス化

以下のコマンドでサービス化を行う

# chkconfig --add webrick
# chkconfig webrick on

おわりに

使用するユーザも多くないし、レスポンスもそんなに気にならないと思うから、WEBrick でサーバを立ててみた。
パフォーマンスが気になってきたら、Unicorn とか他の手段を考える。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5