Systemd Declaring a Service Dependency: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 21: Line 21:
Create a <tt>/etc/systemd/system/httpd.service.d/http-extra.conf</tt> file with the following content:
Create a <tt>/etc/systemd/system/httpd.service.d/http-extra.conf</tt> file with the following content:


<pre>
<syntaxhighlight lang='ini'>
[Unit]
[Unit]
Requires=network-online.target
Requires=network-online.target
After=network-online.target
After=network-online.target
</pre>
</syntaxhighlight>


For more details on the structure of a systemd unit file, see [[systemd Concepts#.5BUnit.5D_Section|the [Unit] section of a unit file]].
For more details on the structure of a systemd unit file, see [[systemd Concepts#.5BUnit.5D_Section|the [Unit] section of a unit file]].

Revision as of 02:40, 1 January 2024

Internal

Overview

This example shows how to declare a dependency between httpd and network services - the system should not attempt to start httpd unless the network service are started, otherwise httpd won't find the network interfaces to bind to. For more details on concepts behind dependencies, see:

systemd dependencies

Procedure

Create a httpd systemd service configuration directory

/etc/systemd/system/httpd.service.d

Create a httpd systemd service configuration file that expresses the dependency

Create a /etc/systemd/system/httpd.service.d/http-extra.conf file with the following content:

[Unit]
Requires=network-online.target
After=network-online.target

For more details on the structure of a systemd unit file, see the [Unit] section of a unit file.

Procedure 2

TODO: Document this, it worked expressing the haproxy dependency on named.

Declare the dependency directly on a service, in the dependent service unit file:

...
Requires=named.service
After=named.service
...

This also worked:

...
After=network-online.target sshd-keygen.service
Wants=sshd-keygen.service
...