fix: a failing user directory or token database no longer leaves the tunnels down.
Release / release (push) Failing after 15m34s
Release / release (push) Failing after 15m34s
This commit is contained in:
1 parent
caf0e334f0
commit
4f1aa282f6
2 files changed
+28
-13
No files matched your search
@@ -20,8 +20,6 @@ import sys
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
||||
|
||||
import ldap
|
||||
|
||||
import vpnrouter
|
||||
import vpnrouter_auth
|
||||
import vpnrouter_ldap
|
||||
@@ -349,22 +347,26 @@ def manage_wireguard(ctx, changed):
|
||||
|
||||
|
||||
def manage_directory():
|
||||
"""Provision the user directory in slapd, whether or not a P2S system is configured."""
|
||||
"""Provision the user directory in slapd, whether or not a P2S system is configured; the problem, or ''."""
|
||||
if vpnrouter_ldap.ensure_services() or not unit_is_active('slapd'):
|
||||
run(['systemctl', 'restart', 'slapd'])
|
||||
result = run(['systemctl', 'restart', 'slapd'], check=False)
|
||||
if result.returncode != 0:
|
||||
return f'slapd cannot be restarted: {result.stderr.strip()}'
|
||||
try:
|
||||
vpnrouter_ldap.provision()
|
||||
except ldap.LDAPError as exc:
|
||||
fail(f'the user directory cannot be provisioned: {exc}')
|
||||
except Exception as exc:
|
||||
return f'the user directory cannot be provisioned: {exc!r}'
|
||||
return ''
|
||||
|
||||
|
||||
def manage_tokens(cfg):
|
||||
"""Make the web service's signing key, and the database of its refresh tokens unless web.database names one."""
|
||||
vpnrouter_auth.ensure_key()
|
||||
"""Make the web service's signing key, and the database of its refresh tokens unless web.database names one; the problem, or ''."""
|
||||
try:
|
||||
vpnrouter_auth.ensure_key()
|
||||
vpnrouter_auth.provision(cfg)
|
||||
except OSError as exc:
|
||||
fail(f'the token database cannot be provisioned: {exc}')
|
||||
except Exception as exc:
|
||||
return f'the token database cannot be provisioned: {exc!r}'
|
||||
return ''
|
||||
|
||||
|
||||
def manage_openvpn(ctx, changed):
|
||||
@@ -473,10 +475,11 @@ def main():
|
||||
elif rules_changed:
|
||||
run(['ufw', 'reload'], check=False)
|
||||
|
||||
manage_directory()
|
||||
manage_tokens(cfg)
|
||||
manage_strongswan(ctx, changed)
|
||||
manage_wireguard(ctx, changed)
|
||||
|
||||
# The tunnels are up before the directory and the tokens, whose problems end setup only after every other step.
|
||||
problems = [problem for problem in (manage_directory(), manage_tokens(cfg)) if problem]
|
||||
manage_openvpn(ctx, changed)
|
||||
|
||||
if 'resolved' in changed:
|
||||
@@ -485,7 +488,9 @@ def main():
|
||||
run_platform_setup(cfg, ctx)
|
||||
refresh_docker_rules()
|
||||
refresh_web(cfg, ctx)
|
||||
return 0
|
||||
for problem in problems:
|
||||
print(f'vpn-router: error: {problem}', file=sys.stderr)
|
||||
return 1 if problems else 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in new issue
Block a user