Let's talk about dependencies in systemd.
So you can manage unit dependencies.
And these dependencies normally are defined in the unit section within the unit file.
An easy way to figure out about the current dependencies is systemctl list dependencies.
That is something that you can do without an argument to see all the dependencies that
have brought you into the current state, or use an argument such as systemctl list dependencies
boot.mount to show the current dependencies that are required by a specific unit.
You can also use options within the unit file to manage dependencies.
Use requires, which means that if this unit loads, the units that are listed here will
load as well.
And if one of the other units is deactivated, this unit will be deactivated as well.
There is a requisite.
A requisite is what you use if you must have the unit already available, otherwise this
unit will fail.
There is once, which is a soft dependency.
It means that this unit wants to load the units listed here, but it won't fail if any
of these units fail.
And we have before, which will start this unit before the unit mentioned with before.
And after, we'll start this unit after the unit that is mentioned with after equals.
Let's do a quick demo.
So let me start by using systemctl list dependencies.
Why not?
Boot.mount.
It's one of the mount targets.
And here we can see it doesn't have very many dependencies.
And if you do that for another service like sshd.service, there you can see everything
that is required to get sshd.service.
Look at the green dots because the green dots indicate what should really be there.
Now I want to show you a demo where I'm going to create a dependency myself.
In order to do so, I need to install the vsftpd service.
And then I'm going to use systemctl edit on httpd.service.
And in the edit, I'm doing it a nice way.
I want to have this in the override file so that my edits are protected from system
updates.
So I'm going to use unit and requires is vsftpd.service, which happens to be the name of my vsftpd service.
Now I'm using psaox.pipe.grep.ftp to show you that currently we don't have any vsftpd.
Now I'm going to use systemctl restart httpd.service.
And I'm doing my psaox again.
And look at that.
vsftpd is started as well.
Can we find any information about it?
Systemctl status vsftpd.
Without the service, it defaults to service.
I can see that it is started, but you don't really see anything about the dependency relation,
the reason why it has been started.
And on the httpd, well, we can see that httpd has an override.conf.
But for the rest of it, we don't see the dependency relation either.
So you really need to figure out how it works.
And that is where systemctl list dependencies can come in handy.