haproxy_join 0.1
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 +23 -0
- data/bin/haproxy_join +98 -0
- metadata +56 -0
data/README
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
haproxy_join : break up a monolithic haproxy config and join the files together
|
2
|
+
|
3
|
+
This code is available as Open Source Software under the MIT license.
|
4
|
+
|
5
|
+
Details:
|
6
|
+
|
7
|
+
This script accepts a filename (FILE_NAME) as the first arg and a path (HAPROXY_PATH) as the second. It expects the haproxy files/directories to be located as follows:
|
8
|
+
|
9
|
+
HAPROXY_PATH/conf/global.cfg (file)
|
10
|
+
HAPROXY_PATH/conf/defaults.cfg (file)
|
11
|
+
HAPROXY_PATH/conf/frontend.cfg (file)
|
12
|
+
HAPROXY_PATH/conf/frontend.d (dir of frontend configs)
|
13
|
+
HAPROXY_PATH/conf/backend.d (dir backend configs)
|
14
|
+
|
15
|
+
The script will concatenate these files together to in the appropriate order to create a single large haproxy configuration at HAPROXY_PATH/FILE_NAME. Also note that under the frontend.d and backend.d the script only picks up files with a ".cfg" extension. It wil also attempt to create a backup of the already joined config file.
|
16
|
+
|
17
|
+
Usage:
|
18
|
+
|
19
|
+
# haproxy_join haproxy.cfg /etc/haproxy/
|
20
|
+
|
21
|
+
This will join all the configs under /etc/haproxy/conf/ in the above directory format and write the resulting file at /etc/haproxy/haproxy.cfg.
|
22
|
+
|
23
|
+
Thanks to Holger Just for his haproxy config tool (http://github.com/finnlabs/haproxy/tree/master) which provided the inspiration for this one.
|
data/bin/haproxy_join
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
## Copyright 2009, Joe Williams <joe@joetify.com>
|
4
|
+
##
|
5
|
+
## Permission is hereby granted, free of charge, to any person
|
6
|
+
## obtaining a copy of this software and associated documentation
|
7
|
+
## files (the "Software"), to deal in the Software without
|
8
|
+
## restriction, including without limitation the rights to use,
|
9
|
+
## copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
## copies of the Software, and to permit persons to whom the
|
11
|
+
## Software is furnished to do so, subject to the following
|
12
|
+
## conditions:
|
13
|
+
##
|
14
|
+
## The above copyright notice and this permission notice shall be
|
15
|
+
## included in all copies or substantial portions of the Software.
|
16
|
+
##
|
17
|
+
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
19
|
+
## OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
21
|
+
## HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
22
|
+
## WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
23
|
+
## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
24
|
+
## OTHER DEALINGS IN THE SOFTWARE.
|
25
|
+
|
26
|
+
require 'find'
|
27
|
+
require 'ftools'
|
28
|
+
|
29
|
+
def write_main(haproxy_dir)
|
30
|
+
global = File.new(
|
31
|
+
File.join(haproxy_dir, "conf", "global.cfg"), "r"
|
32
|
+
)
|
33
|
+
|
34
|
+
defaults = File.new(
|
35
|
+
File.join(haproxy_dir, "conf", "defaults.cfg"), "r"
|
36
|
+
)
|
37
|
+
|
38
|
+
frontend = File.new(
|
39
|
+
File.join(haproxy_dir, "conf", "frontend.cfg"), "r"
|
40
|
+
)
|
41
|
+
|
42
|
+
@haproxy_config.write(global.read)
|
43
|
+
@haproxy_config.write(defaults.read)
|
44
|
+
@haproxy_config.write(frontend.read)
|
45
|
+
|
46
|
+
global.close
|
47
|
+
defaults.close
|
48
|
+
frontend.close
|
49
|
+
end
|
50
|
+
|
51
|
+
def write_d(config_d)
|
52
|
+
config_files = []
|
53
|
+
|
54
|
+
# use .cfg as file extension for all configs
|
55
|
+
extension = ".cfg"
|
56
|
+
|
57
|
+
Find.find(config_d) do |file|
|
58
|
+
if extension.include?(File.extname(file))
|
59
|
+
config_files << file
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
config_files.each do |file|
|
64
|
+
@haproxy_config.write(
|
65
|
+
File.new(File.join(file), "r").read
|
66
|
+
)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def main
|
71
|
+
haproxy_filename = ARGV[0]
|
72
|
+
haproxy_dir = ARGV[1]
|
73
|
+
|
74
|
+
if ARGV.length != 2
|
75
|
+
puts "haproxy_join usage: \n# haproxy_join RESULT_CONFIG CONFIG_DIR"
|
76
|
+
else
|
77
|
+
main_config = File.join(haproxy_dir, haproxy_filename)
|
78
|
+
|
79
|
+
if File.exist?(main_config)
|
80
|
+
File.copy(main_config, main_config + ".BAK-" + Time.now.strftime("%Y%m%d%H%M%S"))
|
81
|
+
end
|
82
|
+
|
83
|
+
@haproxy_config = File.new(main_config, "w")
|
84
|
+
|
85
|
+
write_main(haproxy_dir)
|
86
|
+
|
87
|
+
write_d(
|
88
|
+
File.join(haproxy_dir, "conf", "frontend.d")
|
89
|
+
)
|
90
|
+
write_d(
|
91
|
+
File.join(haproxy_dir, "conf", "backend.d")
|
92
|
+
)
|
93
|
+
|
94
|
+
@haproxy_config.close
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
main
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: haproxy_join
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- joe williams
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-03 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: joe@joetify.com
|
18
|
+
executables:
|
19
|
+
- haproxy_join
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- bin/haproxy_join
|
26
|
+
- README
|
27
|
+
has_rdoc: true
|
28
|
+
homepage: http://github.com/joewilliams/haproxy_join
|
29
|
+
licenses: []
|
30
|
+
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
requirements: []
|
49
|
+
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.3.5
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: haproxy config management
|
55
|
+
test_files: []
|
56
|
+
|