Skip to content

Commit

Permalink
Add timestamp to log messages for easier tracking of time
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasAlfredsson committed Jan 12, 2023
1 parent 47807ef commit 74e6617
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/scripts/start_nginx_certbot.sh
Expand Up @@ -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'"
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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}"
18 changes: 14 additions & 4 deletions src/scripts/util.sh
@@ -1,20 +1,30 @@
#!/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
}

# Helper function to output informational messages to STDOUT.
#
# $1: String to be printed.
info() {
echo "${1}"
log "info" "${1}"
}

# Helper function to output warning messages to STDOUT, with bold yellow text.
Expand All @@ -23,7 +33,7 @@ info() {
warning() {
(set +x; tput -Tscreen bold
tput -Tscreen setaf 3
echo "${1}"
log "warning" "${1}"
tput -Tscreen sgr0)
}

Expand All @@ -33,7 +43,7 @@ warning() {
error() {
(set +x; tput -Tscreen bold
tput -Tscreen setaf 1
echo "${1}"
log "error" "${1}"
tput -Tscreen sgr0) >&2
}

Expand Down

0 comments on commit 74e6617

Please sign in to comment.