Daemons in Linux | Systemctl List Services

Hello everyone In this Article we are going to learn How to manage demons and targets using systemctl command in Linux in a very simple and easy step-by-step approach

Daemons in Linux

Daemons in Linux

The systemctl command is used to manage the demon and the targets that are running in the Linux kernel. The systemctl is a very useful command to start/stop/restart the particular demon that is running in the kernel.

Syntax Of systemctl command

systemctl option demon

1 How to check the status of service

To check the status for the service since how long that is running we can use the systemctl command with status as an option with the name of the service.

# systemctl status sshd
Screenshot 1 12

2. How to stop the service

To stop the service then we can write the stop option in with the service name.

# systemctl stop sshd
Screenshot 2 11

3 If we check status for sshd again now it is showing in stop stage

This is a temporary stop after reboot it will start again

# systemctl status sshd
Screenshot 3 11

When we reboot the server the service will run again

4 How to stop the service permanently

To stop the service permanent then we have to use the disable option in systemctl command this will disable the service after reboot also.

# systemctl disable sshd
Screenshot 4 12

5 How to start the service

To start the service again then we can add the start option with the service name systemctl command

But our service will stop again after reboot.

# systemctl start sshd
Screenshot 5 12

6 How to start the service permanently

To start the service permanently then we have to use enable the option in systemctl command and the service name

# systemctl enable sshd 
Screenshot 6 11

7 How to reload the service

To reload the service then we can use the reload option in systemctl command then it will reload the service.

Suppose that we have done a change in the configuration file then in order to tell the kernel for the change we need to reload the service.

# systemctl reload sshd
Screenshot 7 10

8 How to restart the service

To restart the service then we can add a restart option in systemclt command with the service name.

If we restart the service then our process id will change.

Suppose that 100 users are connected to our server and if we restart the service then the connection will break.

So we will reload the service instead of restarting the service.

For example when we do #systemctl status sshd we are having the PID of 6223

Screenshot 8 9
# systemctl restart sshd 
Screenshot 9 9

Now when we check status again then PID will changed to 7383

Screenshot 10 8

Type of targets in the Linux kernel –

There are 4 types of targets in the linux kernel

1 – Graphical.target -When we want to open GUI Mode then we have to be in this target

2 – multi-user.target – When we want to open CLI Mode then we have to be in this target

3 – rescue.target – When we want to troubleshoot the Operating system then we have to be in this target

4 – emegency.target – When we want to open emergency mode then we have to be in this target

We can set these targets as a permanent or a temporary in linux kernel These manage by systemctl

How to check the current target

To check the current target we can use systemctl command with the get-default option..

# systemctl get-default
Screenshot 11 9

How to convert to different targets

To convert to different targets, for example, rescue.target then we can use the isolate option and then target name.

# systemctl isolate rescue.target
Screenshot 12 9

But If we use the isolate option in the command then this will set temporary targets. After reboot, the target will be in default

How to set target permanently

To set the target permanently then we can use the set-default option in systemctl command with the target name.

 # systemctl set-default multiuser.target 
Screenshot 13 7

Now if we want to go to graphical.target then we can execute .

# sysemctl set-default graphical.target

Similarly if we want to go to rescue mode then we can execute.

# sysemctl set-default rescue.target

Similarly if we want to go to emergency mode then we can execute

 # systemctl isolate rescue.target

Conclusion

If you want to learn Linux in the most simple language then please click on this link.

If you want to read online manual for systemctl command then click on this link

This is the complete knowledge of how we can manage the demons and targets using systemctl command the Linux kernel if you have any doubts please feel free to comment below. Please don’t forget to join our email subscription to get the latest updates on DevOps Articles

Leave a Comment