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.
# systemctl -t help
[box] 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)
Active: active (running) since Wed 2015-12-16 08:35:38 UTC; 2 months 21 days ago
Main PID: 506 (chronyd)
└─506 /usr/sbin/chronyd -u chrony [/box]
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]