Chef Recipeのデバック

概要

Chef Recipeのデバック方法について記述します。

Engine Yard Cloudでは、 Chef Recipeを用いて、Engine Yard Cloudの柔軟性とスケーラビリティをもったままカスタマイズすることが可能です。

Custom Chef Recipeを作成し、デバックする上で役立つインスタンス上でのChef Recipeの位置、dna.json, ログの位置、インスタンス上で実行する方法を紹介します。

 

Custom Chef recipeの基本、使い方についてはこちらをご覧ください。

Chef Recipeの種類

Main Chef Recipe

Engine Yard Cloudにてインスタンスを設定するためにデフォルト設定されているRecipe

Custom Chef Recipe

デフォルトの設定に変更を加えたい場合に用意するRecipe

実行順について

Chef Recipeの実行には以下二通りの方法があります。対象のEnvirnomentすべてのインスタンスで以下の順に実行されます。

 

DashboardからApplyをクリック, $ey rebuild

  1. Main Chef Recipe (DefaultでEngine Yardが提供している)
  2. Custom Chef Recipe

$ey recipes apply

  1.  Custom Chef Recipe

 Chef Recipeの位置

各Chef Recipeは各インスタンスの以下の位置に配置されています。

# Main Chef Recipeの位置
/etc/chef/recipes/cookbooks/

# Custom Chef Recipeの位置
/etc/chef-custom/recipes/cookbooks/

dna.jsonについて

環境名やApp, DB, UtilityインスタンスのIP Addressなどの情報が書かれたjsonになります。

このjsonの情報を参照することによって変更されるデータとロジックを分離します。

コードからはnodeで参照することができます。

# Main Chef Recipeのdna.json
/etc/chef/dna.json

# Custom Chef Recipeの位置
/etc/chef-custom/dna.json

英語ではありますが、こちらに、dna.jsoのデータのアクセス方法を解説した記事があります。

https://blog.engineyard.com/2014/engine-yards-chef-node-object 

ログの位置

直近の実行ログがいかに記録されています。

# Main Chef Recipeのログ
/var/log/chef.main.log

# Custom Chef Recipeのログ
/var/log/chef.custom.log

インスタンスにSSHログインして、カスタムChef Recipeを叩く

デバック用にカスタムChef Recipeを直接実行することも可能です。

#  特定のインスタンスにSSH
$sudo /usr/local/ey_resin/bin/chef-solo -j /etc/chef-custom/dna.json -c /etc/chef-custom/solo.rb

 

eyコマンドのタイミングについて

engineyard gemのコマンドでrecipeをコントロールすることができます。

$ey recipes upload
$ey recipes apply
$ey recieps download

があります。

ey recipes uploadはEngine Yardの管理サーバにレシピが登録されます。各インスタンスへはまだuploadされません。

ey recipes applyを行った時点で、Engine Yardの管理サーバから、各インスタンスへuploadされ、実行されます。

ey recipes downloadはEnigne Yardの管理サーバに登録されたカスタムレシピをローカル環境(コマンドを実行しているマシーン)にdownloadします。

参考

Chef Recipeによる環境のカスタマイズ https://support.cloud.engineyard.com/entries/22340268?locale=67

カスタムレシピテンプレート https://github.com/engineyard/ey-cloud-recipes

コメント

サインインしてコメントを残してください。

Powered by Zendesk