aboutsummaryrefslogtreecommitdiff
path: root/docker/haproxy/haproxy-ssh
diff options
context:
space:
mode:
authorMichal Arbet <michal.arbet@ultimum.io>2023-11-01 03:32:44 +0100
committerMichal Arbet <michal.arbet@ultimum.io>2023-11-07 18:20:35 +0100
commit7fe6696c203f7f4fd0f3ef5e50ba0d42f53569da (patch)
treedbb7ed84c9ae610d02b5000617952cfa2c981544 /docker/haproxy/haproxy-ssh
parentbeed4b68e83537bfe85cdb2983d1fe4ffcd5cc75 (diff)
downloadkolla-7fe6696c203f7f4fd0f3ef5e50ba0d42f53569da.tar.gz
kolla-7fe6696c203f7f4fd0f3ef5e50ba0d42f53569da.zip
Fix letsencrypt-lego logging
This patch fixes formatting of letsencrypt, so it will be easier to parse via fluent. Change-Id: I8a403e14819df4351e28d53c676571a3ad0c14be
Diffstat (limited to 'docker/haproxy/haproxy-ssh')
-rwxr-xr-xdocker/haproxy/haproxy-ssh/update-haproxy-cert.sh26
1 files changed, 19 insertions, 7 deletions
diff --git a/docker/haproxy/haproxy-ssh/update-haproxy-cert.sh b/docker/haproxy/haproxy-ssh/update-haproxy-cert.sh
index 61a5d0806..fe7d8e9fa 100755
--- a/docker/haproxy/haproxy-ssh/update-haproxy-cert.sh
+++ b/docker/haproxy/haproxy-ssh/update-haproxy-cert.sh
@@ -1,5 +1,17 @@
#!/bin/bash
+function log_info {
+ local message="${1}"
+
+ echo "$(date '+%Y/%m/%d %H:%M:%S') [INFO] ${message}"
+}
+
+function log_error {
+ local message="${1}"
+
+ echo "$(date '+%Y/%m/%d %H:%M:%S') [ERROR] ${message}"
+}
+
function haproxy_transaction_start {
local cert_input=${1}
local cert_dest=${2}
@@ -10,9 +22,9 @@ function haproxy_transaction_start {
transaction_grep_check="Transaction (created|updated) for certificate $(echo $cert_dest | sed -e 's|/|\\/|g')!"
transaction_result=$(echo -e "set ssl cert ${cert_dest} <<\n$(cat ${cert_input})\n" | socat unix-connect:/var/lib/kolla/haproxy/haproxy.sock -)
if echo "${transaction_result}" | grep -Pq "${transaction_grep_check}"; then
- echo "$(date +%Y/%m-%d) $(date +%H:%M:%S) [INFO] [${cert_dest} - update] Transaction ${cert_input} -> ${cert_dest} started."
+ log_info "[${cert_dest} - update] Transaction ${cert_input} -> ${cert_dest} started."
else
- echo "$(date +%Y/%m-%d) $(date +%H:%M:%S) [ERROR] [${cert_dest} - update] Transaction ${cert_input} -> ${cert_dest} failed."
+ log_error "[${cert_dest} - update] Transaction ${cert_input} -> ${cert_dest} failed, please check if haproxy admin socket is running and ${cert_input} is not corrupted."
exit 1
fi
@@ -22,9 +34,9 @@ function haproxy_transaction_start {
cert_input_sha1=$(openssl x509 -noout -fingerprint -sha1 -inform pem -in ${cert_input} | awk -F '=' '{print $2}' | sed -e 's/://g')
cert_dest_sha1=$(echo "show ssl cert *${cert_dest}" | socat unix-connect:/var/lib/kolla/haproxy/haproxy.sock - | awk -F 'SHA1 FingerPrint: ' '{print $2}' | sed '/^$/d')
if [ "${cert_input_sha1}" = "${cert_dest_sha1}" ]; then
- echo "$(date +%Y/%m-%d) $(date +%H:%M:%S) [INFO] [${cert_dest} - update] Transaction ${cert_input} -> ${cert_dest} successfull."
+ log_info "[${cert_dest} - update] Transaction ${cert_input} -> ${cert_dest} successfull."
else
- echo "$(date +%Y/%m-%d) $(date +%H:%M:%S) [ERROR] [${cert_dest} - update] Transaction ${cert_input} -> ${cert_dest} failed."
+ log_error "[${cert_dest} - update] Transaction ${cert_input} -> ${cert_dest} failed, SHA1 fingerprint of ${cert_input} is not the same as uploaded one."
exit 1
fi
}
@@ -37,9 +49,9 @@ function haproxy_upload_to_memory {
cert_upload_output=$(echo "commit ssl cert ${cert_dest}" | socat unix-connect:/var/lib/kolla/haproxy/haproxy.sock -)
if echo "${cert_upload_output}" | grep -q "Success!"; then
- echo "$(date +%Y/%m-%d) $(date +%H:%M:%S) [INFO] [${cert_dest} - update] Certificate ${cert_input} uploaded to haproxy memory."
+ log_info "[${cert_dest} - update] Certificate ${cert_input} uploaded to haproxy memory."
else
- echo "$(date +%Y/%m-%d) $(date +%H:%M:%S) [ERROR] [${cert_dest} - update] Certificate ${cert_input} upload to haproxy memory failed."
+ log_error "[${cert_dest} - update] Certificate ${cert_input} upload to haproxy memory failed, please check if haproxy admin socket is running and ${cert_input} is not corrupted."
exit 1
fi
}
@@ -56,7 +68,7 @@ function haproxy_write_to_disk {
cert_backup_path=$(echo "${cert_input}" | awk -v suffix="$cert_backup_suffix" -F '.pem' '{print $1suffix}')
cert_backup_name=$(echo ${cert_backup_path} | awk -F '/' '{print $NF}')
mkdir -p /etc/letsencrypt/backups
- echo "$(date +%Y/%m-%d) $(date +%H:%M:%S) [INFO] [${cert_haproxy_path} - update] Backuping currently loaded ${cert_haproxy_path} -> /etc/letsencrypt/backups/${cert_backup_name}"
+ log_info "[${cert_haproxy_path} - update] Backuping currently loaded ${cert_haproxy_path} -> /etc/letsencrypt/backups/${cert_backup_name}"
cp -a ${cert_haproxy_path} /etc/letsencrypt/backups/${cert_backup_name}
cp -a ${cert_input} ${cert_haproxy_path}
rm -f ${cert_input}