Thin_Upstreams 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,45 +2,89 @@
2
2
  Thin\_Upstreams
3
3
  ================
4
4
 
5
- A Ruby gem to generate .conf files with upstreams
5
+ A Ruby gem to generate partial .conf files with upstreams
6
6
  to include in your nginx.conf. It uses your Thin
7
- configuration files.
7
+ .yml configuration files.
8
+
9
+ Assuming you have a directory structure of:
10
+
11
+ /cwd (current working directory)
12
+ |-- Hi/config/thin.yml (port 6010, servers 3)
13
+ |-- Hello/config/thin.yml (port 7000, servers 2)
14
+
15
+ The file would be generated as `/cwd/upstreams.conf`:
16
+
17
+ upstream Hi {
18
+ server 127.0.0.1:6010;
19
+ server 127.0.0.1:6011;
20
+ server 127.0.0.1:6012;
21
+ }
22
+
23
+ upstream Hello {
24
+ server 127.0.0.1:7000;
25
+ server 127.0.0.1:7001;
26
+ }
27
+
28
+ Then, in your nginx.conf:
29
+
30
+ # ... your other settings
31
+
32
+ http {
33
+
34
+ # ... your other settings
35
+
36
+ include /cwd/upstreams.conf;
37
+
38
+ server {
39
+
40
+ location / {
41
+ proxy_pass http://Hi;
42
+ }
43
+
44
+ location /sub {
45
+ proxy_pass http://Hello;
46
+ }
47
+ }
48
+ }
49
+
8
50
 
9
51
  Installation
10
52
  ------------
11
53
 
12
- gem 'Thin_Upstreams'
54
+ gem install Thin_Upstreams
55
+
56
+ Note: Output File
57
+ ----
58
+
59
+ * Output file name: `upstreams.conf`
60
+ * You can't specify file output name.
61
+ * File is overwritten. No safety checks or warnings.
13
62
 
14
- Notes
15
- -----
16
-
17
- File upstreams.conf is created in current working directory.
18
- You can't specify file output name.
19
63
 
20
64
  Usage: In Ruby
21
65
  ------
22
66
 
23
- Accepts optional file globs:
67
+ Accepts optional file glob:
24
68
 
25
69
  require "Thin_Upstreams"
26
70
 
27
- Dir.chdir("/apps") {
71
+ Dir.chdir("/my_apps") {
28
72
  Thin_Upstreams()
29
- Thin_Upstreams "*/configs/my.thin.yml", "./**/config.yml"
73
+ Thin_Upstreams "*/configs/my.thin.yml"
30
74
  }
31
75
 
32
- File /app/upstreams.conf is created/overwritten. You
76
+ File /my\_apps/upstreams.conf is created/overwritten.
33
77
 
34
78
  Usage: Bash/Shell
35
79
  ------
36
80
 
37
- File glob arguments are optional:
81
+ File glob argument is optional:
38
82
 
39
- cd /apps
83
+ cd /my_apps
40
84
  Thin_Upstreams
41
- Thin_Upstreams "*/configs/my.thin.yml", "./**/config.yml"
85
+ Thin_Upstreams "*/configs/my.thin.yml"
42
86
 
43
- File /app/upstreams.conf is created/overwritten.
87
+ File /my\_app/upstreams.conf is created/overwritten.
44
88
 
45
89
  Run Tests
46
90
  ---------
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
22
  s.require_paths = ["lib"]
23
23
 
24
- s.add_development_dependency 'Exit_Zero'
24
+ s.add_development_dependency 'Exit_0'
25
25
  s.add_development_dependency 'bacon'
26
26
  s.add_development_dependency 'rake'
27
27
  s.add_development_dependency 'Bacon_Colored'
@@ -1,3 +1,3 @@
1
1
  class Thin_Upstreams
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -4,7 +4,7 @@ require "yaml"
4
4
  def Thin_Upstreams glob = "./*/config/thin.yml"
5
5
 
6
6
  str = %~\n~
7
- arr = Dir.glob(glob).each { |file|
7
+ arr = Dir.glob(glob).sort.each { |file|
8
8
  o = YAML::load File.read(file)
9
9
  app_name = begin
10
10
  pwd = File.join( File.expand_path("."), "/" )
data/spec/main.rb CHANGED
@@ -3,40 +3,42 @@ require File.expand_path('spec/helper')
3
3
  require 'Thin_Upstreams'
4
4
  require 'Bacon_Colored'
5
5
  require 'pry'
6
- require 'Exit_Zero'
6
+ require 'Exit_0'
7
7
 
8
8
  DIR = "/tmp/Thin_Upstreams"
9
9
 
10
+ def chdir
11
+ Dir.chdir(DIR) {
12
+ yield
13
+ }
14
+ end
15
+
10
16
  def reset_dir
11
- Exit_Zero "rm -rf #{DIR}"
17
+ Exit_0 "rm -rf #{DIR}"
12
18
 
13
- Exit_Zero "mkdir -p #{DIR}/Hi/config"
14
- Exit_Zero "mkdir -p #{DIR}/Hi/custom"
19
+ Exit_0 "mkdir -p #{DIR}/Hi/config"
20
+ Exit_0 "mkdir -p #{DIR}/Hi/custom"
15
21
 
16
- Exit_Zero "mkdir -p #{DIR}/Hello/config"
17
- Exit_Zero "mkdir -p #{DIR}/Hello/custom"
22
+ Exit_0 "mkdir -p #{DIR}/Hello/config"
23
+ Exit_0 "mkdir -p #{DIR}/Hello/custom"
18
24
 
19
25
  chdir {
20
- Exit_Zero "cd Hi/config && bundle exec thin config -C thin.yml --port 3010 --servers 2"
21
- Exit_Zero "cd Hello/config && bundle exec thin config -C thin.yml --port 4010 --servers 3"
26
+ Exit_0 "cd Hi/config && bundle exec thin config -C thin.yml --port 3010 --servers 2"
27
+ Exit_0 "cd Hello/config && bundle exec thin config -C thin.yml --port 4010 --servers 3"
22
28
 
23
- Exit_Zero "cd Hi/custom && bundle exec thin config -C my.yml --port 6010 --servers 4"
24
- Exit_Zero "cd Hello/custom && bundle exec thin config -C my.yml --port 7010 --servers 5"
29
+ Exit_0 "cd Hi/custom && bundle exec thin config -C my.yml --port 6010 --servers 4"
30
+ Exit_0 "cd Hello/custom && bundle exec thin config -C my.yml --port 7010 --servers 5"
25
31
  }
26
32
  end
27
33
 
34
+ reset_dir
35
+
28
36
  def reset_file
29
37
  chdir {
30
38
  file = "upstreams.conf"
31
39
  nginx = "nginx.conf"
32
- Exit_Zero "rm #{file}" if File.exists?(file)
33
- Exit_Zero "rm #{nginx}" if File.exists?(nginx)
34
- }
35
- end
36
-
37
- def chdir
38
- Dir.chdir(DIR) {
39
- yield
40
+ Exit_0 "rm #{file}" if File.exists?(file)
41
+ Exit_0 "rm #{nginx}" if File.exists?(nginx)
40
42
  }
41
43
  end
42
44
 
data/spec/tests/bin.rb CHANGED
@@ -17,7 +17,7 @@ describe "Thin_Upstreams (bin executable)" do
17
17
  it "creates upstreams.conf file" do
18
18
  target = "upstream Hi"
19
19
  chdir {
20
- Exit_Zero "Thin_Upstreams"
20
+ Exit_0 "Thin_Upstreams"
21
21
  File.read("upstreams.conf")[target].should == target
22
22
  }
23
23
  end
@@ -25,7 +25,7 @@ describe "Thin_Upstreams (bin executable)" do
25
25
  it "accepts a file glob" do
26
26
  target = ":601"
27
27
  chdir {
28
- Exit_Zero "Thin_Upstreams \"*/custom/*.yml\""
28
+ Exit_0 "Thin_Upstreams \"*/custom/*.yml\""
29
29
  File.read("upstreams.conf")[target].should == target
30
30
  }
31
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Thin_Upstreams
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,10 +9,10 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-14 00:00:00.000000000 Z
12
+ date: 2012-04-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: Exit_Zero
15
+ name: Exit_0
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  version: '0'
150
150
  requirements: []
151
151
  rubyforge_project:
152
- rubygems_version: 1.8.19
152
+ rubygems_version: 1.8.23
153
153
  signing_key:
154
154
  specification_version: 3
155
155
  summary: Create upstreams conf file for Nginx.