From ced845ffa65c72fcfd09744a4c48bfa4588023d8 Mon Sep 17 00:00:00 2001 From: vixns Date: Thu, 8 Sep 2016 20:31:10 +0200 Subject: [PATCH] Runsvdir (#283) * upstream merge * add http basic auth support * add haproxy acme plugin * fix some missing/extra labels * Revert "add haproxy acme plugin" This reverts commit 15e7a254cf02ef0165893bd135dd996b0c577fd7. * upstream merge * add http basic auth support * add haproxy acme plugin * fix some missing/extra labels * Revert "add haproxy acme plugin" This reverts commit 15e7a254cf02ef0165893bd135dd996b0c577fd7. * Use runsvdir to launch marathon_lb.py and haproxy. * change to /marathon-lb dir before running, templates dir is relative to current dir. --- README.md | 2 +- run | 48 ++++++++++++++++++++++++++++++------------------ 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index b4907559..1b1faa9b 100644 --- a/README.md +++ b/README.md @@ -346,4 +346,4 @@ PRs are welcome, but here are a few general guidelines: - Use the pre-commit hook to automatically generate docs: ``` bash /path/to/marathon-lb/scripts/install-git-hooks.sh - ``` + ``` \ No newline at end of file diff --git a/run b/run index 8ef293e6..d2734849 100755 --- a/run +++ b/run @@ -3,6 +3,9 @@ set -euo pipefail SYSLOG_SOCKET=${SYSLOG_SOCKET:-/dev/null} +LB_SERVICE="/marathon-lb/service/lb" +mkdir -p $LB_SERVICE + HAPROXY_SERVICE="/marathon-lb/service/haproxy" mkdir -p $HAPROXY_SERVICE/env @@ -70,12 +73,6 @@ if [ -n "${HAPROXY_SYSCTL_PARAMS-}" ]; then fi fi -/usr/bin/runsv "$HAPROXY_SERVICE" & -RUNSV=$! -ARGS="" - -trap "kill $RUNSV; wait $RUNSV; exit 0" TERM INT - MODE=$1; shift case "$MODE" in poll) @@ -99,17 +96,32 @@ case "$MODE" in ;; esac -while true; do - /marathon-lb/marathon_lb.py \ +cat > $LB_SERVICE/run << EOF +#!/bin/sh +exec 2>&1 +cd /marathon-lb +exec /marathon-lb/marathon_lb.py \ --syslog-socket $SYSLOG_SOCKET \ --haproxy-config /marathon-lb/haproxy.cfg \ - --ssl-certs "$SSL_CERTS" \ - --command "sv reload $HAPROXY_SERVICE" \ - $ARGS "$@" & - wait $! || exit $? # Needed for the traps to work - if [ "$MODE" != "poll" ]; then - exit 0 - fi - sleep "$POLL_INTERVAL" & - wait $! -done + --ssl-certs "${SSL_CERTS}" \ + --command "sv reload ${HAPROXY_SERVICE}" \ + $ARGS ${@} + +EOF +chmod 755 $LB_SERVICE/run + + +if [ "${MODE}" == "poll" ]; then + +cat > $LB_SERVICE/finish << EOF +#!/bin/sh +sleep ${POLL_INTERVAL} + +EOF +chmod 755 $LB_SERVICE/finish + +fi + +runsvdir -P /marathon-lb/service & +trap "kill -s 1 $!" TERM INT +wait