Assert slapd is running to avoid miserably crashing with weird ldap errors

This commit is contained in:
Alexandre Aubin 2020-05-01 17:53:07 +02:00
parent 572feafc80
commit 6bd7eb64bd

View file

@ -19,8 +19,10 @@
"""
import os
import atexit
from moulinette.authenticators import ldap
from yunohost.utils.error import YunohostError
# We use a global variable to do some caching
# to avoid re-authenticating in case we call _get_ldap_authenticator multiple times
@ -32,6 +34,8 @@ def _get_ldap_interface():
if _ldap_interface is None:
assert_slapd_is_running()
conf = { "vendor": "ldap",
"name": "as-root",
"parameters": { 'uri': 'ldapi://%2Fvar%2Frun%2Fslapd%2Fldapi',
@ -45,6 +49,13 @@ def _get_ldap_interface():
return _ldap_interface
def assert_slapd_is_running():
# Assert slapd is running...
if not os.system("pgrep slapd >dev/null") == 0:
raise YunohostError("Service slapd is not running but is required to perform this action ... You can try to investigate what's happening with 'systemctl status slapd'")
# We regularly want to extract stuff like 'bar' in ldap path like
# foo=bar,dn=users.example.org,ou=example.org,dc=org so this small helper allow
# to do this without relying of dozens of mysterious string.split()[0]