1

I have a machine hosting an LDAP database and services on other machines run as users from that database. Because the user accounts does not exist locally, the services fail to start when those machines boot before the machine hosting the LDAP database.

All the machines are running Ubuntu 14.04 except for one that is running CentOS 7. Is it possible with upstart and systemd to wait for the LDAP database to be available before starting certain services?

EDIT: I've tried using a pre-start script with Upstart that loops until LDAP is available, but that doesn't work. I found in the Upstart cookbook that the pre-start script is run as user and group specified with "setuid" and "setgid". So the pre-start script is never run because the user and group doesn't exist until the LDAP service is running on another machine.

I tried specifying "respawn" as well but that didn't help in this case. From what I understand from the Upstart cookbook, respawn only takes effect when the main script or executable fails. Thus, the service is not restarted because the service fails before any script is run.

1

I assume you're using systemd, so I would recommend modifying the systemd service file as needed.

The Restart= flag indicates whether or not the service should be started if not running, depending on why it's not running.

You can have: Restart=on-failure as an example. This way the service will continue trying to start until it succeeds.

If you want instead, you can use ExecStart= or ExecStartPre= to run bash commands before the service starts to confirm ldap is available.

You can find more about systemd service files here: https://www.freedesktop.org/software/systemd/man/systemd.service.html

EDIT: For Upstart (Ubuntu) the respawn flag should work similar to systemd Restart=on-failure flag https://wiki.ubuntu.com/SystemdForUpstartUsers

  • I am using systemd for CentOS, but Ubuntu 14.04 is using Upstart with init files in /etc/init. Could I do something similar with them? – Jimmy Jun 8 '16 at 17:44
  • @Jimmy whops! I saw CentOS 7 and got a bit of tunnel vision, it should still be possible with ubuntu services, though I haven't tried it. According to upstart.ubuntu.com/getting-started.html you can write a prestart script, could work with a while loop that tests ldap and sleeps if ldap isn't up. There also looks to be a respawn flag for upstart, which might be equivalent wiki.ubuntu.com/SystemdForUpstartUsers – Centimane Jun 8 '16 at 18:18
  • @Jimmy apparently older versions of Ubuntu can also use systemd, but it may be more than you want to move things over wiki.ubuntu.com/SystemdForUpstartUsers – Centimane Jun 8 '16 at 18:20
  • I'm gonna try to make that script for systemd and upstart to see if it works satisfactorily. I know that versions after 14.04 support systemd and it can work on 14.04 but it is not fully supported. I'm planning to update all the machines but that is going to take some time so this is to keep things running meanwhile. – Jimmy Jun 8 '16 at 18:25
  • @Jimmy I don't know if you saw my comment edits, but I edited the answer with the equivalent flag for upstart. – Centimane Jun 8 '16 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.