tuesday 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/kitchen +1 -0
  3. data/lib/tuesday.rb +166 -117
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5352c8e9dcaf1ec3a339e86586e051621d9be87
4
- data.tar.gz: 37ebeabe09d4acff24a5935c370ffdca676f0f1c
3
+ metadata.gz: 196906735eea820b326932b7dbdb041dc6f8e9ba
4
+ data.tar.gz: 6f6e4659d92779cc36954cc2909bd042e74c0a43
5
5
  SHA512:
6
- metadata.gz: fee4e84f20ebff043e715ec284d940770a18e8fe7445a58429e4d6927d8a981541e99182fd050563e5e4829b8051d0a2d76510eb0bbc793ad453174565a1f4ef
7
- data.tar.gz: bc44f673c8d54cc24fb1c7ce00672601e2bf908da926a9c2829a401c3971d187120b7a1c2b34195359b57b307048200b4a840028fdd9f9dbb1a44a06f2243074
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
- puts "#praisecatgod"
6
- settings = {}
7
-
8
- begin
9
- # Exceptions raised by this code will
10
- # be caught by the following rescue clause
11
- settings = eval "{#{IO.readlines('Menufile').join.strip}}"
12
-
13
- rescue
14
- puts "You don't have a Menufile. Please consult http://tuesdayrb.me for support.
15
- Thank you please come again."
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
- output = `bundle install --without production`
20
- puts output
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
- output = `gem list`
23
- #puts output
24
- unicorn_output = output.match(/unicorn (.*)\n/)
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 "reservation made for mr. unicorn"
30
- end
31
- output = `pwd`
32
- app_name = output.split("/").last
33
- app_name.strip!
34
- puts "I see you would like the #{app_name}. Very fine choice"
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
- base_unicorn = "
37
- working_directory '/var/www/#{app_name}'
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
- pid '/var/www/#{app_name}/pids/unicorn.pid'
59
+ output = `bundle install --without production`
60
+ puts output
40
61
 
41
- stderr_path '/var/www/#{app_name}/logs/unicorn.log'
42
- stdout_path '/var/www/#{app_name}/logs/unicorn.log'
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
- listen '/tmp/unicorn.#{app_name}.sock'
79
+ pid '/var/www/#{app_name}/pids/unicorn.pid'
45
80
 
46
- # Number of processes
47
- # worker_processes 4
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
- # Time-out
51
- timeout 30
84
+ listen '/tmp/unicorn.#{app_name}.sock'
52
85
 
53
- "
54
- puts `rm unicorn.rb`
55
- puts `echo "#{base_unicorn}" >> unicorn.rb`
86
+ # Number of processes
87
+ # worker_processes 4
88
+ worker_processes 1
56
89
 
57
- puts `mkdir logs pids`
90
+ # Time-out
91
+ timeout 30
58
92
 
59
- nginx = `which nginx`
60
- if nginx == ""
61
- #install nginx
62
- if `uname`.strip == "Darwin"
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 `apt-get install nginx`
98
+ puts `echo "#{base_unicorn}" >> unicorn.rb`
66
99
  end
67
- end
68
100
 
69
- #kill the bad nginx
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
- #build new temp default.conf file
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
- new_nginx = ""
134
+ new_nginx = ""
91
135
 
92
- #kill old unicorns
93
- puts "Grinding up the unicorns"
94
- kitchen.each do |key,value|
95
- str = "#{value[:pwd]}/pids/unicorn.pid"
96
- puts str
97
- unicorn_id = IO.readlines(str).join.strip
98
- puts `kill "#{unicorn_id}"`
99
- end
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
- puts "Making your order"
145
+ #run new unicorns
104
146
 
105
- if kitchen["#{app_name}".to_sym]
106
- kitchen.delete("#{app_name}".to_sym)
107
- end
147
+ puts "Making your order"
108
148
 
109
- kitchen["#{app_name}".to_sym] = {pwd: "#{`pwd`}".strip}
149
+ if kitchen["#{app_name}".to_sym]
150
+ kitchen.delete("#{app_name}".to_sym)
151
+ end
110
152
 
111
- puts "Making the patties"
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
- upstream #{app_name} {
121
- # Path to Unicorn SOCK file, as defined previously
122
- server unix:/tmp/unicorn.#{app_name}.sock fail_timeout=0;
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
- server {
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
- # Set the server name, similar to Apache's settings
131
- server_name localhost #{app_name}.#{domain_name};
177
+ listen 80;
132
178
 
133
- # Application root, as defined previously
134
- root /var/www/#{app_name}/public;
179
+ # Set the server name, similar to Apache's settings
180
+ server_name localhost #{app_name}.#{domain_name};
135
181
 
136
- try_files $uri/index.html $uri @#{app_name};
182
+ # Application root, as defined previously
183
+ root /var/www/#{app_name}/public;
137
184
 
138
- location @#{app_name} {
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
- error_page 500 502 503 504 /500.html;
146
- client_max_body_size 4G;
147
- keepalive_timeout 10;
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
- File.write('/usr/local/bin/kitchen', "#{kitchen}")
155
- File.write("/etc/nginx/conf.d/default.conf",new_nginx)
200
+ "
201
+ end
156
202
 
157
- #restart nginx
158
- puts `service nginx restart`
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tuesday
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yves DeSousa