Skip to content

Commit d01a19d

Browse files
committed
Fixes
1 parent 0ccd342 commit d01a19d

File tree

4 files changed

+29
-32
lines changed

4 files changed

+29
-32
lines changed

examples/config.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ nginx-certbot:
66
# Certificate renewal interval. Falls back to the RENEWAL_INTERVAL environment variable
77
# or, if that is unset, to '8d'.
88
renewal-interval: 8d
9-
# Boolean to enable nginx debug mode and more verbose logging output. Falls back to the
10-
# DEBUG environment variable or, if that is unset, to 'false'.
11-
debug: false
129

1310
# Certbot parameters.
1411
certbot:

src/scripts/create_dhparams.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ set -e
1111
# The created file should be stored somewhere under /etc/letsencrypt/dhparams/
1212
# to ensure persistence between restarts.
1313
create_dhparam() {
14+
# Read dhparam-size from config file, falling back to DHPARAM_SIZE environment variable.
15+
local CONFIG_FILE="${NGINX_CERTBOT_CONFIG_FILE:-/etc/nginx-certbot/config.yml}"
16+
if [ -f "${CONFIG_FILE}" ]; then
17+
YAML_DHPARAM_SIZE=$(shyaml get-value nginx-certbot.dhparam-size '' < "${CONFIG_FILE}")
18+
if [ -n "${YAML_DHPARAM_SIZE}" ]; then
19+
DHPARAM_SIZE=${YAML_DHPARAM_SIZE}
20+
debug "Using nginx-certbot.dhparam-size=${DHPARAM_SIZE} from config file."
21+
fi
22+
fi
1423
if [ -z "${DHPARAM_SIZE}" ]; then
1524
debug "DHPARAM_SIZE unset, using default of 2048 bits"
1625
DHPARAM_SIZE=2048

src/scripts/run_certbot.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ info "Starting certificate renewal process"
88

99
# If we have a config file we parse it and let definitions within take
1010
# precedence over any environment variables.
11+
CONFIG_FILE="${NGINX_CERTBOT_CONFIG_FILE:-/etc/nginx-certbot/config.yml}"
1112
if [ -f "${CONFIG_FILE}" ]; then
1213
certbot_authenticator="$(shyaml get-value certbot.authenticator '' < "${CONFIG_FILE}")"
1314
certbot_elliptic_curve="$(shyaml get-value certbot.elliptic-curve '' < "${CONFIG_FILE}")"

src/scripts/start_nginx_certbot.sh

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,18 @@ trap "clean_exit" EXIT
2121
# Source "util.sh" so we can have our nice tools.
2222
. "$(cd "$(dirname "$0")"; pwd)/util.sh"
2323

24-
# Configuration file
25-
if [ -n "${NGINX_CERTBOT_CONFIG_FILE}" ] && [ ! -f "${NGINX_CERTBOT_CONFIG_FILE}" ]; then
26-
# If the variable is set but the file doesn't exist we error out since this
27-
# is most likely a user error.
28-
error "NGINX_CERTBOT_CONFIG_FILE is configured but '${NGINX_CERTBOT_CONFIG_FILE}' does not exist, exiting"
29-
exit 1
30-
fi
31-
export CONFIG_FILE="${NGINX_CERTBOT_CONFIG_FILE:-/etc/nginx-certbot/config.yml}"
32-
33-
# If the config file exist we extract configuration from it and override any corresponding environment variables:
34-
# - nginx-certbot.debug overrides DEBUG
35-
# - nginx-certbot.dhparam-size overrides DHPARAM_SIZE
36-
# - nginx-certbot.renewal-interval overrides RENEWAL_INTERVAL
37-
if [ -f "${CONFIG_FILE}" ]; then
38-
debug "Configuration file '${CONFIG_FILE}' exist."
39-
YAML_DEBUG=$(shyaml get-value nginx-certbot.debug '' < "${CONFIG_FILE}")
40-
if [ "${YAML_DEBUG}" == "True" ] || [ "${YAML_DEBUG}" == "1" ]; then
41-
export DEBUG=1
42-
elif [ "${YAML_DEBUG}" == "False" ] || [ "${YAML_DEBUG}" == "0" ]; then
43-
export DEBUG=0
44-
fi
45-
YAML_DHPARAM_SIZE=$(shyaml get-value nginx-certbot.dhparam-size '' < "${CONFIG_FILE}")
46-
if [ -n "${YAML_DHPARAM_SIZE}" ]; then
47-
export DHPARAM_SIZE=${YAML_DHPARAM_SIZE}
48-
fi
49-
YAML_RENEWAL_INTERVAL=$(shyaml get-value nginx-certbot.renewal-interval '' < "${CONFIG_FILE}")
50-
if [ -n "${YAML_RENEWAL_INTERVAL}" ]; then
51-
export RENEWAL_INTERVAL=${YAML_RENEWAL_INTERVAL}
24+
# Configuration file from NGINX_CERTBOT_CONFIG_FILE environment variable. We make some noise
25+
# here during startup if the variable is set to a file that doesn't exist since this is most
26+
# likely a user error.
27+
CONFIG_FILE="${NGINX_CERTBOT_CONFIG_FILE:-/etc/nginx-certbot/config.yml}"
28+
if [ ! -f "${CONFIG_FILE}" ]; then
29+
if [ -n "${NGINX_CERTBOT_CONFIG_FILE}" ]; then
30+
warning "NGINX_CERTBOT_CONFIG_FILE is configured but '${CONFIG_FILE}' does not exist."
31+
else
32+
debug "Configuration file '${CONFIG_FILE}' doesn't exist."
5233
fi
5334
else
54-
debug "Configuration file '${CONFIG_FILE}' doesn't exist. Falling back to environment variables and default values."
35+
debug "Configuration file '${CONFIG_FILE}' exist."
5536
fi
5637

5738
# If the environment variable `DEBUG=1` is set, then this message is printed.
@@ -76,6 +57,15 @@ fi
7657
debug "PID of the main Nginx process: ${NGINX_PID}"
7758

7859
# Make sure a renewal interval is set before continuing.
60+
# If we have a config file with 'nginx-certbot.renewal-interval' set we let that override
61+
# the RENEWAL_INTERVAL environment variable
62+
if [ -f "${CONFIG_FILE}" ]; then
63+
YAML_RENEWAL_INTERVAL=$(shyaml get-value nginx-certbot.renewal-interval '' < "${CONFIG_FILE}")
64+
if [ -n "${YAML_RENEWAL_INTERVAL}" ]; then
65+
RENEWAL_INTERVAL=${YAML_RENEWAL_INTERVAL}
66+
debug "Using nginx-certbot.renewal-interval=${RENEWAL_INTERVAL} from config file."
67+
fi
68+
fi
7969
if [ -z "${RENEWAL_INTERVAL}" ]; then
8070
debug "RENEWAL_INTERVAL unset, using default of '8d'"
8171
RENEWAL_INTERVAL='8d'

0 commit comments

Comments
 (0)