4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

asset_host を 環境変数を使って出し分ける

Last updated at Posted at 2014-05-28

管理ツールのasset_hostだけ自host見に行かせたくて糞はまった件

概要

とある、Railsアプリケーションがあったとしてですね。

例えば、アプリケーションサーバ(メインコンテンツを表示してるサーバ)では、js, css, html, pngなどの静的ファイルは
画像サーバのドメインを見に行ってほしくて、管理ツールのサーバは自サーバを見に行ってほしいっていうことがあったんですね。

メインコンテンツ : web
管理ツール : admin

とします。

プロセス監視はeyeを使ってます。

asset_host

rails_root/config/environments/production.rb

  config.action_controller.asset_host = "//stat.yanap.jp" unless ENV["ROLE"] == "admin"

環境変数のROLEにadminが設定されてるときは、asset_hostを設定しないで、自サーバ見に行くようにしたい

eye

https://github.com/kostya/eye
https://github.com/kostya/eye/blob/master/examples/unicorn.eye

admin.eyeみたいなの用意します

# 一番外側
ROLE = "admin"

# Eye.application "rails_unicorn" do の中
env "ROLE" => ROLE

# process("unicorn") do の中
role = ''
if ROLE == 'admin'
  role = "ROLE=#{ROLE}"
end

# unicorn start command
start_command   "sudo -u yanap #{role} bundle exec unicorn_rails -c ./config/unicorn.rb -E RAILS_ENV -p 5000 -D"

思えば、当たり前なんですが、unicorn起動コマンドのところまで、ちゃんと渡さないとダメだった。
Eye.application "rails_unicorn" do の中までで、止まってて、できないできない言ってはまってしまった。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?