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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/capx/runner.rb', line 13
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
if match = DIR_PATTERN.match(line)
@deploy_to = File.join(match[:path], 'current')
end
end
if @server.nil? || @user.nil?
puts 'capistrano server/user not found'
else
ssh_cmd = "ssh #{@user}@#{@server}"
if @switch == 'ssh'
ssh_cmd = "ssh -t #{@user}@#{@server} \"cd #{@deploy_to}; exec /bin/bash -l\"" unless @deploy_to.nil?
cmd = ssh_cmd
execute_cmd(cmd)
elsif @switch == 'disk'
cmd = "#{ssh_cmd} 'df -H'"
execute_cmd(cmd)
elsif @switch == 'info'
cmd = "#{ssh_cmd} 'cat /etc/*-release'"
execute_cmd(cmd)
elsif @switch == 'redis'
cmd = "#{ssh_cmd} 'redis-cli INFO keyspace'"
execute_cmd(cmd)
else
puts "#{@user}@#{@server}"
end
end
else
puts "File #{file} not found"
end
end
|