tuesday 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kitchen +1 -0
- data/lib/tuesday.rb +166 -117
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 196906735eea820b326932b7dbdb041dc6f8e9ba
|
4
|
+
data.tar.gz: 6f6e4659d92779cc36954cc2909bd042e74c0a43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd36b91c2d668057733255f5418455479e2654a4ee8c6a7f4293ebb29945eb590646c735c24dff6589c73aa93a2faea2e9c7a566095cfd55c6ffb50cdc7c5314
|
7
|
+
data.tar.gz: 29e6082c79c1611faf49559aa9a6241f9858987914b58e625301dca1b45a5a8d4c8e3d8c21735fce0b1b3b685e31839d35a11b9b94a5248ae0d06bb29114e7a0
|
data/lib/kitchen
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
|
data/lib/tuesday.rb
CHANGED
@@ -2,161 +2,210 @@
|
|
2
2
|
|
3
3
|
class Tuesday
|
4
4
|
def self.run
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
abort
|
17
|
-
end
|
5
|
+
ARGV[0] = "regular" if ARGV[0].nil?
|
6
|
+
|
7
|
+
if ARGV[0].downcase == "reset"
|
8
|
+
kitchen_path = File.join( File.dirname(__FILE__), 'kitchen' )
|
9
|
+
kitchen_str = ""
|
10
|
+
File.foreach(kitchen_path){|line| kitchen_str += line}
|
11
|
+
kitchen = eval(kitchen_str.strip)
|
12
|
+
puts "Preparing the food"
|
13
|
+
if kitchen.nil?
|
14
|
+
kitchen = {}
|
15
|
+
end
|
18
16
|
|
19
|
-
|
20
|
-
|
17
|
+
kitchen.each do |key,value|
|
18
|
+
if value[:rails_app]
|
19
|
+
puts `rm "#{value[:pwd]}"/config/unicorn.rb`
|
20
|
+
else
|
21
|
+
puts `rm "#{value[:pwd]}"/unicorn.rb`
|
22
|
+
end
|
23
|
+
str = "#{value[:pwd]}/pids/unicorn.pid"
|
24
|
+
puts str
|
25
|
+
unicorn_id = IO.readlines(str).join.strip
|
26
|
+
puts `kill "#{unicorn_id}"`
|
27
|
+
end
|
21
28
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
if unicorn_output.nil?
|
26
|
-
puts "I'm sorry...you appear to be missing Unicorn. Don't worry I got you ;)"
|
27
|
-
puts `gem install unicorn`
|
29
|
+
File.write(kitchen_path, "")
|
30
|
+
File.write("/etc/nginx/conf.d/default.conf","")
|
31
|
+
puts `service nginx restart`
|
28
32
|
else
|
29
|
-
puts "
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
#puts "#praisecatgod"
|
34
|
+
settings = {}
|
35
|
+
|
36
|
+
rails_app = false
|
37
|
+
|
38
|
+
begin
|
39
|
+
# Exceptions raised by this code will
|
40
|
+
# be caught by the following rescue clause
|
41
|
+
settings = eval "{#{IO.readlines('Menufile').join.strip}}"
|
42
|
+
rescue
|
43
|
+
puts "You don't have a Menufile. Please consult http://tuesdayrb.me for support.
|
44
|
+
Thank you please come again."
|
45
|
+
abort
|
46
|
+
end
|
35
47
|
|
36
|
-
|
37
|
-
|
48
|
+
begin
|
49
|
+
#check if file is a rails app
|
50
|
+
if File.read("config.ru").match("Rails")
|
51
|
+
rails_app = true
|
52
|
+
end
|
53
|
+
rescue
|
54
|
+
puts "You don't have a config.ru. Please consult http://tuesdayrb.me for support.
|
55
|
+
Thank you please come again."
|
56
|
+
abort
|
57
|
+
end
|
38
58
|
|
39
|
-
|
59
|
+
output = `bundle install --without production`
|
60
|
+
puts output
|
40
61
|
|
41
|
-
|
42
|
-
|
62
|
+
output = `gem list`
|
63
|
+
#puts output
|
64
|
+
unicorn_output = output.match(/unicorn (.*)\n/)
|
65
|
+
if unicorn_output.nil?
|
66
|
+
puts "I'm sorry...you appear to be missing Unicorn. Don't worry I got you ;)"
|
67
|
+
puts `gem install unicorn`
|
68
|
+
else
|
69
|
+
puts "reservation made for mr. unicorn"
|
70
|
+
end
|
71
|
+
output = `pwd`
|
72
|
+
app_name = output.split("/").last
|
73
|
+
app_name.strip!
|
74
|
+
puts "I see you would like the #{app_name}. Very fine choice"
|
75
|
+
|
76
|
+
base_unicorn = "
|
77
|
+
working_directory '/var/www/#{app_name}'
|
43
78
|
|
44
|
-
|
79
|
+
pid '/var/www/#{app_name}/pids/unicorn.pid'
|
45
80
|
|
46
|
-
|
47
|
-
|
48
|
-
worker_processes 1
|
81
|
+
stderr_path '/var/www/#{app_name}/logs/unicorn.log'
|
82
|
+
stdout_path '/var/www/#{app_name}/logs/unicorn.log'
|
49
83
|
|
50
|
-
|
51
|
-
timeout 30
|
84
|
+
listen '/tmp/unicorn.#{app_name}.sock'
|
52
85
|
|
53
|
-
|
54
|
-
|
55
|
-
|
86
|
+
# Number of processes
|
87
|
+
# worker_processes 4
|
88
|
+
worker_processes 1
|
56
89
|
|
57
|
-
|
90
|
+
# Time-out
|
91
|
+
timeout 30
|
58
92
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
puts `brew install nginx`
|
93
|
+
"
|
94
|
+
puts `rm unicorn.rb`
|
95
|
+
if rails_app
|
96
|
+
puts `echo "#{base_unicorn}" >> config/unicorn.rb`
|
64
97
|
else
|
65
|
-
puts `
|
98
|
+
puts `echo "#{base_unicorn}" >> unicorn.rb`
|
66
99
|
end
|
67
|
-
end
|
68
100
|
|
69
|
-
|
70
|
-
puts "Killing the bad nginx"
|
71
|
-
puts `rm /etc/nginx/conf.d/defaults`
|
72
|
-
puts `rm /etc/nginx/sites-available/*`
|
73
|
-
puts `rm /etc/nginx/sites-enabled/*`
|
74
|
-
puts `rm /etc/nginx/conf.d/default.conf`
|
75
|
-
|
76
|
-
#add app to kitchen
|
77
|
-
kitchen = eval "#{IO.readlines('/usr/local/bin/kitchen').join.strip}"
|
78
|
-
if kitchen.nil?
|
79
|
-
kitchen = {}
|
80
|
-
end
|
101
|
+
puts `mkdir logs pids`
|
81
102
|
|
103
|
+
nginx = `which nginx`
|
104
|
+
if nginx == ""
|
105
|
+
#install nginx
|
106
|
+
if `uname`.strip == "Darwin"
|
107
|
+
puts `brew install nginx`
|
108
|
+
else
|
109
|
+
puts `apt-get install nginx`
|
110
|
+
end
|
111
|
+
end
|
82
112
|
|
83
|
-
|
113
|
+
#kill the bad nginx
|
114
|
+
puts "Killing the bad nginx"
|
115
|
+
puts `rm /etc/nginx/conf.d/defaults`
|
116
|
+
puts `rm /etc/nginx/sites-available/*`
|
117
|
+
puts `rm /etc/nginx/sites-enabled/*`
|
118
|
+
puts `rm /etc/nginx/conf.d/default.conf`
|
119
|
+
|
120
|
+
#add app to kitchen
|
121
|
+
puts "Stocking up the kitchen"
|
122
|
+
|
123
|
+
kitchen_path = File.join( File.dirname(__FILE__), 'kitchen' )
|
124
|
+
kitchen_str = ""
|
125
|
+
File.foreach(kitchen_path){|line| kitchen_str += line}
|
126
|
+
kitchen = eval(kitchen_str.strip)
|
127
|
+
puts "#{settings}"
|
128
|
+
puts "Preparing the food"
|
129
|
+
if kitchen.nil?
|
130
|
+
kitchen = {}
|
131
|
+
end
|
84
132
|
|
85
|
-
#kill old default.conf
|
86
|
-
#puts "Reloading nginx config"
|
87
|
-
#
|
88
|
-
#write new default conf file
|
89
133
|
|
90
|
-
|
134
|
+
new_nginx = ""
|
91
135
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
#run new unicorns
|
136
|
+
#kill old unicorns
|
137
|
+
puts "Grinding up the unicorns"
|
138
|
+
kitchen.each do |key,value|
|
139
|
+
str = "#{value[:pwd]}/pids/unicorn.pid"
|
140
|
+
puts str
|
141
|
+
unicorn_id = IO.readlines(str).join.strip
|
142
|
+
puts `kill "#{unicorn_id}"`
|
143
|
+
end
|
102
144
|
|
103
|
-
|
145
|
+
#run new unicorns
|
104
146
|
|
105
|
-
|
106
|
-
kitchen.delete("#{app_name}".to_sym)
|
107
|
-
end
|
147
|
+
puts "Making your order"
|
108
148
|
|
109
|
-
|
149
|
+
if kitchen["#{app_name}".to_sym]
|
150
|
+
kitchen.delete("#{app_name}".to_sym)
|
151
|
+
end
|
110
152
|
|
111
|
-
|
112
|
-
kitchen.each do |key,value|
|
113
|
-
puts `unicorn -c "#{value[:pwd]}"/unicorn.rb -D`
|
114
|
-
value[:pid] = IO.readlines("#{value[:pwd]}/pids/unicorn.pid").join.strip
|
115
|
-
app_name = key
|
116
|
-
domain_name = settings[:domain]
|
117
|
-
#new_nginx += gen_nginx(key,settings[:domain])
|
118
|
-
new_nginx += "
|
153
|
+
kitchen["#{app_name}".to_sym] = {pwd: "#{`pwd`}".strip, rails_app: "#{rails_app}"}
|
119
154
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
155
|
+
puts "Making the patties"
|
156
|
+
puts "#{kitchen}"
|
157
|
+
kitchen.each do |key,value|
|
158
|
+
if value[:rails_app].downcase == "true"
|
159
|
+
puts `unicorn_rails -c "#{value[:pwd]}"/config/unicorn.rb -D`
|
160
|
+
else
|
161
|
+
puts `unicorn -c "#{value[:pwd]}"/unicorn.rb -D`
|
162
|
+
end
|
163
|
+
value[:pid] = IO.readlines("#{value[:pwd]}/pids/unicorn.pid").join.strip
|
164
|
+
app_name = key
|
165
|
+
domain_name = settings[:domain]
|
166
|
+
#new_nginx += gen_nginx(key,settings[:domain])
|
167
|
+
new_nginx += "
|
124
168
|
|
125
|
-
|
169
|
+
upstream #{app_name} {
|
170
|
+
# Path to Unicorn SOCK file, as defined previously
|
171
|
+
server unix:/tmp/unicorn.#{app_name}.sock fail_timeout=0;
|
172
|
+
}
|
126
173
|
|
174
|
+
server {
|
127
175
|
|
128
|
-
listen 80;
|
129
176
|
|
130
|
-
|
131
|
-
server_name localhost #{app_name}.#{domain_name};
|
177
|
+
listen 80;
|
132
178
|
|
133
|
-
|
134
|
-
|
179
|
+
# Set the server name, similar to Apache's settings
|
180
|
+
server_name localhost #{app_name}.#{domain_name};
|
135
181
|
|
136
|
-
|
182
|
+
# Application root, as defined previously
|
183
|
+
root /var/www/#{app_name}/public;
|
137
184
|
|
138
|
-
|
139
|
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
140
|
-
proxy_set_header Host $http_host;
|
141
|
-
proxy_redirect off;
|
142
|
-
proxy_pass http://#{app_name};
|
143
|
-
}
|
185
|
+
try_files $uri/index.html $uri @#{app_name};
|
144
186
|
|
145
|
-
|
146
|
-
|
147
|
-
|
187
|
+
location @#{app_name} {
|
188
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
189
|
+
proxy_set_header Host $http_host;
|
190
|
+
proxy_redirect off;
|
191
|
+
proxy_pass http://#{app_name};
|
192
|
+
}
|
148
193
|
|
149
|
-
|
194
|
+
error_page 500 502 503 504 /500.html;
|
195
|
+
client_max_body_size 4G;
|
196
|
+
keepalive_timeout 10;
|
150
197
|
|
151
|
-
|
152
|
-
end
|
198
|
+
}
|
153
199
|
|
154
|
-
|
155
|
-
|
200
|
+
"
|
201
|
+
end
|
156
202
|
|
157
|
-
|
158
|
-
|
203
|
+
File.write(kitchen_path, "#{kitchen}")
|
204
|
+
File.write("/etc/nginx/conf.d/default.conf",new_nginx)
|
159
205
|
|
206
|
+
#restart nginx
|
207
|
+
puts `service nginx restart`
|
208
|
+
end
|
160
209
|
end
|
161
210
|
end
|
162
211
|
|