Class: Capx::Runner
- Inherits:
-
Object
- Object
- Capx::Runner
- Defined in:
- lib/capx/runner.rb
Constant Summary collapse
- PATTERN =
/server:?\s+[\'\"]([\w\-\.]+)[\'\"],\s+user:?\s+[\'\"]([\w\-\.]+)[\'\"]/
Instance Method Summary collapse
-
#initialize(options) ⇒ Runner
constructor
A new instance of Runner.
- #run ⇒ Object
Constructor Details
#initialize(options) ⇒ Runner
Returns a new instance of Runner.
5 6 7 8 9 10 |
# File 'lib/capx/runner.rb', line 5 def initialize() @stage = [:stage] @switch = [:switch] @user = [:user] @server = nil end |
Instance Method Details
#run ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/capx/runner.rb', line 12 def run file = "config/deploy/#{@stage}.rb" if File.exist?(file) File.open(file).each do |line| if match = PATTERN.match(line) @server = match.captures[0] @user = match.captures[1] if @user.nil? end end if @server.nil? || @user.nil? puts "capistrano server/user not found" else if @switch == 'ssh' # call ssh cmd = "ssh #{@user}@#{@server}" execute_cmd(cmd) elsif @switch == 'disk' # call remote df -H cmd = "ssh #{@user}@#{@server} 'df -H'" execute_cmd(cmd) elsif @switch == 'info' cmd = "ssh #{@user}@#{@server} 'cat /etc/*-release'" execute_cmd(cmd) else puts "#{@user}@#{@server}" end end else puts "File #{file} not found" end end |