cloudler 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/cloudler.gemspec +1 -1
- data/lib/cloudler.rb +27 -7
- metadata +1 -1
data/cloudler.gemspec
CHANGED
data/lib/cloudler.rb
CHANGED
@@ -2,6 +2,9 @@ require 'net/ssh'
|
|
2
2
|
require 'net/scp'
|
3
3
|
|
4
4
|
class Cloudler
|
5
|
+
|
6
|
+
VERSION = '0.1.2'
|
7
|
+
|
5
8
|
def self.hosts= hosts
|
6
9
|
@hosts = hosts
|
7
10
|
end
|
@@ -30,20 +33,32 @@ class Cloudler
|
|
30
33
|
@precommands = precommands
|
31
34
|
end
|
32
35
|
|
36
|
+
def self.path= path
|
37
|
+
@path = path
|
38
|
+
end
|
39
|
+
|
33
40
|
def self.run
|
34
41
|
@files ||= []
|
35
42
|
@gems ||= []
|
36
43
|
@precommands ||= []
|
44
|
+
@path ||=
|
45
|
+
if @username == 'root'
|
46
|
+
'/root/.cloudler'
|
47
|
+
else
|
48
|
+
"/home/#{@username}/.cloudler"
|
49
|
+
end
|
37
50
|
|
38
51
|
@hosts.each do |host|
|
39
52
|
Net::SSH.start(host, @username, :password => @password) do |ssh|
|
40
53
|
puts "Uploading files..."
|
41
|
-
ssh.exec! "rm -rf
|
42
|
-
ssh.exec! "mkdir
|
54
|
+
ssh.exec! "rm -rf #{@path}"
|
55
|
+
ssh.exec! "mkdir #{@path}"
|
43
56
|
if @files.length > 0
|
44
|
-
|
57
|
+
@files.each do |file|
|
58
|
+
ssh.scp.upload(file, "#{@path}", :recursive => true)
|
59
|
+
end
|
45
60
|
else
|
46
|
-
ssh.scp.upload!('.', "
|
61
|
+
ssh.scp.upload!('.', "#{@path}", :recursive => true)
|
47
62
|
end
|
48
63
|
|
49
64
|
puts "Files uploaded."
|
@@ -59,7 +74,7 @@ class Cloudler
|
|
59
74
|
if @precommands.length > 0
|
60
75
|
puts "Executing pre-commands"
|
61
76
|
@precommands.each do |command|
|
62
|
-
ssh.exec "cd
|
77
|
+
ssh.exec "cd #{@path} && #{command}" do |ch,stream,data|
|
63
78
|
puts data
|
64
79
|
end
|
65
80
|
end
|
@@ -67,11 +82,11 @@ class Cloudler
|
|
67
82
|
end
|
68
83
|
|
69
84
|
puts "Executing command..."
|
70
|
-
ssh.exec! "cd
|
85
|
+
ssh.exec! "cd #{@path} && #{@command}" do |ch, stream, data|
|
71
86
|
puts data
|
72
87
|
end
|
73
88
|
puts "Command finished."
|
74
|
-
end
|
89
|
+
end
|
75
90
|
end
|
76
91
|
end
|
77
92
|
|
@@ -81,6 +96,7 @@ class Cloudler
|
|
81
96
|
host 'HOSTNAME' # or for multiple servers, use ['HOST1', 'HOST2', ...]
|
82
97
|
username 'USERNAME'
|
83
98
|
password 'PASSWORD'
|
99
|
+
path 'PATH' # Optional path to upload the files to. By default it is /root/.cloudler, or /home/[username]/.cloudler
|
84
100
|
precommands [] # Optional list of commands to run before executing the main command
|
85
101
|
command 'COMMAND'
|
86
102
|
files [] # Optional list of files to upload
|
@@ -121,3 +137,7 @@ end
|
|
121
137
|
def precommands array
|
122
138
|
Cloudler.precommands = array
|
123
139
|
end
|
140
|
+
|
141
|
+
def path string
|
142
|
+
Cloudler.path = string
|
143
|
+
end
|