Overview of systemd and systemctl :
Systemd service manager manage boot process and server processes . In this tutorial , we are discussing about systemd services and socket units , which handle system daemons and network services.
Daemons are the services or process that run in task background or in wait to run. Generally the daemons started on boot time and it end when the system shutdown or we can manually close the process or down the daemon .
A socket is for communication which uses by a daemon. Socket is responsible for communication between local or remote clients. Socket can send and received communication and can bind to port, service and machine and in address in header of packet.
What systemd and systemctl units are ?
The systemctl command is to manage different type of systemd services and Units . There is different type of units available in systemd based system, below command will display will list of available units.
Available unit types:
Above was the output of available unit on systemd. Here we will discuss some basic units , which is very common .
Service Unit : This unit will cal with .service extension and it list system services. This type of units work when we need to start daemon frequently like ssh, web server and network services etc.
Path Unit : Same as other unit path unit have a .path extension and have used for services which are in spool directories.
Below is the command for list all mount units on the system. You can put any one of them from list of unit list like service ,socket,target,device,mount,automount,snapshot,timer,swap,path,slice,scope
Syntax :# systemctl list-units –type=[unit_name]
systemctl list-units --type=mount
To show all active and inactive socket on the system.
# systemctl list-units --type=[unit_name] --all
Verify the Status of units :
Here we are going to check installed and running status of servce on the system.
List all the service on services unit.
# systemctl list-units --type=service
Check status of the service, i have fetch from list which is “chronyd”. this service is used for NTP syncroniztion.
# systemctl status chronyd
● chronyd.service – NTP client/server
Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; preset: enabled)
Active: active (running) since Mon 2023-10-09 07:55:49 IST; 8h ago
Process: 1082 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 1102 (chronyd)
Tasks: 1 (limit: 9309)
└─1102 /usr/sbin/chronyd -F 2
Oct 09 07:55:49 desktop.server systemd: Started chronyd.service – NTP client/server.
Oct 09 07:56:52 desktop.server chronyd: Selected source 18.104.22.168 (2.rhel.pool.ntp.org)
Oct 09 07:56:53 desktop.server chronyd: Source 22.214.171.124 replaced with 126.96.36.199 (1.rhel.pool.ntp.org)
Oct 09 07:56:53 desktop.server chronyd: Selected source 188.8.131.52 (3.rhel.pool.ntp.org)
Oct 09 07:57:56 desktop.server chronyd: Selected source 184.108.40.206 (0.rhel.pool.ntp.org)
Oct 09 08:03:20 desktop.server chronyd: Selected source 220.127.116.11 (3.rhel.pool.ntp.org)
Below commands is very useful and its output is customized like we have run is-active and is-enabled for sshd service unit. which will check the service active and will be start on boot time.
the sshd output is shwoing active (running) means running with more than one processes and enabled will be started at the the boot time.
# systemctl is-enabled sshd enabled # systemctl is-active sshd active
Start / Restart / Stop OR mask/unmask on running system :
To Stop the service :
# systemctl stop [UNIT NAME]
To start/ restart the service :
# systemctl start [UNIT NAME]
># systemctl restart [UNIT NAME]
Check the status of service through below command.
# systemctl status [UNIT NAME]
Mask will prevent accidentally start a service that will be masked .
# systemclt mask [UNIT NAME]
To disable Mask , run the below command
# systemctl unmask [UNIT NAME]
Enable/Disable services at boot
To enable the service for next boot time :
# systemctl enable [UNIT NAME]
To disable the service
# systemctl disable [UNIT NAME]