Skip to content

Commit 06ebe43

Browse files
[fix] Handle missing VPN_DOMAIN safely in OpenVPN startup #572
Avoid container failure when VPN_DOMAIN is unset by logging a warning and exiting gracefully. Fixes #572
1 parent dffee77 commit 06ebe43

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

images/common/init_command.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22
# OpenWISP common module init script
33
set -e
44
source utils.sh
@@ -29,7 +29,10 @@ elif [ "$MODULE_NAME" = 'freeradius' ]; then
2929
source docker-entrypoint.sh -X
3030
fi
3131
elif [ "$MODULE_NAME" = 'openvpn' ]; then
32-
if [ -z "$VPN_DOMAIN" ]; then echo "VPN_DOMAIN is required" >if [ -z "$VPN_DOMAIN" ]; then echo "VPN_DOMAIN is required" >if [ -z "$VPN_DOMAIN" ]; then exit; fi2; exit 1; fi2; exit 1; fi
32+
if [ -z "$VPN_DOMAIN" ]; then
33+
echo "WARNING: VPN_DOMAIN not set, skipping OpenVPN setup" >&2
34+
exit 0
35+
fi
3336
wait_nginx_services
3437
openvpn_preconfig
3538
openvpn_config
@@ -43,7 +46,7 @@ elif [ "$MODULE_NAME" = 'openvpn' ]; then
4346
crond
4447
# Schedule send topology script only when
4548
# network topology module is enabled.
46-
if [ "$USE_OPENWISP_TOPOLOGY" = "True" ]; then
49+
if [ "$USE_OPENWISP_TOPOLOGY" == "True" ]; then
4750
init_send_network_topology
4851
fi
4952
# Supervisor is used to start the service because OpenVPN
@@ -66,7 +69,7 @@ elif [ "$MODULE_NAME" = 'nginx' ]; then
6669
# sentinel from the generated nginx.conf.
6770
export NGINX_WORKER_RLIMIT_NOFILE="${NGINX_WORKER_RLIMIT_NOFILE:-__UNSET__}"
6871
envsubst </etc/nginx/nginx.template.conf >/etc/nginx/nginx.conf
69-
# Remove incomplete worker_rlimit_nofile directives if env var is unset or empty
72+
# Remove incomplete worker_rlimit_nofile directives if env var is unset or empty
7073
sed -i '/__UNSET__/d; /^worker_rlimit_nofile *$/d; /^[[:space:]]*$/d' /etc/nginx/nginx.conf
7174
envsubst_create_config /etc/nginx/openwisp.internal.template.conf internal INTERNAL
7275
if [ "$SSL_CERT_MODE" = 'Yes' ]; then
@@ -93,7 +96,7 @@ elif [ "$MODULE_NAME" = 'celery' ]; then
9396
${OPENWISP_CELERY_NETWORK_COMMAND_FLAGS}
9497
fi
9598

96-
if [ "$USE_OPENWISP_FIRMWARE" = "True" ] && [ "$USE_OPENWISP_CELERY_FIRMWARE" = "True" ]; then
99+
if [[ "$USE_OPENWISP_FIRMWARE" == "True" && "$USE_OPENWISP_CELERY_FIRMWARE" == "True" ]]; then
97100
echo "Starting the 'firmware_upgrader' celery worker"
98101
celery -A openwisp worker -l ${DJANGO_LOG_LEVEL} --queues firmware_upgrader \
99102
-n firmware_upgrader@%h --logfile /opt/openwisp/logs/celery_firmware_upgrader.log \
@@ -104,7 +107,7 @@ elif [ "$MODULE_NAME" = 'celery' ]; then
104107
tail -f /opt/openwisp/logs/*
105108
elif [ "$MODULE_NAME" = 'celery_monitoring' ]; then
106109
python services.py database redis dashboard
107-
if [ "$USE_OPENWISP_MONITORING" = "True" ] && [ "$USE_OPENWISP_CELERY_MONITORING" = "True" ]; then
110+
if [[ "$USE_OPENWISP_MONITORING" == "True" && "$USE_OPENWISP_CELERY_MONITORING" == 'True' ]]; then
108111
echo "Starting the 'monitoring' celery worker"
109112
celery -A openwisp worker -l ${DJANGO_LOG_LEVEL} --queues monitoring \
110113
-n monitoring@%h --logfile /opt/openwisp/logs/celery_monitoring.log \

0 commit comments

Comments
 (0)