- In this video, I'll tell you about systemd socket's.
So, a systemd socket is used with a service.
To start a service
when traffic comes in on a specific socket.
To use systemd socket's, you will have a service
as well as a socket file
and they need to have the same name.
So, sshd.service would come with sshd.socket ,for instance.
You can use ListenStream to tell the socket
to listen on a TCP port.
Or ListenDatagram to listen on a UDP port.
And when using socket's, the socket is started
or enabled or both
and not a service.
So, it's a socket that's taking over the activity
and triggering the service whenever that is needed.
Let me show you.
So, let me use systemctl list unit files minus D socket.
The minus D option is a nice option that allows you to
filter only a specific type.
And here we can see the socket files that are available
on my system by default.
So, there is an sshd.socket.
Let's check out sshd.socket,
which is currently disabled and disabled.
That's okay, we can always enable it if you want to.
Now the thing to realize here,
sshd.socket comes with sshd.service.
Cockpit.socket, which is another one that's pretty common
in Red Hat environments, comes with cockpit.service.
And the only thing you need to do is to enable the socket
if you want it to trigger the service.
And that's exactly what we are going to do.
Well, you know what?
Let's rather have a look at cockpit.socket.
So, systemctl cat on cockpit.socket,
is showing us what this thing is doing.
So, here we have the socket configuration and
on the socket configuration
we have ListenStream set to 90 90,
which is the default cockpit port.
So, let's check out systemctl status
on cockpit.service.
And there we can see it's inactive (dead).
That's exactly what I want it to be.
I want to use systemctl enable.
That is now on cockpit.socket.
And now what is happening
if you do the status on cockpit.service again?
Well, it's still inactive and dead
but we can see a green light
for triggered by cockpit.socket.
So, I am going to open a browser
and let's check out what is happening on port 90 90,
of this sent to our system.
So, I'm going to local host
call on 90 90.
And there we can see the potential security risk.
That's okay, we are going to accept the risk and continue.
And there we go CentOS Stream.
So, let's log in as the root user
with the passwords to get access to the cockpit
the web-based interface that is available
on CentOS in Red Hat's related service by default.
So, what is the issue?
Well, the issue is that right now
I'm in this cockpit and if we check out the status
of cockpit.service again.
There we can see that it is active and it is running
because of the socket.
And if we are going to disable it again
by closing all tabs and quit
then the socket is going to be disabled
after a while as well.
Apparently, it doesn't realize yet
that there is no incoming traffic anymore,
but it'll disappear.
And that's the benefit of using socket's.
Now, there is a couple
of socket's that come pre-installed when
you install your Linux distribution.
Apart from that, you can always create your own.
Socket's work with everything.
You just tell the socket what to monitor,
make sure it has the same name as a service
and that's going to be all.