Skip to content

Commit

Permalink
Optionally send SIGTERM after reload.
Browse files Browse the repository at this point in the history
This is to address issues #5, #71, #267, #276, and #318.
  • Loading branch information
brndnmtthws committed Sep 26, 2016
1 parent d6f2aed commit e273faf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ are [documented here](Longhelp.md#templates).
* Avoid using the `HAPROXY_{n}_PORT` label; prefer defining service ports.
* Consider running multiple marathon-lb instances. In practice, 2 or more should be used to provide high availability. Note: **do not** run marathon-lb on every node in your cluster. This is considered an anti-pattern due to the implications of hammering the Marathon API and excess health checking.
* Consider using a dedicated load balancer in front of marathon-lb to permit upgrades/changes. Common choices include an ELB (on AWS) or a hardware load balancer for on-premise installations.
* You may want to set the `HAPROXY_RELOAD_SIGTERM_DELAY` environment variable to a value such as `5m`. This value is passed directly to the `sleep` command, which is executed after every HAProxy reload before sending a SIGTERM to the old HAProxy PIDs (see [service/haproxy/run](service/haproxy/run)). For cases where you expect long-lived TCP connections, you may _not_ want to terminate HAProxy before all connections finish. See [this discussion](http://www.serverphorums.com/read.php?10,862139) for more on HAProxy reloads, and issues [#5](https://github.com/mesosphere/marathon-lb/issues/5), [#71](https://github.com/mesosphere/marathon-lb/issues/71), [#267](https://github.com/mesosphere/marathon-lb/issues/267), [#276](https://github.com/mesosphere/marathon-lb/issues/276), and [#318](https://github.com/mesosphere/marathon-lb/issues/318) for more.
* Use separate marathon-lb groups (specified with `--group`) for internal and external load balancing. On DC/OS, the default group is `external`. A simple `options.json` for an internal load balancer would be:

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

```
bash /path/to/marathon-lb/scripts/install-git-hooks.sh
```
```
5 changes: 5 additions & 0 deletions run
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ else
exit 1
fi

if [ -n "${HAPROXY_RELOAD_SIGTERM_DELAY-}" ]; then
echo $HAPROXY_RELOAD_SIGTERM_DELAY > $HAPROXY_SERVICE/env/HAPROXY_RELOAD_SIGTERM_DELAY
fi


# Find the --ssl-certs arg if one was provided,
# get the certs and remove them and the arg from the list
# of positional parameters so we don't duplicate them
Expand Down
6 changes: 5 additions & 1 deletion service/haproxy/run
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ reload() {
socat /var/run/haproxy/socket - <<< "show servers state" > /var/state/haproxy/global

# Trigger reload
haproxy -p $PIDFILE -f /marathon-lb/haproxy.cfg -D -sf $(pidof haproxy)
HAPROXY_PIDS=$(pidof haproxy)
haproxy -p $PIDFILE -f /marathon-lb/haproxy.cfg -D -sf $HAPROXY_PIDS
if [ -n "${HAPROXY_RELOAD_SIGTERM_DELAY-}" ]; then
sleep $HAPROXY_RELOAD_SIGTERM_DELAY && kill $HAPROXY_PIDS 2> /dev/null &
fi

# Remove the firewall rules
removeFirewallRules
Expand Down

0 comments on commit e273faf

Please sign in to comment.