-
Notifications
You must be signed in to change notification settings - Fork 0
/
eye.rb
78 lines (74 loc) · 2.98 KB
/
eye.rb
1
2
3
4
5
6
7
8
9
10
11
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
dep 'eye.running' do
hostname = shell("hostname")
requires 'eye.configured'.with(hostname)
requires 'eye.scripted'
met? {
shell("ps -ef | grep eye") {|shell| shell.stdout.include?("eye monitoring") }
}
meet {
shell "/etc/init.d/eye start"
}
end
dep 'eye.installed' do
met? {
rvm_run_with_ruby("2.3.3", "gem list eye") {|shell| shell.stdout.include?("eye") }
}
meet {
rvm_run_with_ruby "2.3.3", "gem install eye --no-rdoc --no-ri"
# Eye Http on rubygems has issues, need to install from Github
# rvm_run_with_ruby "2.3.3", "gem install eye-http --no-rdoc --no-ri"
shell("git clone https://github.com/kostya/eye-http.git")
cd "/root/eye-http" do
shell("gem build eye-http.gemspec")
shell("gem install eye-http-0.9.gem")
end
shell("rm -rf /root/eye-http")
eye_lib_path = rvm_run_with_ruby "2.3.3", "gem which eye"
#puts eye_lib_path
#puts File.expand_path(eye_lib_path, "../bin/eye")
shell("ln -sf #{File.expand_path(File.join(eye_lib_path, "../../bin/eye"))} /usr/local/bin/eye")
shell("mkdir /root/eye")
}
end
dep 'eye.configured', :hostname do
requires 'eye.installed'
met? {
Babushka::Renderable.new("/root/eye/server.eye").from?(dependency.load_path.parent / "eye/server.eye.erb") &&
Babushka::Renderable.new("/root/eye/extended_router.rb").from?(dependency.load_path.parent / "eye/extended_router.rb.erb") &&
Babushka::Renderable.new("/root/eye/extended_controller.rb").from?(dependency.load_path.parent / "eye/extended_controller.rb.erb") &&
Babushka::Renderable.new("/root/eye/http_decorator.rb").from?(dependency.load_path.parent / "eye/http_decorator.rb.erb")
}
meet {
render_erb "eye/server.eye.erb", :to => "/root/eye/server.eye"
render_erb "eye/extended_router.rb.erb", :to => "/root/eye/extended_router.rb"
render_erb "eye/extended_controller.rb.erb", :to => "/root/eye/extended_controller.rb"
render_erb "eye/http_decorator.rb.erb", :to => "/root/eye/http_decorator.rb"
}
end
dep 'eye.scripted' do
requires 'rcconf.bin'
met? {
Babushka::Renderable.new("/etc/init.d/eye").from?(dependency.load_path.parent / "eye/init.erb")
}
meet {
render_erb "eye/init.erb", :to => "/etc/init.d/eye", :perms => '755', :sudo => true
sudo "update-rc.d eye defaults"
}
end
dep 'eye-process.configured', :app_name, :app_type do
met? {
shell? "grep #{app_name} server.eye", :cd => "/root/eye"
}
meet {
cd "/root/eye" do
shell %Q{export p="process '#{app_name}' do
pid_file #{app_type == 'rails' ? "'/opt/#{app_name}/shared/tmp/pids/unicorn.pid'" : "'/opt/#{app_name}/tmp/pids/unicorn.pid'"}
start_command '/etc/init.d/#{app_name} start'
restart_command '/etc/init.d/#{app_name} restart'
stop_command '/etc/init.d/#{app_name} stop'
restart_grace 30.seconds
end" && awk -v proc="$p" '/Apps/{print;print proc;next}1' server.eye > server.tmp && mv server.tmp server.eye}
end
shell "/etc/init.d/eye restart"
}
end