Problem with OpenLDAP server

I get the following errors
ldap.service - Start OpenLDAP server
Loaded: loaded (/usr/lib/systemd/system/ldap.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Mon 2023-07-17 15:28:36 IST; 2s ago
Process: 10330 ExecStop=/usr/bin/kill cat /var/run/slapd/slapd.pid (code=exited, status=1/FAILURE)
Process: 10326 ExecStart=/bin/sh -c slapd 2>&1 </dev/null (code=exited, status=0/SUCCESS)
Main PID: 10326 (code=exited, status=0/SUCCESS)

Jul 17 15:28:36 tesla.ue.ucc.ie systemd[1]: Started Start OpenLDAP server.
Jul 17 15:28:36 tesla.ue.ucc.ie slapd[10327]: @(#) $OpenLDAP: slapd 2.4.46 (Oct 11 2021 21:12:19) $
mockbuild@ord1-prod-x86build002.svc.aws.rockylinux.org:/builddir/build/BUILD/openldap-2.4.46/openldap-2.4.46/servers/sla>
Jul 17 15:28:36 tesla.ue.ucc.ie slapd[10328]: slapd starting
Jul 17 15:28:36 tesla.ue.ucc.ie kill[10330]: kill: cannot find process “cat" Jul 17 15:28:36 tesla.ue.ucc.ie kill[10330]: kill: cannot find process "/var/run/slapd/slapd.pid
Jul 17 15:28:36 tesla.ue.ucc.ie systemd[1]: ldap.service: Control process exited, code=exited status=1
Jul 17 15:28:36 tesla.ue.ucc.ie slapd[10328]: daemon: shutdown requested and initiated.
Jul 17 15:28:36 tesla.ue.ucc.ie slapd[10328]: slapd shutdown: waiting for 0 operations/tasks to finish
Jul 17 15:28:36 tesla.ue.ucc.ie slapd[10328]: slapd stopped.
Jul 17 15:28:36 tesla.ue.ucc.ie systemd[1]: ldap.service: Failed with result ‘exit-code’.


ls: cannot access ‘/var/run/slapd/’: No such file or directory

I have Rocky Linux release 8.8 (Green Obsidian)
openldap-servers.x86_64 2.4.46-18.el8

When I run the command slapd & it works.
Looks like some issue with systemctl start/stop ldap.service

This is my ldap.service file :
[Unit]
Description=Start OpenLDAP server

[Service]
ExecStart=/bin/sh -c ‘slapd 2>&1 </dev/null’
ExecStop=kill cat /var/run/slapd/slapd.pid

[Install]
WantedBy=multi-user.target

OK problem solved:
I got a few thing wrong:

  1. I was using systemctl start/stop ldap.service, it should be systemctl start/stop slapd.service
  2. I did not have slapd.service enabled to start at boot, so when I did a reboot [which I do not do very often] slapd was not starting.
1 Like

Note that the systemctl status slapd.service shows only latest log messages.
The journalctl -u slapd.service shows more.


For more “what (services) do I have?” see outputs of:

systemctl status
systemctl list-unit-files
systemctl

Red Hat has deprecated OpenLDAP server in RHEL. They do offer 389ds (aka dirsrv).
(Considering the recent turmoil that is mere trivia.)

My problem now is that the dir /var/run/slapd is not been created after a reboot.
/run/openldap/ is but has no slapd.pid after spald starts.

OK, I fixed that now:
In /usr/lib/tmpfiles.d/slapd.conf
d /run/openladp 0755 ldap ldap --------> -d /run/slapd 0755 ldap ldap -

I am not sure how my system got screwed up.

Both EL8 and EL9 versions of the package (from PowerTools and EPEL, respectively) do claim
providing the /var/run/openldap:

[el8 ~]# dnf -q --enablerepo=powertools list openldap-servers
Available Packages
openldap-servers.x86_64             2.4.46-18.el8             powertools
[el8 ~]# dnf -q --enablerepo=powertools rq -l openldap-servers | grep -E "var|service"
/usr/lib/systemd/system/slapd.service
/var/lib/ldap
/var/run/openldap

[el9 ~]# dnf -q --enablerepo=epel list openldap-servers
Available Packages
openldap-servers.x86_64                 2.6.2-2.el9                 epel
[el9 ~l]# dnf -q --enablerepo=epel rq -l openldap-servers | grep -E "var|service"
/usr/lib/systemd/system/slapd.service
/var/lib/ldap
/var/run/openldap

The /run (which the /var/run points to) is a tmpfs in RAM, so created on boot.
That means that something must create the /run/openldap on boot or at start of service.

As you find out, the tmpfiles does some of it and openldap-servers has something for it:

[el8 ~]# dnf -q --enablerepo=powertools rq -l openldap-servers | grep -E "tmpfil"
/usr/lib/tmpfiles.d/slapd.conf

Logically, slapd.service must start after the tmpfiles has done its bit.


PS. At least on el9 systemd does warn about /var/run and implores to update scripts to use /run.

I have two systemd scripts on my system:
/usr/lib/systemd/system/ldap.service
/usr/lib/systemd/system/slapd.service

only /usr/lib/systemd/system/slapd.service works and produces /run/slapd/slapd.pid and /run/slapd/slapd.args

Any idea as to why this is?

Where do they come from?

rpm -qf /usr/lib/systemd/system/ldap.service
rpm -qf /usr/lib/systemd/system/slapd.service

and what is in the working unti file (/usr/lib/systemd/system/slapd.service)?

file /usr/lib/systemd/system/ldap.service is not owned by any package

rpm -qf /usr/lib/systemd/system/slapd.service
openldap-servers-2.4.46-18.el8.x86_64

/usr/lib/systemd/system/slapd.service

Unit]
Description=OpenLDAP Server Daemon
After=syslog.target network-online.target
Documentation=man:slapd
Documentation=man:slapd-config
Documentation=man:slapd-hdb
Documentation=man:slapd-mdb
Documentation=file:///usr/share/doc/openldap-servers/guide.html

[Service]
Type=forking
ExecStartPre=/usr/libexec/openldap/check-config.sh
ExecStart=/usr/sbin/slapd -u ldap -h “ldap:/// ldaps:/// ldapi:///”

[Install]
WantedBy=multi-user.target
Alias=openldap.service

Was probably created by you and can be removed.
It should not have been in /usr/lib/systemd/system in the first place;
local customizations should go to /etc/systemd/system. See man systemd.unit

See description of PIDFile in man systemd.service
See description of unit file command edit in man systemctl


You could edit the service with:

systemctl edit slapd.service

(It starts vi by default.)

You start with empty buffer, and should probably add:

[Service]
PIDFile=/run/openldap/slapd.pid

After save&quit (of editor) you should find a subdir and file under /etc/systemd/system.


You should also read man slapd and man slapd-config to see whether the PID-file is mentioned there; you want everybody to agree that it is the /run/openldap/slapd.pid


If that does not work out, then revert and adjust the tpmfiles config to create /run/slapd on boot instead.