Module: AppDeploy
- Defined in:
- lib/app-deploy/utils.rb,
lib/app-deploy/daemon.rb,
lib/app-deploy/version.rb,
lib/app-deploy/rack_cluster.rb,
lib/app-deploy/daemon_cluster.rb
Defined Under Namespace
Modules: Daemon, DaemonCluster, RackCluster
Constant Summary
collapse
- VERSION =
'0.8.1'
Class Method Summary
collapse
-
.always_reenable(tasks) ⇒ Object
-
.clone(opts) ⇒ Object
-
.dependency(opts = {}) ⇒ Object
-
.dependency_gem(opts = {}, &block) ⇒ Object
-
.each(*with) ⇒ Object
-
.extract_config(config) ⇒ Object
-
.gem ⇒ Object
-
.gem_bin ⇒ Object
-
.github ⇒ Object
-
.install_gem(opts) ⇒ Object
-
.install_gem_local(proj, task) ⇒ Object
-
.install_gem_remote(gem_name, source = nil) ⇒ Object
-
.installed_gem?(gem_name) ⇒ Boolean
-
.invoke(task_name, hash = {}) ⇒ Object
wrap Rake::Task#invoke for named arguments.
-
.kill_pid(signal, pid, name = nil) ⇒ Object
-
.kill_pidfile(signal, pid_path, name = nil) ⇒ Object
-
.kill_raise(signal, pid, name = nil) ⇒ Object
-
.read_pid(pid_path) ⇒ Object
-
.term(pid_path, name = nil, limit = 5, wait = 0.1) ⇒ Object
-
.uninstall_gem(opts) ⇒ Object
Class Method Details
.always_reenable(tasks) ⇒ Object
11
12
13
|
# File 'lib/app-deploy/utils.rb', line 11
def always_reenable tasks
tasks.each{ |t| t.enhance{ |tt| tt.reenable } }
end
|
.clone(opts) ⇒ Object
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/app-deploy/utils.rb', line 78
def clone opts
user, proj, path = opts[:github_user], opts[:github_project], opts[:git_path]
if File.exist?(path)
puts "Skip #{proj} because #{path} exists"
else
sh "git clone git://github.com/#{user}/#{proj}.git #{path}"
sh "git --git-dir #{path}/.git gc"
end
end
|
.dependency(opts = {}) ⇒ Object
16
17
18
19
20
|
# File 'lib/app-deploy/utils.rb', line 16
def dependency opts = {}
opts = opts.dup
opts[:git_path] ||= opts[:github_project]
github << opts.freeze
end
|
.dependency_gem(opts = {}, &block) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/app-deploy/utils.rb', line 23
def dependency_gem opts = {}, &block
opts = opts.dup
if opts[:github_project]
opts[:git_path] ||= opts[:github_project]
opts[:task_gem] = block if block_given?
github << opts.freeze
end
gem << opts.freeze
end
|
.each(*with) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/app-deploy/utils.rb', line 35
def each *with
with = [:gem, :github] if with.empty?
cwd = Dir.pwd
with.map{ |kind| AppDeploy.send(kind) }.flatten.uniq.each{ |opts|
puts
if opts[:github_project]
if File.directory?(opts[:git_path])
begin
Dir.chdir(opts[:git_path])
yield(opts)
rescue RuntimeError => e
puts e
ensure
Dir.chdir(cwd)
end
else
puts "Skip #{opts[:github_project]}, because it was not found"
end
else yield(opts)
end
}
end
|
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/app-deploy/utils.rb', line 64
def config
require 'yaml'
YAML.load(File.read(config)).inject([]){ |result, opt_value|
opt, value = opt_value
if block_given?
result << yield(opt, value)
else
result << "--#{opt} #{value}"
end
result
}.compact.join(' ')
end
|
.gem ⇒ Object
22
|
# File 'lib/app-deploy/utils.rb', line 22
def gem; @gem ||= []; end
|
.gem_bin ⇒ Object
143
144
145
|
# File 'lib/app-deploy/utils.rb', line 143
def gem_bin
Gem.ruby + ' ' + `which gem`.strip
end
|
.github ⇒ Object
15
|
# File 'lib/app-deploy/utils.rb', line 15
def github; @github ||= []; end
|
.install_gem(opts) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/app-deploy/utils.rb', line 98
def install_gem opts
gem_name = opts[:gem] || opts[:github_project]
if AppDeploy.installed_gem?(gem_name)
puts "Skip #{gem_name} because it was installed. Uninstall first if you want to reinstall"
else
if opts[:gem]
AppDeploy.install_gem_remote(opts[:gem], opts[:source])
else
AppDeploy.install_gem_local(opts[:github_project], opts[:task_gem])
end
end
end
|
.install_gem_local(proj, task) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/app-deploy/utils.rb', line 127
def install_gem_local proj, task
case task
when 'bones'
sh 'rake clobber'
sh 'rake gem:package'
sh "#{gem_bin} install --local pkg/#{proj}-*.gem --no-ri --no-rdoc"
when 'hoe'
sh 'rake gem'
sh "#{gem_bin} install --local pkg/#{proj}-*.gem --no-ri --no-rdoc"
when Proc
task.call
end
end
|
.install_gem_remote(gem_name, source = nil) ⇒ Object
123
124
125
|
# File 'lib/app-deploy/utils.rb', line 123
def install_gem_remote gem_name, source = nil
sh "#{gem_bin} install #{gem_name}#{source ? ' --source ' + source : ''}"
end
|
.installed_gem?(gem_name) ⇒ Boolean
90
91
92
93
94
95
96
|
# File 'lib/app-deploy/utils.rb', line 90
def installed_gem? gem_name
Gem.send(:gem, gem_name)
true
rescue LoadError
false
end
|
.invoke(task_name, hash = {}) ⇒ Object
wrap Rake::Task#invoke for named arguments
5
6
7
8
9
|
# File 'lib/app-deploy/utils.rb', line 5
def invoke task_name, hash = {}
task = Rake::Task[task_name]
args = task.arg_names.map{ |name| hash[name] }
task.invoke(*args)
end
|
.kill_pid(signal, pid, name = nil) ⇒ Object
190
191
192
193
194
195
196
|
# File 'lib/app-deploy/utils.rb', line 190
def kill_pid signal, pid, name = nil
AppDeploy.kill_raise(signal, pid, name)
pid
rescue Errno::ESRCH
puts "WARN: No such pid: #{pid}"
nil
end
|
.kill_pidfile(signal, pid_path, name = nil) ⇒ Object
178
179
180
181
182
183
184
185
186
187
188
|
# File 'lib/app-deploy/utils.rb', line 178
def kill_pidfile signal, pid_path, name = nil
if pid = AppDeploy.read_pid(pid_path)
AppDeploy.kill_raise(signal, pid, name)
return pid
end
nil
rescue Errno::ESRCH
puts "WARN: No such pid: #{pid}, removing #{pid_path}..."
File.delete(pid_path)
nil
end
|
.kill_raise(signal, pid, name = nil) ⇒ Object
198
199
200
201
202
|
# File 'lib/app-deploy/utils.rb', line 198
def kill_raise signal, pid, name = nil
puts "Sending #{signal} to #{name}(#{pid})..."
Process.kill(signal, pid)
pid
end
|
.read_pid(pid_path) ⇒ Object
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/app-deploy/utils.rb', line 148
def read_pid pid_path
if File.exist?(pid_path)
File.read(pid_path).strip.to_i
else
puts "WARN: No pid file found in #{pid_path}"
nil
end
end
|
.term(pid_path, name = nil, limit = 5, wait = 0.1) ⇒ Object
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/app-deploy/utils.rb', line 159
def term pid_path, name = nil, limit = 5, wait = 0.1
require 'timeout'
pid = AppDeploy.kill_pidfile('TERM', pid_path, name)
Timeout.timeout(limit.to_i){
if pid
while true
Process.kill('TERM', pid)
sleep(wait)
end
end
}
rescue Errno::ESRCH
puts "Killed #{name}(#{pid})"
rescue Timeout::Error
puts "Timeout(#{limit}) killing #{name}(#{pid})"
end
|
.uninstall_gem(opts) ⇒ Object
114
115
116
117
118
119
120
121
|
# File 'lib/app-deploy/utils.rb', line 114
def uninstall_gem opts
gem_name = opts[:gem] || opts[:github_project]
if AppDeploy.installed_gem?(gem_name)
sh "#{gem_bin} uninstall #{gem_name}"
else
puts "Skip #{gem_name} because it was not installed"
end
end
|