Cap shellは生きていた
カピストラーノについてです.
Capistrano - Wikipedia
以前,こんなことを書いてしまったのですが,
Capistranoは生きていた - なぜか数学者にはワイン好きが多い
残念なのは,cap shellが無くなってしまったみたいな点です.
まじめにドキュメントを読むと書いてありました.
capistrano/README.md at master · capistrano/capistrano · GitHub
Console
Note: Here be dragons. The console is very immature, but it's much more cleanly architected than previous incarnations and it'll only get better from here on in.
Execute arbitrary remote commands, to use this simply add require 'capistrano/console' which will add the necessary tasks to your environment:
というわけで,Capfileに
require 'capistrano/setup' require 'capistrano/console'
こんな感じのを先頭に書いて
$ cap console capistrano console - enter command to execute on staging staging> ls -l /etc/hosts INFO [2db46c18] Running /usr/bin/env ls -l /etc/hosts on server01 INFO [48e5ffe8] Running /usr/bin/env ls -l /etc/hosts on server02 INFO [28084cc7] Running /usr/bin/env ls -l /etc/hosts on server03 INFO [28084cc7] Finished in 0.122 seconds command successful. INFO [48e5ffe8] Finished in 0.135 seconds command successful. INFO [2db46c18] Finished in 0.141 seconds command successful.
アレ,出力が出ない...
set :log_level, :debug
ログレベルを変えてもダメ...
結局,バックエンドのSSHKitのログレベルを変更することで出力を見ることができました.
SSHKit.config.output_verbosity = Logger::DEBUG
$ cap console capistrano console - enter command to execute on staging staging> ls -l /etc/hosts INFO [6606370d] Running /usr/bin/env ls -l /etc/hosts on server01 INFO [8bdbbe47] Running /usr/bin/env ls -l /etc/hosts on server02 INFO [950a8288] Running /usr/bin/env ls -l /etc/hosts on server03 DEBUG [6606370d] Command: ls -l /etc/hosts DEBUG [8bdbbe47] Command: ls -l /etc/hosts DEBUG [950a8288] Command: ls -l /etc/hosts DEBUG [8bdbbe47] -rw-r--r-- 1 root root 743 Oct 28 14:20 /etc/hosts INFO [8bdbbe47] Finished in 0.122 seconds command successful. DEBUG [950a8288] -rw-r--r-- 1 root root 798 Oct 28 14:21 /etc/hosts INFO [950a8288] Finished in 0.124 seconds command successful. DEBUG [6606370d] -rw-r--r-- 1 root root 825 Oct 28 14:20 /etc/hosts INFO [6606370d] Finished in 0.140 seconds command successful.
もちろんレシピの中なら,
#SSHKit.config.output_verbosity = Logger::DEBUG task :hosts do on roles(:some_user) do |host| p capture("ls -l /etc/hosts"); end; end;
とやれば
$ cap hosts "-rw-r--r-- 1 root root 798 Oct 28 14:21 /etc/hosts" "-rw-r--r-- 1 root root 743 Oct 28 14:20 /etc/hosts" "-rw-r--r-- 1 root root 825 Oct 28 14:20 /etc/hosts"
デバグログ無しで出力を得られます.
(info capture("ls -l /etc/hosts");でも良いかも)