Skip to content

Commit cbb3a13

Browse files
pandafynemesifier
authored andcommitted
[fix] Made OpenVPN container optional #490
Fixes #490 (cherry picked from commit 94908a3)
1 parent 584da53 commit cbb3a13

5 files changed

Lines changed: 31 additions & 12 deletions

File tree

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ OPENWISP_CELERY_MONITORING_COMMAND_FLAGS=--concurrency=1
5858
OPENWISP_CELERY_MONITORING_CHECKS_COMMAND_FLAGS=--concurrency=1
5959
USE_OPENWISP_CELERY_FIRMWARE=True
6060
OPENWISP_CELERY_FIRMWARE_COMMAND_FLAGS=--concurrency=1
61+
CELERY_SERVICE_NETWORK_MODE=service:openvpn
6162
# Metric collection
6263
METRIC_COLLECTION=True
6364
# collectstatic

deploy/auto-install.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ setup_docker_openwisp() {
148148
# VPN domain
149149
if [[ -z "$vpn_domain" ]]; then
150150
set_env "VPN_DOMAIN" "openvpn.${domain}"
151+
set_env CELERY_SERVICE_NETWORK_MODE "service:openvpn"
151152
elif [[ "${vpn_domain,,}" == "n" ]]; then
152-
set_env "VPN_DOMAIN" "example.com"
153+
set_env "VPN_DOMAIN" ""
154+
set_env CELERY_SERVICE_NETWORK_MODE ""
153155
else
154156
set_env "VPN_DOMAIN" "$vpn_domain"
155157
fi

docker-compose.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ x-celery-depends-on: &celery-depends-on
77
dashboard:
88
condition: service_started
99
openvpn:
10+
required: false
1011
condition: service_healthy
1112

1213
services:
@@ -81,7 +82,7 @@ services:
8182
env_file:
8283
- .env
8384
<<: *celery-depends-on
84-
network_mode: "service:openvpn"
85+
network_mode: "${CELERY_SERVICE_NETWORK_MODE-service:openvpn}"
8586

8687
celery_monitoring:
8788
image: openwisp/openwisp-dashboard:latest
@@ -95,7 +96,7 @@ services:
9596
env_file:
9697
- .env
9798
<<: *celery-depends-on
98-
network_mode: "service:openvpn"
99+
network_mode: "${CELERY_SERVICE_NETWORK_MODE-service:openvpn}"
99100

100101
celerybeat:
101102
image: openwisp/openwisp-dashboard:latest
@@ -167,7 +168,7 @@ services:
167168

168169
openvpn:
169170
image: openwisp/openwisp-openvpn:latest
170-
restart: always
171+
restart: on-failure
171172
build:
172173
context: images
173174
dockerfile: openwisp_openvpn/Dockerfile

docs/user/settings.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,19 @@ framework.
399399
- **Valid Values:** STRING.
400400
- **Default:** ``--concurrency=1``.
401401

402+
``CELERY_SERVICE_NETWORK_MODE``
403+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
404+
405+
- **Explanation:** Controls the Docker network mode for `celery` and
406+
`celery_monitoring` workers. Default ``service:openvpn`` shares the
407+
OpenVPN container's network namespace so workers can reach VPN-connected
408+
devices. Set to an empty string ``""`` to use the default bridge network
409+
when you need direct LAN access to devices (the auto-install script sets
410+
this to ``""`` if OpenVPN is disabled).
411+
- **Valid Values:** Docker network mode (e.g. ``service:<name>``,
412+
``host``) or empty string (``""``).
413+
- **Default:** ``service:openvpn``
414+
402415
``OPENWISP_CUSTOM_OPENWRT_IMAGES``
403416
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
404417

images/openwisp_dashboard/load_init_data.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,18 +241,20 @@ def create_default_topology(vpn):
241241
create_admin()
242242
# Steps for creating new vpn client template with all the
243243
# required objects (CA, Certificate, VPN Server).
244-
default_ca = create_default_ca()
245-
default_cert = create_default_cert(default_ca)
246-
default_vpn = create_default_vpn(
247-
default_ca,
248-
default_cert,
249-
)
250-
create_default_vpn_template(default_vpn)
244+
is_vpn_enabled = os.environ.get("VPN_DOMAIN", "") != ""
245+
if is_vpn_enabled:
246+
default_ca = create_default_ca()
247+
default_cert = create_default_cert(default_ca)
248+
default_vpn = create_default_vpn(
249+
default_ca,
250+
default_cert,
251+
)
252+
create_default_vpn_template(default_vpn)
251253

252254
create_default_credentials()
253255
create_ssh_key_template()
254256

255-
if env_bool(os.environ.get("USE_OPENWISP_TOPOLOGY")):
257+
if is_vpn_enabled and env_bool(os.environ.get("USE_OPENWISP_TOPOLOGY")):
256258
Topology = load_model("topology", "Topology")
257259
create_default_topology(default_vpn)
258260

0 commit comments

Comments
 (0)