Systemd Order Help?

Home » General » Systemd Order Help?
General 7 Comments

I’m looking into ‘porting’ some custom init.d scripts that are in use on CentOS 6 boxes for use on CentOS 7 using systemd

One particular init.d script needs to run after autofs has been started, but before X11 is started

I’m guessing I could use something like:

After=autofs.service
Before=graphical.target

Is this correct?

However, I would like to use the same systemd unit file on servers that won’t run X – will the above work? Or is there a better/another way of doing this?

Thanks

James Pearson

7 thoughts on - Systemd Order Help?

  • You probably want “display-manager.service” instead of
    “graphical.target”.

    You also will want “Requires=autofs.service”. The distinction between
    “After/Before” and “Requires” is exactly for the reason you give; the ordering directives don’t require anything, so without display-manager.service enabled, Before=display-manager.service is just a no-op. Actually, you might even want “BindsTo=autofs.service”, which is stronger.

    Depending on your setup, you many want to look at converting your automatic mounts into systemd mounts, and depend on that directly, rather than on the autofs service.

  • Matthew Miller wrote:

    Thanks – that makes sense …

    It’s one systemd (baby) step at a time for me at the moment – that’s probably too much to consider :-)

    Thanks

    James Pearson

  • You probably want “display-manager.service” instead of
    “graphical.target”.

    You also will want “Requires=autofs.service”. The distinction between
    “After/Before” and “Requires” is exactly for the reason you give; the ordering directives don’t require anything, so without display-manager.service enabled, Before=display-manager.service is just a no-op. Actually, you might even want “BindsTo=autofs.service”, which is stronger.

    Depending on your setup, you many want to look at converting your automatic mounts into systemd mounts, and depend on that directly, rather than on the autofs service.

    Just one little thing to note here that many don’t realise. All mounts in the system (ie not manually via the mount command) are systemd mounts.

    There’s a generator that makes mount units from fstab and it is the actual runtime mount unit that gets used.

    So with things in fstab you can still have a service require something like data.mount … There’s even a directive RequiresMountsFor to ensure that a path is mounted before that unit is started.

    Finally autofs is made even easier with systemd as all you need to do to declare a mount autofs is x-systemd.automount in the options field and then it’ll only be mounted on demand rather than at boot.

  • I’ve not actually tested that tbh Matt …

    I expect that indeed that case it wouldn’t work

    But unless you need a complicated map arrangement I’d argue on EL7
    you’d be better off using the fstab option to make the mount automount

  • […]

    Yeah, exactly what I meant with the first paragraph above. :)

    I’ve seen some prettttty complicated setups. And by seen, I mean “been responsible for”. And by “responsible”, I mean “to blame”. :)

LEAVE A COMMENT