Setting better log
This commit is contained in:
parent
defa564601
commit
e63f41def1
5 changed files with 27 additions and 10 deletions
|
|
@ -1,12 +1,14 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
source /scripts/functions.sh
|
||||||
|
|
||||||
if [ ! -f /scripts/letsencrypt_hosts.txt ]; then
|
if [ ! -f /scripts/letsencrypt_hosts.txt ]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Semaphore
|
# Semaphore
|
||||||
if [ -f /tmp/certbot-lock ]; then
|
if [ -f /tmp/certbot-lock ]; then
|
||||||
echo "[CERTBOT_JOB] $(date +"$EASYHAPROXY_DATEFORMAT") Another process is running"
|
log "notice" "CERTBOT_JOB" "Another process is running"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -30,7 +32,7 @@ for domain in $(cat /scripts/letsencrypt_hosts.txt); do
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -n "$REQUEST_CERTS" ]; then
|
if [ -n "$REQUEST_CERTS" ]; then
|
||||||
echo "[CERTBOT_JOB] $(date +"$EASYHAPROXY_DATEFORMAT") Requesting certificates for $REQUEST_CERTS"
|
log "info" "CERTBOT_JOB" "Requesting certificates for $REQUEST_CERTS"
|
||||||
certbot certonly \
|
certbot certonly \
|
||||||
--standalone \
|
--standalone \
|
||||||
--preferred-challenges http \
|
--preferred-challenges http \
|
||||||
|
|
@ -45,7 +47,7 @@ if [ -n "$REQUEST_CERTS" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$RENEW_CERTS" ]; then
|
if [ -n "$RENEW_CERTS" ]; then
|
||||||
echo "[CERTBOT_JOB] $(date +"$EASYHAPROXY_DATEFORMAT") Resquesting renew certificated fort $RENEW_CERTS"
|
log "info" "CERTBOT_JOB" "Resquesting renew certificated fort $RENEW_CERTS"
|
||||||
certbot renew --post-hook "/scripts/certbot_to_haproxy.sh"
|
certbot renew --post-hook "/scripts/certbot_to_haproxy.sh"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
source /scripts/functions.sh
|
||||||
|
|
||||||
# Loop through all Let's Encrypt certificates
|
# Loop through all Let's Encrypt certificates
|
||||||
for CERTIFICATE in `find /etc/letsencrypt/live/* -type d`; do
|
for CERTIFICATE in `find /etc/letsencrypt/live/* -type d`; do
|
||||||
CERTIFICATE=`basename $CERTIFICATE`
|
CERTIFICATE=`basename $CERTIFICATE`
|
||||||
|
|
|
||||||
9
assets/scripts/functions.sh
Normal file
9
assets/scripts/functions.sh
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
function log() {
|
||||||
|
# ARGS:
|
||||||
|
# - loglevel
|
||||||
|
# - app
|
||||||
|
# - message
|
||||||
|
echo [$2] $(date +"$EASYHAPROXY_DATEFORMAT") [$1]: $3
|
||||||
|
}
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
source /scripts/functions.sh
|
||||||
|
|
||||||
cd /scripts
|
cd /scripts
|
||||||
|
|
||||||
RELOAD="true"
|
RELOAD="true"
|
||||||
|
|
||||||
if [[ "static|docker|swarm" != *"$EASYHAPROXY_DISCOVER"* ]];then
|
if [[ "static|docker|swarm" != *"$EASYHAPROXY_DISCOVER"* ]];then
|
||||||
echo "[CONF_CHECK] $(date +"$EASYHAPROXY_DATEFORMAT") ERROR: EASYHAPROXY_DISCOVER should be 'static', 'docker', or 'swarm'. I got '$EASYHAPROXY_DISCOVER' instead."
|
log "info" "CONF_CHECK" "ERROR: EASYHAPROXY_DISCOVER should be 'static', 'docker', or 'swarm'. I got '$EASYHAPROXY_DISCOVER' instead."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -40,7 +42,7 @@ else
|
||||||
RELOAD="false"
|
RELOAD="false"
|
||||||
else
|
else
|
||||||
python3 swarm.py > /etc/haproxy/haproxy.cfg
|
python3 swarm.py > /etc/haproxy/haproxy.cfg
|
||||||
echo "[CONF_CHECK] $(date +"$EASYHAPROXY_DATEFORMAT") New configuration found"
|
log "info" "CONF_CHECK" "New configuration found"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -49,23 +51,23 @@ if cmp -s ${CONTROL_FILE} ${CONTROL_FILE}.old ; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -z "$1" ]]; then
|
if [[ ! -z "$1" ]]; then
|
||||||
echo "[CONF_CHECK] $(date +"$EASYHAPROXY_DATEFORMAT") Initial configuration. Skip certbot."
|
log "info" "CONF_CHECK" "Initial configuration. Skip certbot."
|
||||||
else
|
else
|
||||||
/scripts/certbot.sh
|
/scripts/certbot.sh
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If Certbot reloads successfully will create the file /tmp/force-reload
|
# If Certbot reloads successfully will create the file /tmp/force-reload
|
||||||
if [ -f /tmp/force-reload ]; then
|
if [ -f /tmp/force-reload ]; then
|
||||||
echo "[CONF_CHECK] $(date +"$EASYHAPROXY_DATEFORMAT") New certificates found..."
|
log "info" "CONF_CHECK" "New certificates found..."
|
||||||
RELOAD="true"
|
RELOAD="true"
|
||||||
rm /tmp/force-reload
|
rm /tmp/force-reload
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -z "$1" ]]; then
|
if [[ ! -z "$1" ]]; then
|
||||||
echo "[CONF_CHECK] $(date +"$EASYHAPROXY_DATEFORMAT") Starting haproxy..."
|
log "info" "CONF_CHECK" "Starting haproxy..."
|
||||||
/usr/sbin/haproxy -W -f /etc/haproxy/haproxy.cfg $(ls /etc/haproxy/conf.d/*.cfg 2>/dev/null | xargs -I{} echo -f {}) -p /run/haproxy.pid -S /var/run/haproxy.sock &
|
/usr/sbin/haproxy -W -f /etc/haproxy/haproxy.cfg $(ls /etc/haproxy/conf.d/*.cfg 2>/dev/null | xargs -I{} echo -f {}) -p /run/haproxy.pid -S /var/run/haproxy.sock &
|
||||||
|
|
||||||
elif [[ "$RELOAD" == "true" ]]; then
|
elif [[ "$RELOAD" == "true" ]]; then
|
||||||
echo "[CONF_CHECK] $(date +"$EASYHAPROXY_DATEFORMAT") Reloading..."
|
log "info" "CONF_CHECK" "Reloading..."
|
||||||
/usr/sbin/haproxy -W -f /etc/haproxy/haproxy.cfg $(ls /etc/haproxy/conf.d/*.cfg 2>/dev/null | xargs -I{} echo -f {}) -p /run/haproxy.pid -x /var/run/haproxy.sock -sf $(cat /run/haproxy.pid) &
|
/usr/sbin/haproxy -W -f /etc/haproxy/haproxy.cfg $(ls /etc/haproxy/conf.d/*.cfg 2>/dev/null | xargs -I{} echo -f {}) -p /run/haproxy.pid -x /var/run/haproxy.sock -sf $(cat /run/haproxy.pid) &
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
source /scripts/functions.sh
|
||||||
|
|
||||||
/usr/sbin/haproxy -v
|
/usr/sbin/haproxy -v
|
||||||
|
|
||||||
if [ -z "$EASYHAPROXY_DATEFORMAT" ]; then
|
if [ -z "$EASYHAPROXY_DATEFORMAT" ]; then
|
||||||
|
|
@ -22,6 +24,6 @@ echo
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
sleep $EASYHAPROXY_REFRESH_CONF
|
sleep $EASYHAPROXY_REFRESH_CONF
|
||||||
echo "[CONF_CHECK] $(date +"$EASYHAPROXY_DATEFORMAT") - Heartbeat."
|
log "info" "CONF_CHECK" "Heartbeat."
|
||||||
/scripts/haproxy-reload.sh
|
/scripts/haproxy-reload.sh
|
||||||
done
|
done
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue