From e9e999542d62ef30f417f84254264051060068a6 Mon Sep 17 00:00:00 2001
From: Daniel Watrous <dwmaillist@gmail.com>
Date: Fri, 4 May 2018 10:14:31 -0500
Subject: [PATCH] add reload

---
 deploy/haproxy.sh | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/deploy/haproxy.sh b/deploy/haproxy.sh
index 77f9c94f..0b89b7ae 100644
--- a/deploy/haproxy.sh
+++ b/deploy/haproxy.sh
@@ -20,9 +20,18 @@ haproxy_deploy() {
   _debug _cca "$_cca"
   _debug _cfullchain "$_cfullchain"
 
-  # combine the key and fullchain into a single pem and install
+  # handle reload preference
+  DEFAULT_HAPROXY_RELOAD="/usr/sbin/service haproxy restart"
+  if [[ -z "${DEPLOY_HAPROXY_RELOAD}" ]]; then
+    _reload="${DEFAULT_HAPROXY_RELOAD}"
+    _cleardomainconf DEPLOY_HAPROXY_RELOAD
+  else
+    _reload="${DEPLOY_HAPROXY_RELOAD}"
+    _savedomainconf DEPLOY_HAPROXY_RELOAD "$DEPLOY_HAPROXY_RELOAD"
+  fi
   _savedomainconf DEPLOY_HAPROXY_PEM_PATH "$DEPLOY_HAPROXY_PEM_PATH"
 
+  # work out the path where the PEM file should go
   _pem_path="${DEPLOY_HAPROXY_PEM_PATH}"
   if [ -z "$_pem_path" ]; then
     _err "Path to save PEM file not found. Please define DEPLOY_HAPROXY_PEM_PATH."
@@ -31,10 +40,19 @@ haproxy_deploy() {
   _pem_full_path="$_pem_path/$_cdomain.pem"
   _info "Full path to PEM $_pem_full_path"
 
+  # combine the key and fullchain into a single pem and install
   cat "$_cfullchain" "$_ckey" >"$_pem_full_path"
   chmod 600 "$_pem_full_path"
-
   _info "Certificate successfully deployed"
-  return 0
+
+  # restart HAProxy
+  _info "Run reload: $_reload"
+  if eval "$_reload"; then
+    _info "Reload success!"
+    return 0
+  else
+    _err "Reload error"
+    return 1
+  fi
 
 }