Systemd Declaring a Service Dependency: Difference between revisions
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=Internal= | =Internal= | ||
* [[Systemd_Operations#Declaring_a_Dependency_between_Services|systemd Operations]] | |||
* [[systemd]] | * [[Systemd_Concepts#Dependencies|systemd Concepts]] | ||
=Overview= | =Overview= | ||
Line 12: | Line 12: | ||
==Create a httpd systemd service configuration directory== | ==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: | ||
/etc/systemd/system/httpd.service.d | <font size=-2> | ||
</ | /etc/systemd/system/httpd.service.d | ||
</font> | |||
==Create a httpd systemd service configuration file that expresses the dependency== | ==Create a httpd systemd service configuration file that expresses the dependency== | ||
Line 21: | Line 23: | ||
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: | ||
< | <syntaxhighlight lang='ini'> | ||
[Unit] | [Unit] | ||
Requires=network-online.target | Requires=network-online.target | ||
After=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]]. | For more details on the structure of a systemd unit file, see [[systemd Concepts#.5BUnit.5D_Section|the [Unit] section of a unit file]]. | ||
Line 31: | Line 35: | ||
=Procedure 2= | =Procedure 2= | ||
<font color= | <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: | 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: | 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:
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
...