The basics of systemd consist of managing the state of a systemd unit.
So how does that work?
Well, you would use the systemctl command to manage everything that is going on.
Systemctl start will start the unit.
Systemctl status will show unit status and systemctl stop will stop it.
To find out about different unit properties, use systemctl show.
Also important is to make sure that units are started automatically when your system
boots.
We call that enabling and disabling units.
Use systemctl enable with the optional argument minus minus now to start it now also if it
hasn't been started yet.
And that will make sure that the unit is automatically started.
And systemctl disable minus minus now takes away automatic starting of the unit.
Systemctl list units will show all units currently loaded and systemctl list dependencies shows
all that was loaded to get to the current system state.
And finally, the command systemctl list unit files shows all unit files on this system.
And it can be convenient as well.
Let's check this out.
So I'm going to demonstrate the Httpd unit.
To start it, I need to install it using dnf install minus y Httpd.
I like to demonstrate Httpd because it's not an essential service that will break functionality
if something is going wrong.
Now let's start by using systemctl status on Httpd where we can see that systemd is
aware of the Httpd.service, but the white dot here is indicating that currently it's
inactive.
We can also see that systemd has found the unit file in userlib systemd system and the
name is Httpd.service, but currently it's disabled and the preset is disabled.
Let me change that using systemctl enable minus minus now Httpd, which is not only going
to flag it for automatic start, but which will start it right now as well.
So when you enable a unit, it's flagged for automatic start and behind the scenes, a symbolic
link is created in the etc systemd system multi-user target dot once directory.
And this symbolic link means that if you enter the multi-user target, it will follow the
symbolic link and as a result, it will automatically start the unit.
Now let's investigate the status again.
As you can see, there's a lot more information now.
So we can see that it is enabled, preset disabled.
That means that the default state of the unit as defined in the package is disabled.
The unit is active and running and we can even see the main process ID of the unit.
That's convenient for process management.
There is the number of tasks, there is the amount of memory it is using and more relevant
information, including the logs for this unit.
These logs are convenient because if anything doesn't work out well, well, you can easily
troubleshoot right here.
Now the unit works with different parameters.
We call them directives.
And if you want to know more about these directives, use systemctl show on httpd dot service.
So systemctl show followed by the name of the unit shows all of the directives that
are relevant for this specific unit.
And there you can see many directives and sometimes you will wonder what is this directive
doing?
Well, if ever you are wondering what is this directive doing, you can look that up.
Let's look up IP accounting, for instance.
To do so, I'm using man systemd dot directives.
And there you can find the list of all directives that exist.
So when I search for IP accounting using forward slash IP account, there we can see
that IP accounting is further defined in systemd resource control 5.
That's a man page.
So if I want to know more about IP accounting, I am going to use man systemd dot resource
control.
And there I can look it up, IP accounting, and I get a description of this directive.
Now this was just one example.
It will work for all directives.
Now we have a couple of units that are listed right now.
I like to figure out which these are.
And to do so, there is systemctl list units.
That will show you a list of all the units and their current state.
That can be convenient, but this is focused on units that are currently active.
If you want to see units that are inactive as well, I would suggest you use systemctl
list unit files.
There we can see the name of the units, nicely grouped by the unit type, and the current
state, and the preset.
So you can see if it is disabled or enabled, and that might give you a hint on what you
need to do to get your system in the desired state.
Now for a nice overview of everything that is happening in the current situation, you
can also use systemctl list dependencies.
That is showing the current state where you are, so the default target.
Default target on a graphical system is graphical.target.
And in the graphical.target, we have a couple of units.
Then graphical.target includes the multi-user target, which has units as well.
And you can see units that are currently running, but also units that are currently
not running.
And even, in some cases, with the Red Cross units that have had an issue.
I like systemctl list dependencies a lot because you get an overview of everything, and you
see the relation between the units in an easy way.