- [Narrator] In this video we'll talk about dependencies,
dependencies between different systemd units.
Different statements can be used in the Unit section
to define unit file dependencies.
There is Before, which means that this unit starts
before the specified unit.
And After, which obviously means that this unit starts
when the specified unit is started.
There is a Requires, which means that when this unit starts
the unit listed here is also started.
And if the specified unit fails, this one also fails.
And there is Wanted.
When this unit starts, the unit listed here is also started.
Now even if you can manage dependencies in units
you should consider using targets
for more consistent dependency management.
It's easy to have an overview of everything
that is going on,
but for now let's create some dependencies.
Okay, let me start by using dnf install vsftpd
(keyboard clicks)
And systemctl status httpd.
As you can see, loaded, disabled, inactive.
That's exactly what we need.
Loaded means that systemd knows which unit file to use
and that is about it.
For the rest of it, this unit currently is doing nothing.
Same case for vsftpd.
Now I'm going to use systemctl edit httpd dot service
And I'm going to edit the unit configuration.
Requires is vsftpd dot service.
And I'm using systemctl start.
No, before doing that let me use ps aux pipe grep ftp.
Just so we agree that there is no vsftpd service running
at this moment
and now I can use systemctl start httpd.
This is a systemd ctl start,
systemctl start doesn't make it persistent
that would need systemctl enabled,
but I don't need it to be persistent at this moment.
What I need is httpd to be starting
and what we also need is to see
that suddenly vsftpd is running as well
and that's what you obtain by using a Requires.
Now as I was mentioning a Requires isn't very clear
to analyze dependency relations
so it's probably much better to make sure that vsftpd,
as well as httpd, are just in the same target
and they're also WantedBy section.
WantedBy is not as strong as Requires
but by putting them in the same target
you make it easier to see the logical relation
between the two of them.