Systemctl Commands In Linux

"All the services are controlled by kernel itself & required services are initiated at the time of boot"

How System Bootup

The brief process of system bootup has shown below.

BIOS >> Bootloader- access the MBR file from hdd >> MBR loads the GRUB >> GRUB loads kernel >> kernel start services -systemd

What is Systemd:

Systemd is a system and service manager for Linux operating systems. When run as first process on boot (as PID 1), it acts as init system that brings up and maintains userspace services

- So systemd is first service which initiates once system is boot up & it's PID number is 1.

- Systemd is daemon which manage or control all the services running in the system

- Systemd has a capability to parallel start of system service at the boot time

- Systemd works on unit concept in which all services are categorized under these unit types

What is Unit:

A unit is a resource which can be managed or controlled by systemd.

The following unit types are available:

Service Unit : Which start and control daemons and the processes they consist of.

Socket Unit : Which encapsulate local IPC or network sockets in the system, useful for socket-based activation.

Target Unit : Target units are useful to group units, or provide well-known synchronization points during boot-up.

Device Unit : Target units are useful to group units, or provide well-known synchronization points during boot-up.

Mount Unit : Mount units control mount points in the file system, for details see systemd.

Automount units :Automount units provide automount capabilities, for on-demand mounting of file systems as well as parallelized boot-up

Snapshot Unit : Snapshot units can be used to temporarily save the state of the set of systemd units, which later may be restored by activating the saved snapshot unit.

Timer Unit : Timer units are useful for triggering activation of other units based on timers

Swap Unit : Swap units are very similar to mount units and encapsulate memory swap partitions or files of the operating system. They are described in systemd.

Path Unit : Path units may be used to activate other services when file system objects change or are modified.

Slice Unit : Slice units may be used to group units which manage system processes (such as service and scope units) in a hierarchical tree for resource management purposes

Scope Unit: Scope units are similar to service units, but manage foreign processes instead of starting them as well

File Path For Systemd Services

Systemd unit files distributed with installed RPM packages

# usr/lib/systemd/system

Systemd unit files created at run time

# /run/systemd/system

Systemd unit files which are created by systemctl enable command

# /etc/systemd/system

What is Systemctl

Systemctl is a command-line utility which is use to inspect & control 'systemd' system and service manager in Linux. It is sucessor of previously used sysV init script . List of commands given below to manage system services.

1: List loaded & active services only

#systemctl

It will list all the services which are active and loaded in system . The list has four column which are described below

Unit : It shows the service unit type.

Load : It reflects whether the unit definition was properly loaded

Active : The high-level unit activation state, i.e. generalization of SUB.

SUB : The low-level unit activation state, values depend on unit type.

2: List all servies whether they are in active/inactive state.

# systemctl --all

3: Start a service

# systemctl start 'service_name'

Example:

4: Start a service

# systemctl stop 'service_name'

5: Enable a service so it will automatically start at the time of boot.

# systemctl enable 'service_name'

6: Disable a service so it will not automatically start at the time of boot.

# systemctl disable 'service_name'

7: Check whether a service is active or not.

# systemctl is-active 'service_name'

8: Check current status of a service.

# systemctl status 'service_name'

9: List all services and check if they are enabled.

# systemctl list-unit-files --type service

Example:

10: List only specific type of unit files.

# systemctl –-type="unit_name"

Example:

11: List services that are ordered to start before the specified unit.

# systemctl list-dependencies --after

Example:

12: List services that are ordered to start after the specified unit.

# systemctl list-dependencies --before

13: Restart a service.

# systemctl restart "service_name"

14: Restart a service if service already in running state.

# systemctl try-restart "service_name"

15: Reload a service configuration if service already in running state.

# systemctl reload "service_name"

16: Display the status of all services.

# systemctl list-units --type service --all

17: list all unit file dependencies for a particular service

# systemctl list-dependencies "service_name"

Example:

18: To edit the service unit file behaviour without knowing the actual path of the file.

#systemctl edit –-full "service_name"

Example:

#systemctl edit –-full httpd.service

19: To see the configuration text content of a service unit file without knowing the actual path of the file.

#systemctl cat "service_name"

Example:

#systemctl cat httpd

20: To see low level information of a service.

#systemctl show 'service_name'

Example:

#systemctl show sshd

21: To display full name of unit file with its enable or disable state.

#systemctl list-unit-files --type service'

22: To prevent a service from being started manually or by another service.

#systemctl mask 'service_name'

23: To undo the previous(22) action.

#systemctl unmask 'service_name'

24: Target files are similar to runlevels in Linux. To check the default target means what runlevel you are currently using.

#systemctl get-default

Runlevel and Systemd Target files comparison :

25: To see all targets files in Linux

#systemctl list-units --type target

26: To switch to another target

#systemctl isolet 'target_name'

Example :

#systemctl isolet reboot.target

27: To set target as default

#systemctl set-default 'target_name'

Example :

#systemctl set-default multi-user.target

Post a Comment

0 Comments