multibinder 0.0.4 → 0.0.5
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.
- checksums.yaml +4 -4
- data/bin/multibinder-haproxy-erb +2 -2
- data/bin/multibinder-haproxy-wrapper +5 -2
- data/haproxy/README.md +95 -0
- data/lib/multibinder.rb +4 -0
- data/lib/multibinder/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48c7529264a07e02ceede53195b8865e5d333b55
|
4
|
+
data.tar.gz: a46092b200c70902b02fe4d3ba9a76dfb64eb6c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9353acb7fad02a3a1d84b5a8ab4befa95c3120db2bde5bcaa8db361fdcaa8a248d0bf4db6f08fad4397f76afaf2cdc5b7c612569748ffc1e8b4b8da68cfbe61
|
7
|
+
data.tar.gz: 63cde39aa688749c9d3800f64e408461b9dfcc2e74b56b6d199d6d312042c403f059d96749f37ec403f46b35cdf92eb408601b54db91259bb0876a925d46567a
|
data/bin/multibinder-haproxy-erb
CHANGED
@@ -13,8 +13,8 @@ haproxy_call = ARGV
|
|
13
13
|
abort 'multibinder-haproxy expects a configuration file to be passed to haproxy' if haproxy_call.index('-f').nil?
|
14
14
|
config_file_index = haproxy_call.index('-f') + 1
|
15
15
|
haproxy_erb = haproxy_call[config_file_index]
|
16
|
-
abort 'Config file must end with .erb' unless haproxy_erb.end_with? '.erb'
|
17
|
-
haproxy_cfg = haproxy_erb.sub(
|
16
|
+
abort 'Config file must end with .erb or .mb' unless haproxy_erb.end_with? '.erb' or haproxy_erb.end_with? '.mb'
|
17
|
+
haproxy_cfg = haproxy_erb.sub(/\.(erb|mb)$/, '')
|
18
18
|
haproxy_call[config_file_index] = haproxy_cfg
|
19
19
|
|
20
20
|
def bind_tcp(ip, port)
|
@@ -39,7 +39,10 @@ Signal.trap("USR2") do
|
|
39
39
|
|
40
40
|
# wait a while for the pid file to change. after a while, give up and unblock reloads
|
41
41
|
for i in 0..20
|
42
|
-
|
42
|
+
begin
|
43
|
+
break if File.read($PID_FILE) != old_pids
|
44
|
+
rescue Errno::ENOENT
|
45
|
+
end
|
43
46
|
sleep 1
|
44
47
|
end
|
45
48
|
end
|
@@ -61,4 +64,4 @@ begin
|
|
61
64
|
end
|
62
65
|
ensure
|
63
66
|
cleanup_existing
|
64
|
-
end
|
67
|
+
end
|
data/haproxy/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
## multibinder + HAProxy
|
2
|
+
|
3
|
+
HAProxy by default doesn't include support for zero-downtime reloads. multibinder was developed to work with HAProxy, and has some useful wrappers included that allow running multiple HAProxy instances with multibinder on the same machine, while enabling zero-downtime reloads.
|
4
|
+
|
5
|
+
### Installation on Ubuntu 16.04
|
6
|
+
|
7
|
+
Install multibinder and dependencies:
|
8
|
+
```
|
9
|
+
sudo apt-get install -y haproxy ruby
|
10
|
+
sudo gem install multibinder
|
11
|
+
```
|
12
|
+
|
13
|
+
The multibinder systemd scripts automatically support multiple haproxy instances, so stop and disable the default haproxy service:
|
14
|
+
```
|
15
|
+
sudo systemctl stop haproxy
|
16
|
+
sudo systemctl disable haproxy
|
17
|
+
```
|
18
|
+
|
19
|
+
Install the `multibinder` and `haproxy-multi@` systemd service files, and start multibinder itself:
|
20
|
+
```
|
21
|
+
sudo cp $(gem environment gemdir)/gems/multibinder-0.0.4/haproxy/*.service /etc/systemd/system/
|
22
|
+
sudo systemctl daemon-reload
|
23
|
+
|
24
|
+
sudo systemctl enable multibinder
|
25
|
+
sudo systemctl start multibinder
|
26
|
+
```
|
27
|
+
|
28
|
+
Create your first haproxy service configuration file, replacing all bind IP/ports with ERB code like the following:
|
29
|
+
```
|
30
|
+
cat >/etc/haproxy/foo.cfg.erb <<EOF
|
31
|
+
global
|
32
|
+
user haproxy
|
33
|
+
group haproxy
|
34
|
+
daemon
|
35
|
+
maxconn 256
|
36
|
+
|
37
|
+
defaults
|
38
|
+
mode http
|
39
|
+
timeout connect 5000ms
|
40
|
+
timeout client 50000ms
|
41
|
+
timeout server 50000ms
|
42
|
+
|
43
|
+
frontend http-in
|
44
|
+
bind <%= bind_tcp('0.0.0.0', 80) %>
|
45
|
+
EOF
|
46
|
+
```
|
47
|
+
|
48
|
+
Now start your multibinder-enabled haproxy `foo` service!
|
49
|
+
```
|
50
|
+
sudo systemctl enable haproxy-multi@foo
|
51
|
+
sudo systemctl start haproxy-multi@foo
|
52
|
+
```
|
53
|
+
|
54
|
+
You'll have a process tree like the following:
|
55
|
+
```
|
56
|
+
$ sudo systemctl status haproxy-multi@foo
|
57
|
+
● haproxy-multi@foo.service - HAProxy Load Balancer
|
58
|
+
Loaded: loaded (/etc/systemd/system/haproxy-multi@.service; enabled; vendor preset: enabled)
|
59
|
+
Active: active (running) since Mon 2016-10-31 20:56:28 UTC; 1s ago
|
60
|
+
Docs: man:haproxy(1)
|
61
|
+
file:/usr/share/doc/haproxy/configuration.txt.gz
|
62
|
+
Process: 3092 ExecStop=/bin/kill -TERM $MAINPID (code=exited, status=0/SUCCESS)
|
63
|
+
Process: 3076 ExecReload=/bin/sh -c /usr/local/bin/multibinder-haproxy-erb /usr/sbin/haproxy -c -f ${CONFIG}; /bin/kill -USR2 $MAINPID (code=exited, status=0/SUCCESS)
|
64
|
+
Process: 3105 ExecStartPre=/usr/local/bin/multibinder-haproxy-erb /usr/sbin/haproxy -f ${CONFIG} -c -q (code=exited, status=0/SUCCESS)
|
65
|
+
Main PID: 3109 (multibinder-hap)
|
66
|
+
CGroup: /system.slice/system-haproxy\x2dmulti.slice/haproxy-multi@foo.service
|
67
|
+
├─3109 /usr/bin/ruby2.3 /usr/local/bin/multibinder-haproxy-wrapper /usr/sbin/haproxy -Ds -f /etc/haproxy/foo.cfg.erb -p /run/haproxy-foo.pid
|
68
|
+
├─3113 /usr/sbin/haproxy -Ds -f /etc/haproxy/foo.cfg -p /run/haproxy-foo.pid
|
69
|
+
└─3115 /usr/sbin/haproxy -Ds -f /etc/haproxy/foo.cfg -p /run/haproxy-foo.pid
|
70
|
+
|
71
|
+
Oct 31 20:56:28 ip-172-31-8-204 systemd[1]: Starting HAProxy Load Balancer...
|
72
|
+
Oct 31 20:56:28 ip-172-31-8-204 systemd[1]: Started HAProxy Load Balancer.
|
73
|
+
```
|
74
|
+
|
75
|
+
With multibinder running separately from the haproxy process(es):
|
76
|
+
```
|
77
|
+
$ sudo systemctl status multibinder
|
78
|
+
● multibinder.service - Multibinder
|
79
|
+
Loaded: loaded (/etc/systemd/system/multibinder.service; enabled; vendor preset: enabled)
|
80
|
+
Active: active (running) since Mon 2016-10-31 20:50:05 UTC; 7min ago
|
81
|
+
Main PID: 2751 (multibinder)
|
82
|
+
Tasks: 2
|
83
|
+
Memory: 4.9M
|
84
|
+
CPU: 44ms
|
85
|
+
CGroup: /system.slice/multibinder.service
|
86
|
+
└─2751 /usr/bin/ruby2.3 /usr/local/bin/multibinder /run/multibinder.sock
|
87
|
+
|
88
|
+
Oct 31 20:50:05 ip-172-31-8-204 systemd[1]: Started Multibinder.
|
89
|
+
Oct 31 20:50:05 ip-172-31-8-204 multibinder[2751]: Listening for binds on control socket: /run/multibinder.sock
|
90
|
+
```
|
91
|
+
|
92
|
+
Reloading an haproxy instance safely can then be requested through systemctl:
|
93
|
+
```
|
94
|
+
$ sudo systemctl reload haproxy-multi@foo
|
95
|
+
```
|
data/lib/multibinder.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'multibinder/version'
|
2
2
|
require 'json'
|
3
|
+
require 'securerandom'
|
4
|
+
require 'socket'
|
5
|
+
require 'fcntl'
|
3
6
|
|
4
7
|
module MultiBinder
|
5
8
|
def self.bind(address, port, options={})
|
@@ -11,6 +14,7 @@ module MultiBinder
|
|
11
14
|
binder.sendmsg JSON.dump({
|
12
15
|
:jsonrpc => '2.0',
|
13
16
|
:method => 'bind',
|
17
|
+
:id => SecureRandom.uuid,
|
14
18
|
:params => [{
|
15
19
|
:address => address,
|
16
20
|
:port => port,
|
data/lib/multibinder/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multibinder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Theo Julienne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- bin/multibinder
|
57
57
|
- bin/multibinder-haproxy-erb
|
58
58
|
- bin/multibinder-haproxy-wrapper
|
59
|
+
- haproxy/README.md
|
59
60
|
- haproxy/haproxy-multi@.service
|
60
61
|
- haproxy/multibinder.service
|
61
62
|
- lib/multibinder.rb
|