Systemd Declaring a Service Dependency: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Internal=
=Internal=
* [[Systemd_Operations#Declaring_a_Dependency_between_Services|systemd Operations]]
* [[Systemd_Concepts#Dependencies|systemd Concepts]]


* [[systemd]]
=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:
 
{{Internal|Systemd_Concepts#Dependencies|systemd dependencies}}
 
=Procedure=
 
==Create a httpd systemd service configuration directory==
This is only necessary if the unit file (ex: <code>/usr/lib/systemd/system/httpd.service</code>) does not already exits.
 
If it does not exist, create a directory:
<font size=-2>
/etc/systemd/system/httpd.service.d
</font>
 
==Create a httpd systemd service configuration file that expresses the dependency==
 
Create a <tt>/etc/systemd/system/httpd.service.d/http-extra.conf</tt> file with the following content:
 
<syntaxhighlight lang='ini'>
[Unit]
Requires=network-online.target
After=network-online.target
</syntaxhighlight>
 
⚠️ Wrong configurations used <code>network.target</code>. This is incorrect, it has to be <code>network-online.target</code>.


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


=Overview=
=Procedure 2=
 
<font color=darkkhaki>TODO: Document this, it worked expressing the haproxy dependency on named.</font>
 
Declare the dependency directly on a service, in the dependent service unit file:
<syntaxhighlight lang='ini'>
...
Requires=named.service
After=named.service
...
</syntaxhighlight>
 
This also worked:
<syntaxhighlight lang='ini'>
...
After=network-online.target sshd-keygen.service
Wants=sshd-keygen.service
...
</syntaxhighlight>

Latest revision as of 03:13, 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

This is only necessary if the unit file (ex: /usr/lib/systemd/system/httpd.service) does not already exits.

If it does not exist, create a 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

⚠️ Wrong configurations used network.target. This is incorrect, it has to be 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
...