25

I need to specify a boot order for processes to start. I have 389 Directory Server and Samba running on Fedora 18. How can I have the network services boot, then 389 DS, then Samba? Is there a GUI to manage this in Fedora?

I have enabled Samba to start with systemctl enable smb.service. I have also enabled 389 DS with systemctl enable dirsrv.target.

3
  • Systemd doesn't require order among services, the idea is to start everything in parallel and hand the conections to the servers as they become available. The configuration given by the default installation should be fine. Why do you think you have to define an order? Does something fail to work?
    – vonbrand
    Feb 27, 2013 at 0:47
  • I should also note, since this has come back up, that you really shouldn't be running file/print services on your domain controller. Feb 22, 2014 at 22:45
  • @vonbrand I had this problem, where my DHCP server needed slapd to be up (because its configuration was stored in an LDAP directory). If it wasn't, the DHCP server wouldn't come up.
    – mat
    Sep 18, 2017 at 12:33

4 Answers 4

37

Use systemctl edit smb.service to update the dependencies.

After=dirsrv.target - Will ensure the smb.service is started after dirsrv.target.

For robustness, (which will be worth while if you're tinkering with this stuff) you may also wish to include some of the following:

Requires=dirsrv.target - Activate dirsrv.target when smb.service is activated. Will cause smb.service to fail if dirsrv.target fails.

Wants=dirsrv.target - Activate dirsrv.target when smb.service is activated. Won't cause smb.service to fail if dirsrv.target fails.

BindsTo=dirsrv.target - If dirsrv.target is deactivated, deactivate smb.service.

Source: http://www.freedesktop.org/software/systemd/man/systemd.unit.html

systemd-ui provides a GUI for systemd. Gives a good view of the state of systemd but you'll still have to use a text editor to modify the unit files.

3
  • In a case A Requires B , what will say "B" has "failed" so that A will not be started? The program of B return a Non-zero value?
    – John Wang
    Oct 19, 2016 at 9:13
  • 3
    Downvoted because this advises bad practice. Do not edit the /usr/lib/systemd versions of unit files unless you are a distro maintainer or you enjoy your files getting overwritten on each package update. Either copy the unit file into /etc/systemd and then edit, or use a drop-in file (see systemd.unit(5) for details). Even easier, just use systemctl edit smb.service which does the drop-in file magic automatically! Mar 11, 2019 at 0:01
  • 4
    Thanks for editing the answer! It resolves concerns, and I have converted to an upvote. :-) Mar 18, 2019 at 3:10
12

Do two things:

  1. Edit the /lib/systemd/system/smb.service unit file, to specify the dependency. The [unit] section contains an After= line which specifies what services/targets should be reached before this one.

    After=syslog.target network.target nmb.service winbind.service
    

    Change it to:

    After=dirsrv.target syslog.target network.target nmb.service winbind.service
    
  2. Report this dependency back to Fedora as a bug, so that it can be incorporated in future releases.

2
  • That doesn't seem to work. Samba is still booting before 389. Feb 27, 2013 at 20:43
  • 6
    after you modify unit files, you should usually run systemctl daemon-reload Jun 26, 2015 at 14:52
5

you maybe need to change or include a line with the Requires directive in the [Unit] section of the /usr/lib/systemd/system/smb.service file.

Requires=dirsrv.target

and

After=dirsrv.target
2
  • Well, I've voted for this answer, however, I'd personally go with Wants=dirsrv.target instead of Requires=. (see systemd.unit(5) for Wants=)
    – galaxy
    Aug 2, 2014 at 9:22
  • short and simple. nice answer!
    – agfe2
    Nov 8, 2022 at 7:36
4

There are two alternatives to modifying the service file in /usr/lib/systemd/system (see Example 2. Overriding vendor settings):

  1. Copy the file to /etc/systemd/system and perform the modifications on the copy. This file will completely override the file in /usr/lib.

  2. Create the file /etc/systemd/system/smb.service.d/local.conf. The contents of the file should be something like the example below. This selectively overrides the "Requires" and "After" options in the vendor provided service file.

Each of these (including modifying the file in /usr/lib) offers advantages and disadvantages. The best choice may depend on the service and the nature of the modifications.

While it may work, it is not sufficient to only add the "After" option (see [Unit] Section Options). "After" controls order, but not dependencies. If dirsrv.target is not started in some other way, specifying an order will not start it. Use of the "Requires" or "Wants" option will force dirsrv.target to be started.

[Unit]
Requires=dirsrv.target
After=dirsrv.target

NB: I don't know if this approach was available when this question was originally asked.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .