mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Assert slapd is running to avoid miserably crashing with weird ldap errors
This commit is contained in:
parent
572feafc80
commit
6bd7eb64bd
1 changed files with 11 additions and 0 deletions
|
@ -19,8 +19,10 @@
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
import atexit
|
import atexit
|
||||||
from moulinette.authenticators import ldap
|
from moulinette.authenticators import ldap
|
||||||
|
from yunohost.utils.error import YunohostError
|
||||||
|
|
||||||
# We use a global variable to do some caching
|
# We use a global variable to do some caching
|
||||||
# to avoid re-authenticating in case we call _get_ldap_authenticator multiple times
|
# 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:
|
if _ldap_interface is None:
|
||||||
|
|
||||||
|
assert_slapd_is_running()
|
||||||
|
|
||||||
conf = { "vendor": "ldap",
|
conf = { "vendor": "ldap",
|
||||||
"name": "as-root",
|
"name": "as-root",
|
||||||
"parameters": { 'uri': 'ldapi://%2Fvar%2Frun%2Fslapd%2Fldapi',
|
"parameters": { 'uri': 'ldapi://%2Fvar%2Frun%2Fslapd%2Fldapi',
|
||||||
|
@ -45,6 +49,13 @@ def _get_ldap_interface():
|
||||||
return _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
|
# 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
|
# 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]
|
# to do this without relying of dozens of mysterious string.split()[0]
|
||||||
|
|
Loading…
Add table
Reference in a new issue