インストール

gem install capistrano
gem 'capistrano', '~> 3.4.0'

bundle installで3.4が入る!

capistranoプロジェクトの作成

mkdir test
cd test
cap install

簡単なタスクを作ってみる

#
# Global options
# --------------
set :ssh_options, {
  keys: %w(秘密鍵の場所),
  forward_agent: false,
  auth_methods: %w(publickey)
}

role :app, %w{xxxx01@192.168.99.01 xxx01@192.168.99.02}

task :customdeploy do
 on roles(:app) do
   # invokeでほかのタスクを呼ぶ
   invoke "ls"
   invoke "apacherestart"
 end
end
# tomcat 再起動
task :apacherestart do
  on roles(:app) do
    execute "/etc/init.d/tomcat5 restart"
    execute "/etc/init.d/httpd restart"
  end
end

task :ls do
  on roles(:app) do
    execute "ls"
  end
end
cap dev customdeploy --dry-run

タスク

デフォルトではいろいろなタスクがある。capistranoで決められた順番で実行されるが、 framework_tasks = [:starting, :started]で定義するとその順序で実施される?

コマンド集

タスクの一覧表示cap -T
実際に実行しないでコマンドのみ表示--dry-runを付ける

設定ファイルの記述

画面にログputs
変数の設定set
変数の取得fetch
コマンド実行結果の取得files = capture(:ls, '-xtr', '/var/tmp')

トラブルシューティング

インストール直後のマシンcap install実施で、以下のエラーが出た。

cannot load such file -- io/console
gem install io-console

参考記事

Ansibleで代用

http://tdoc.info/blog/2015/01/14/deploying_with_ansible.html


トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2022-10-14 (金) 13:16:52