Skip to content

Commit

Permalink
Add an endpoint to reload HAProxy config (#312)
Browse files Browse the repository at this point in the history
* First attempt at a reload endpoint

* Add --api-listen parameter

* Parse API listen URI before launching thread

* Catch errors early
* Apparently the http:// is important...

* Refactor config validation into separate method

* Simplify logic around skipping validation
* In preparation for testing existing config...

* Add the ability to reload existing HAProxy config

* <endpoint>/reload?existing

* Fix notifying bools in event processor

* Improve debug logging around config comparisons

* Tweak response messages for reload API

* Do a slightly better check on query params

* Add a README note about the endpoint

* Regenerate Longhelp.md

* Remove API and add signal handling to the event processor

* Revert "Regenerate Longhelp.md"

This reverts commit eef20c8.

* Revert "Add a README note about the endpoint"

This reverts commit c5a5c50.

* Add Lua script and endpoints to send signals to marathon-lb

* Write about new endpoints in README

* Regenerate Longhelp.md

* Add note to README about marathon-lb expecting to be in its own PID namespace
  • Loading branch information
JayH5 authored and brndnmtthws committed Sep 29, 2016
1 parent f7ca0e0 commit 54935d9
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 77 deletions.
6 changes: 6 additions & 0 deletions Longhelp.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ global
lua-load /marathon-lb/getpids.lua
lua-load /marathon-lb/getconfig.lua
lua-load /marathon-lb/getmaps.lua
lua-load /marathon-lb/signalmlb.lua
defaults
load-server-state-from-file global
log global
Expand Down Expand Up @@ -410,6 +411,11 @@ listen stats
http-request use-service lua.getappmap if getappmap
acl getconfig path /_haproxy_getconfig
http-request use-service lua.getconfig if getconfig
acl signalmlbhup path /_mlb_signal/hup
http-request use-service lua.signalmlbhup if signalmlbhup
acl signalmlbusr1 path /_mlb_signal/usr1
http-request use-service lua.signalmlbusr1 if signalmlbusr1
```
## `HAPROXY_HTTPS_FRONTEND_ACL`
*Overridable*
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ Marathon-lb exposes a few endpoints on port 9090 (by default). They are:
| `:9090/_haproxy_getvhostmap` | Returns the HAProxy vhost to backend map. This endpoint returns HAProxy map file only when the `--haproxy-map` flag is enabled, it returns an empty string otherwise. Implemented in [`getmaps.lua`](getmaps.lua). |
| `:9090/_haproxy_getappmap` | Returns the HAProxy app ID to backend map. Like `_haproxy_getvhostmap`, this requires the `--haproxy-map` flag to be enabled and returns an empty string otherwise. Also implemented in `getmaps.lua`. |
| `:9090/_haproxy_getpids` | Returns the PIDs for all HAProxy instances within the current process namespace. This literally returns `$(pidof haproxy)`. Implemented in [`getpids.lua`](getpids.lua). This is also used by the [`zdd.py`](zdd.py) script to determine if connections have finished draining during a deploy. |
| `:9090/_mlb_signal/hup`* | Sends a `SIGHUP` signal to the marathon-lb process, causing it to fetch the running apps from Marathon and reload the HAProxy config as though an event was received from Marathon. |
| `:9090/_mlb_signal/usr1`* | Sends a `SIGUSR1` signal to the marathon-lb process, causing it to restart HAProxy with the existing config, without checking Marathon for changes. |

\* These endpoints won't function when marathon-lb is in `poll` mode as there is no marathon-lb process to be signaled in this mode (marathon-lb exits after each poll).

## HAProxy Configuration

Expand Down Expand Up @@ -265,6 +268,7 @@ are [documented here](Longhelp.md#templates).
>
< HTTP/1.1 200 OK
```
* Some of the features of marathon-lb assume that it is the only instance of itself running in a PID namespace. i.e. marathon-lb assumes that it is running in a container. Certain features like the `/_mlb_signal` endpoints and the `/_haproxy_getpids` endpoint (and by extension, zero-downtime deployments) may behave unexpectedly if more than one instance of marathon-lb is running in the same PID namespace or if there are other HAProxy processes in the same PID namespace.

## Zero-downtime Deployments

Expand Down Expand Up @@ -352,4 +356,4 @@ PRs are welcome, but here are a few general guidelines:

```
bash /path/to/marathon-lb/scripts/install-git-hooks.sh
```
```
6 changes: 6 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def load(self):
lua-load /marathon-lb/getpids.lua
lua-load /marathon-lb/getconfig.lua
lua-load /marathon-lb/getmaps.lua
lua-load /marathon-lb/signalmlb.lua
defaults
load-server-state-from-file global
log global
Expand Down Expand Up @@ -91,6 +92,11 @@ def load(self):
http-request use-service lua.getappmap if getappmap
acl getconfig path /_haproxy_getconfig
http-request use-service lua.getconfig if getconfig
acl signalmlbhup path /_mlb_signal/hup
http-request use-service lua.signalmlbhup if signalmlbhup
acl signalmlbusr1 path /_mlb_signal/usr1
http-request use-service lua.signalmlbusr1 if signalmlbusr1
''',
overridable=False,
description='''\
Expand Down
Loading

0 comments on commit 54935d9

Please sign in to comment.