gem install capistrano
gem 'capistrano', '~> 3.4.0'
bundle installで3.4が入る!
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