タケユー・ウェブ日報

Ruby on Rails や Flutter といったWeb・モバイルアプリ技術を武器にお客様のビジネス立ち上げを支援する、タケユー・ウェブ株式会社の技術ブログです。

OpsWorks で使うunicornのバージョンを変更する

Cookbookを見てみると、変数に設定してあり、customize.rbで上書きできそうです。

opsworks-cookbooks/default.rb at v339 · aws/opsworks-cookbooks · GitHub

default[:unicorn][:worker_processes] = node[:rails][:max_pool_size] ? node[:rails][:max_pool_size] : 4
default[:unicorn][:backlog] = 1024
default[:unicorn][:timeout] = 60
default[:unicorn][:preload_app] = true
default[:unicorn][:version] = '4.7.0'
default[:unicorn][:tcp_nodelay] = true
default[:unicorn][:tcp_nopush] = false
default[:unicorn][:tries] = 5
default[:unicorn][:delay] = 0.5
default[:unicorn][:accept_filter] = "httpready"

以前書いたのと同様にして変更してみます。

takeyuweb.hatenablog.com

手順

1. Custom Chef Cookbooksのリポジトリを作成

すでにプロジェクトのカスタムCookbooksがある場合はそちらに追加していくので個別に作成する必要はありません。

2. unicorn/attributes/customize.rb

こんな感じで作成します。

###
# This is the place to override the unicorn cookbook's default attributes.
#
# Do not edit THIS file directly. Instead, create
# "unicorn/attributes/customize.rb" in your cookbook repository and
# put the overrides in YOUR customize.rb file.
###

# The following shows how to override the Unicorn timout:
#
#normal[:unicorn][:timeout] = 30
normal[:unicorn][:version] = '4.9.0' # Gemfile.lockと合わせる

versionの値は(通常Railsだと思いますが)Gemfile.lockのunicornバージョンとあわせます。

バージョンが合わないとき … Bundlerでエラーになります

Gemfile側にunicornがないときRails Appのデプロイ時に起動やリロードができません

3. StackにCustom Chef Cookbooksのリポジトリ登録・更新

すでに(ry

4. Update Custom Cookbooks

スタックのRun CommandでカスタムCookbooksを更新します。AppのデプロイだけではカスタムCookbooksは更新されないので注意。

5. Setup

スタックのRun CommandでSetupします。これでシステムRubyUnicornが再インストールされます。

以上、そんな感じです。