LoginSignup
1
1

More than 5 years have passed since last update.

Windowsマシンからheroku上のredmineをunicornで起動するようにするお話

Last updated at Posted at 2014-12-17

4回目の投稿です。前回はこちら

今回は、heroku上で動くredmine(≒Railsアプリ)をunicornで起動するようにするお話です。

前置き

  • 既にheroku上にredmine環境が構築済みであるとして書いています
  • ローカルにheroku上に構築したredmineのリポジトリがあるとしています
  • Windowsマシンで操作しています
  • コンソールはGit Bushを使用しています。

手順

unicorn.rbとProcfileの作成

Procfileとは、heroku上にデプロイしたWebサービスの実行に任意のコマンドを指定できるファイルです。
公式はヘルプはこちら
Procfileを使っている仕組みについてはこちらのQiita記事が参考になるかと思います。
http://qiita.com/7kaji/items/6a59977d2ad85604e7fd

config\unicorn.rbというファイルを作成し、以下の内容を記載します。

# config/unicorn.rb
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 15
preload_app true

before_fork do |server, worker|
  Signal.trap 'TERM' do
    puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
    Process.kill 'QUIT', Process.pid
  end

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|
  Signal.trap 'TERM' do
    puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
  end

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
end

redmineルートディレクトリにProcfileという名前のファイルを作成し、以下を記載します。

web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb

Gemfileの編集

Gemfileに以下の行を追加します。

gem unicorn

ただし、当方、Windows環境なのでunicornのインストールは茨の道です。
ローカルでは使用しないので、非推奨な強行手段ですが、Gemfile.lockファイルを編集してしまいます。

Gemfile.lockファイルに以下の行を追記します。

    unicorn

herokuへPuch

以下のコマンドを実行してherokuへPushします。

git add .
git commit -m "deploy unicorn"
git push heroku master

確認

以下のコマンドを実行
heroku ps
そして返ってきた文字列に以下が含まれているなら成功。
bundle exec unicorn -p $PORT -c ./config/unicorn.rb

以上でherokuのredmineのunicornで起動するようになりました。

参考

1
1
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
1
1