web_server_config_generator 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +0 -0
- data/lib/web_server_config_generator/generator.rb +42 -43
- data/lib/web_server_config_generator/nginx_conf.rb +0 -0
- data/lib/web_server_config_generator/pathname.rb +0 -0
- data/lib/web_server_config_generator/project_directory.rb +0 -0
- data/lib/web_server_config_generator/sub_uri_project.rb +0 -0
- metadata +6 -4
data/README
CHANGED
Binary file
|
@@ -4,17 +4,17 @@ module WebServerConfigGenerator
|
|
4
4
|
options.each do |opt, val|
|
5
5
|
instance_variable_set("@#{opt}", val)
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
@starting_port = options[:starting_port] || 40000
|
9
9
|
@port_pool_size = options[:port_pool_size] || 10000
|
10
|
-
|
10
|
+
|
11
11
|
@environment_map = Hash.new(options[:environments]) if options[:environments]
|
12
12
|
|
13
13
|
setup_config_dir
|
14
|
-
|
14
|
+
|
15
15
|
@project_or_projects_dir ||= projects_dir
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def write_conf_files
|
19
19
|
FileUtils.cd projects_dir do
|
20
20
|
# generate files for each proj/env
|
@@ -24,7 +24,7 @@ module WebServerConfigGenerator
|
|
24
24
|
list_of_conf_files << write_conf_file(p, env)
|
25
25
|
end
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
sub_uri_projects.each do |p|
|
29
29
|
create_sub_uri_links_dir p
|
30
30
|
list_of_conf_files << write_conf_file(p, p.env)
|
@@ -38,10 +38,10 @@ module WebServerConfigGenerator
|
|
38
38
|
web_server_vhost_nginx_conf.write(new_lines.join)
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def create_sub_uri_links_dir(sub_uri_project)
|
43
43
|
env = sub_uri_project.env
|
44
|
-
|
44
|
+
|
45
45
|
web_server_sub_uri_apps_dir.mkdir unless web_server_sub_uri_apps_dir.exist?
|
46
46
|
links_dir = web_server_sub_uri_apps_dir + sub_uri_project.server_name
|
47
47
|
links_dir.mkdir unless links_dir.exist?
|
@@ -56,7 +56,7 @@ module WebServerConfigGenerator
|
|
56
56
|
def server_names
|
57
57
|
projects.map { |p| p.server_names }.flatten.uniq
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def delete_ghost_entries
|
61
61
|
global_config[:hosts].each do |host|
|
62
62
|
Host.delete host
|
@@ -64,7 +64,7 @@ module WebServerConfigGenerator
|
|
64
64
|
global_config[:hosts] = []
|
65
65
|
save_global_config(global_config)
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
def add_ghost_entries
|
69
69
|
current_hosts = Host.list
|
70
70
|
already_correct = []
|
@@ -88,18 +88,18 @@ module WebServerConfigGenerator
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
if already_correct.size > 0
|
93
93
|
puts "\n#{already_correct.size} hosts were already setup correctly"
|
94
94
|
puts
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
if added.size > 0
|
98
98
|
puts "The following hostnames were added for 127.0.0.1:"
|
99
99
|
puts added.map { |h| " #{h.name}\n" }
|
100
100
|
puts
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
if present_but_incorrect.size > 0
|
104
104
|
puts "The following hostnames were present, but didn't map to 127.0.0.1:"
|
105
105
|
pad = present_but_incorrect.max{|a,b| a.to_s.length <=> b.to_s.length }.to_s.length
|
@@ -107,7 +107,7 @@ module WebServerConfigGenerator
|
|
107
107
|
puts
|
108
108
|
end
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
def setup_config_dir
|
112
112
|
unless File.exist?(config_dir)
|
113
113
|
unless dir = $PROJECTS_DIRECTORY
|
@@ -120,13 +120,13 @@ module WebServerConfigGenerator
|
|
120
120
|
end
|
121
121
|
puts "setting up config dir"
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
FileUtils.mkdir_p config_dir
|
125
125
|
initial_config = { :projects_dirs => [File.expand_path(dir)]}
|
126
126
|
save_global_config(initial_config)
|
127
127
|
end
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
def symlink(link_target, link_name)
|
131
131
|
if File.exist?(link_name)
|
132
132
|
if FileTest.symlink?(link_name)
|
@@ -140,7 +140,7 @@ module WebServerConfigGenerator
|
|
140
140
|
File.symlink link_target, link_name
|
141
141
|
end
|
142
142
|
end
|
143
|
-
|
143
|
+
|
144
144
|
def setup_webserver_links_dir
|
145
145
|
web_server_links_dir.mkpath
|
146
146
|
environments.each do |e|
|
@@ -148,7 +148,7 @@ module WebServerConfigGenerator
|
|
148
148
|
symlink(projects_dir, link_name)
|
149
149
|
end
|
150
150
|
end
|
151
|
-
|
151
|
+
|
152
152
|
def app_projects
|
153
153
|
@app_projects ||=
|
154
154
|
begin
|
@@ -156,7 +156,7 @@ module WebServerConfigGenerator
|
|
156
156
|
@app_projects
|
157
157
|
end
|
158
158
|
end
|
159
|
-
|
159
|
+
|
160
160
|
def sub_uri_projects
|
161
161
|
return @sub_uri_projects if @sub_uri_projects
|
162
162
|
server_name_env_project_map = {}
|
@@ -178,19 +178,19 @@ module WebServerConfigGenerator
|
|
178
178
|
WebServerConfigGenerator::SubUriProject.new(server_name, env_and_projects, self)
|
179
179
|
end
|
180
180
|
end
|
181
|
-
|
181
|
+
|
182
182
|
def projects
|
183
183
|
app_projects + sub_uri_projects
|
184
184
|
end
|
185
|
-
|
185
|
+
|
186
186
|
def environments
|
187
187
|
@environments ||= environment_map.values.flatten.uniq
|
188
188
|
end
|
189
|
-
|
189
|
+
|
190
190
|
def web_server_vhost_nginx_conf
|
191
191
|
web_server_vhost_nginx_dir + "projects.conf"
|
192
192
|
end
|
193
|
-
|
193
|
+
|
194
194
|
def check_nginx_conf
|
195
195
|
unless nginx_conf =~ /include.*#{web_server_vhost_nginx_conf}/
|
196
196
|
puts "\nWarning: You'll need to make sure this line is in your nginx config, in the http block:"
|
@@ -202,31 +202,31 @@ module WebServerConfigGenerator
|
|
202
202
|
puts " server_names_hash_bucket_size 128;"
|
203
203
|
end
|
204
204
|
end
|
205
|
-
|
205
|
+
|
206
206
|
def prompt_to_restart_nginx
|
207
207
|
puts
|
208
208
|
if $RESTART_NGINX || ($RESTART_NGINX.nil? && agree("Restart nginx? [Y/n]") { |q| q.default = "Y"})
|
209
209
|
puts "Restarting nginx..."
|
210
|
-
cmd = "sudo
|
210
|
+
cmd = "sudo #{nginx} -s quit; sleep 1 && sudo #{nginx}"
|
211
211
|
puts "running: #{cmd}"
|
212
212
|
system cmd
|
213
213
|
end
|
214
214
|
end
|
215
|
-
|
215
|
+
|
216
216
|
def web_server_links_dir
|
217
217
|
config_dir + "links"
|
218
218
|
end
|
219
|
-
|
219
|
+
|
220
220
|
def projects_dir
|
221
221
|
WebServerConfigGenerator::Pathname.new(global_config[:projects_dirs].first).expand_path
|
222
222
|
end
|
223
|
-
|
223
|
+
|
224
224
|
def web_server_sub_uri_apps_dir
|
225
225
|
config_dir + "sub_uri_apps"
|
226
226
|
end
|
227
|
-
|
227
|
+
|
228
228
|
private
|
229
|
-
|
229
|
+
|
230
230
|
def config_dir
|
231
231
|
@config_dir ||=
|
232
232
|
begin
|
@@ -236,29 +236,29 @@ module WebServerConfigGenerator
|
|
236
236
|
end
|
237
237
|
end
|
238
238
|
end
|
239
|
-
|
239
|
+
|
240
240
|
def global_config(reload = false)
|
241
241
|
@global_config = nil if reload
|
242
242
|
@global_config ||= YAML.load_file(global_config_path)
|
243
243
|
end
|
244
|
-
|
244
|
+
|
245
245
|
def save_global_config(config)
|
246
246
|
@global_config = config
|
247
247
|
File.open(global_config_path, "w") { |f| f.write config.to_yaml }
|
248
248
|
end
|
249
|
-
|
249
|
+
|
250
250
|
def global_config_path
|
251
251
|
File.join(config_dir, "global_config.yml")
|
252
252
|
end
|
253
|
-
|
253
|
+
|
254
254
|
def web_server_vhost_dir
|
255
255
|
config_dir + "vhost"
|
256
256
|
end
|
257
|
-
|
257
|
+
|
258
258
|
def web_server_vhost_nginx_dir
|
259
259
|
web_server_vhost_dir + "nginx"
|
260
260
|
end
|
261
|
-
|
261
|
+
|
262
262
|
def find_project_and_symlink_dirs
|
263
263
|
@app_projects ||= []
|
264
264
|
|
@@ -266,7 +266,7 @@ module WebServerConfigGenerator
|
|
266
266
|
@app_projects = [WebServerConfigGenerator::ProjectDirectory.new(@project_or_projects_dir, self)]
|
267
267
|
return
|
268
268
|
end
|
269
|
-
|
269
|
+
|
270
270
|
[
|
271
271
|
Dir[File.join(projects_dir, "*", ".webconfig.yml")],
|
272
272
|
Dir[File.join(projects_dir, "*", "*", ".webconfig.yml")],
|
@@ -275,15 +275,15 @@ module WebServerConfigGenerator
|
|
275
275
|
@app_projects << WebServerConfigGenerator::ProjectDirectory.new(path, self)
|
276
276
|
end
|
277
277
|
end
|
278
|
-
|
278
|
+
|
279
279
|
def projects_environment_map
|
280
280
|
app_projects.inject({}) { |map, p| map[p] = p.environments; map }
|
281
281
|
end
|
282
|
-
|
282
|
+
|
283
283
|
def symlinks_environment_map
|
284
284
|
sub_uri_projects.inject({}) { |map, p| map[p] = p.env.to_s; map }
|
285
285
|
end
|
286
|
-
|
286
|
+
|
287
287
|
def environment_map
|
288
288
|
@environment_map ||= projects_environment_map.merge(symlinks_environment_map)
|
289
289
|
end
|
@@ -307,12 +307,12 @@ module WebServerConfigGenerator
|
|
307
307
|
# end
|
308
308
|
project_env_vhost_filename.expand_path
|
309
309
|
end
|
310
|
-
|
310
|
+
|
311
311
|
def nginx_conf_path
|
312
312
|
m = `#{nginx} -t 2>&1`.match /the configuration file (.*) syntax is ok/
|
313
313
|
m[1]
|
314
314
|
end
|
315
|
-
|
315
|
+
|
316
316
|
def nginx_conf
|
317
317
|
@nginx_conf ||= begin
|
318
318
|
File.read(nginx_conf_path)
|
@@ -329,7 +329,6 @@ module WebServerConfigGenerator
|
|
329
329
|
]
|
330
330
|
nginx_path_options.detect { |p| system "which #{p} &> /dev/null" }
|
331
331
|
end
|
332
|
-
|
332
|
+
|
333
333
|
end
|
334
334
|
end
|
335
|
-
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 3
|
9
|
+
version: 0.1.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Expected Behavior
|
@@ -14,8 +14,8 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
18
|
-
default_executable:
|
17
|
+
date: 2010-04-14 00:00:00 -04:00
|
18
|
+
default_executable: web_server_setup
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: automatically generate web server config files for you projects directory
|
@@ -33,6 +33,8 @@ files:
|
|
33
33
|
- lib/web_server_config_generator/pathname.rb
|
34
34
|
- lib/web_server_config_generator/project_directory.rb
|
35
35
|
- lib/web_server_config_generator/sub_uri_project.rb
|
36
|
+
- bin/web_server_setup
|
37
|
+
- README
|
36
38
|
has_rdoc: true
|
37
39
|
homepage: http://github.com/expectedbehavior/web_server_config_generator
|
38
40
|
licenses: []
|