Created
July 21, 2014 12:16
-
-
Save kazuph/693496806f0c94810257 to your computer and use it in GitHub Desktop.
capistrano 3 をできるだけシンプルにサーバーにコマンドを流し込むツールとして使いこなす ref: http://qiita.com/kazuph/items/deeaa7d3f9889674d7fe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lock '3.2.1' | |
set :pty, true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :utils do | |
task :ls do | |
on roles(:app) do | |
execute "ls" | |
end | |
end | |
task :perl_version do | |
on roles(:app) do | |
execute %[perl -v] | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ bundle init | |
$ echo gem "capistrano" >> Gemfile | |
$ bundle install | |
$ cap install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cap -V | |
Capistrano Version: 3.2.1 (Rake Version: 10.3.2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ bundle exec cap dev utils:perl_version | |
INFO[444094bb] Running /usr/bin/env perl -v on +HFOWFLWKEJF+WLEHF | |
DEBUG[444094bb] Command: perl -v | |
DEBUG[444094bb] | |
DEBUG[444094bb] This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi | |
DEBUG[444094bb] | |
DEBUG[444094bb] Copyright 1987-2009, Larry Wall | |
DEBUG[444094bb] | |
DEBUG[444094bb] Perl may be copied only under the terms of either the Artistic License or the | |
DEBUG[444094bb] GNU General Public License, which may be found in the Perl 5 source kit. | |
DEBUG[444094bb] | |
DEBUG[444094bb] Complete documentation for Perl, including FAQ lists, should be found on | |
DEBUG[444094bb] this system using "man perl" or "perldoc perl". If you have access to the | |
DEBUG[444094bb] Internet, point your browser at http://www.perl.org/, the Perl Home Page. | |
DEBUG[444094bb] | |
INFO[444094bb] Finished in 1.874 seconds with exit status 0 (successful). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ bundle exec cap dev utils:perl_version | |
INFO[444094bb] Running /usr/bin/env perl -v on LHFWLKEFJWEFJ | |
DEBUG[444094bb] Command: perl -v | |
DEBUG[444094bb] | |
DEBUG[444094bb] This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi | |
DEBUG[444094bb] | |
DEBUG[444094bb] Copyright 1987-2009, Larry Wall | |
DEBUG[444094bb] | |
DEBUG[444094bb] Perl may be copied only under the terms of either the Artistic License or the | |
DEBUG[444094bb] GNU General Public License, which may be found in the Perl 5 source kit. | |
DEBUG[444094bb] | |
DEBUG[444094bb] Complete documentation for Perl, including FAQ lists, should be found on | |
DEBUG[444094bb] this system using "man perl" or "perldoc perl". If you have access to the | |
DEBUG[444094bb] Internet, point your browser at http://www.perl.org/, the Perl Home Page. | |
DEBUG[444094bb] | |
INFO[444094bb] Finished in 1.874 seconds with exit status 0 (successful). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bundle exec cap dev utils:echo user_name=kazuph |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ bundle exec cap dev utils:echo | |
Please enter user_name (): kazuph | |
INFO[62046886] Running /usr/bin/env echo kazuph on example.com | |
DEBUG[62046886] Command: echo kazuph | |
INFO[62046886] Finished in 2.086 seconds with exit status 0 (successful). | |
DEBUG[62046886] kazuph | |
INFO[62046886] Finished in 2.086 seconds with exit status 0 (successful). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INFO[29ab7cc8] Running /usr/bin/env sudo whoami on +LHKFlkL+FHLEWJF | |
DEBUG[29ab7cc8] Command: sudo whoami | |
DEBUG[29ab7cc8] sudo | |
DEBUG[29ab7cc8] : | |
DEBUG[29ab7cc8] sudo を実行するには tty がなければいけません。すみません | |
DEBUG[29ab7cc8] | |
cap aborted! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ tree | |
. | |
├── Capfile | |
├── Gemfile | |
├── Gemfile.lock | |
├── config | |
│ ├── deploy | |
│ │ ├── production.rb | |
│ │ └── staging.rb | |
│ └── deploy.rb | |
└── lib | |
└── capistrano | |
└── tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 最初のexecute | |
/usr/bin/env whoami | |
# 2つ目のexecute | |
/usr/bin/env if ! sudo -u fuga whoami > /dev/null; then echo "You cannot switch to user 'fuga' using sudo, please check the sudoers file" 1>&2; false; fi on example.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
└─- config | |
└── deploy | |
├── production.rb | |
├── staging.rb | |
└── dev.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cap dev YOUR_TASK_NAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ bundle exec cap dev ls | |
INFO[6a60919c] Running /usr/bin/env ls on example.com | |
DEBUG[6a60919c] Command: /usr/bin/env ls | |
DEBUG[6a60919c] <<ここにファイル一覧が表示される>> | |
INFO[6a60919c] Finished in 1.851 seconds with exit status 0 (successful). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task :upload_dir_all do | |
on roles(:app) do | |
execute :mkdir, '-p', '/home/hoge/cap_sample' | |
upload! '.', '/home/hoge/cap_sample', recursive: true | |
execute :tree, '-L 2 /home/hoge/cap_sample' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment