From 74e66173fb30eead39d43bf34349116150110f3f Mon Sep 17 00:00:00 2001 From: jonas Date: Wed, 11 Jan 2023 20:01:32 +0100 Subject: [PATCH] Add timestamp to log messages for easier tracking of time --- src/scripts/start_nginx_certbot.sh | 7 ++++++- src/scripts/util.sh | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/scripts/start_nginx_certbot.sh b/src/scripts/start_nginx_certbot.sh index 9d3af4a..dffe087 100644 --- a/src/scripts/start_nginx_certbot.sh +++ b/src/scripts/start_nginx_certbot.sh @@ -40,8 +40,8 @@ else nginx -g "daemon off;" & NGINX_PID=$! fi +debug "PID of the main Nginx process: ${NGINX_PID}" -info "Starting the autorenewal service" # Make sure a renewal interval is set before continuing. if [ -z "${RENEWAL_INTERVAL}" ]; then debug "RENEWAL_INTERVAL unset, using default of '8d'" @@ -53,6 +53,8 @@ fi ( set -e while true; do + info "Running the autorenewal service" + # Create symlinks from conf.d/ to user_conf.d/ if necessary. symlink_user_configs @@ -76,6 +78,7 @@ while true; do done ) & CERTBOT_LOOP_PID=$! +debug "PID of the autorenewal loop: ${CERTBOT_LOOP_PID}" # A helper function to prematurely terminate the sleep process, inside the # autorenewal loop process, in order to immediately restart the loop again @@ -104,4 +107,6 @@ while [ -z "${exit_code}" ] || [ "${exit_code}" = "129" ]; do wait -n ${NGINX_PID} ${CERTBOT_LOOP_PID} exit_code=$? done + +debug "Exiting with code ${exit_code}" exit "${exit_code}" diff --git a/src/scripts/util.sh b/src/scripts/util.sh index edfa4bf..53f4ff0 100644 --- a/src/scripts/util.sh +++ b/src/scripts/util.sh @@ -1,12 +1,22 @@ #!/bin/bash +: ${DATE_FORMAT_STRING:="+%Y/%m/%d %T"} + +# Helper function used to output messages in a uniform manner. +# +# $1: The log level to print. +# $2: The message to be printed. +log() { + echo "$(date "${DATE_FORMAT_STRING}") [${1}] ${2}" +} + # Helper function to output debug messages to STDOUT if the `DEBUG` environment # variable is set to 1. # # $1: String to be printed. debug() { if [ 1 = "${DEBUG}" ]; then - echo "${1}" + log "debug" "${1}" fi } @@ -14,7 +24,7 @@ debug() { # # $1: String to be printed. info() { - echo "${1}" + log "info" "${1}" } # Helper function to output warning messages to STDOUT, with bold yellow text. @@ -23,7 +33,7 @@ info() { warning() { (set +x; tput -Tscreen bold tput -Tscreen setaf 3 - echo "${1}" + log "warning" "${1}" tput -Tscreen sgr0) } @@ -33,7 +43,7 @@ warning() { error() { (set +x; tput -Tscreen bold tput -Tscreen setaf 1 - echo "${1}" + log "error" "${1}" tput -Tscreen sgr0) >&2 }