Linux 101 : Systemd - Systemctl, Targets and "Runlevels" -



Systemd process:

The first process to be started by the boot process in the systemd process.
Systemd is comprised of different unit types, amongst them, are the service units

To display all the service, we use the below command:


It shows all the services (active and non-active).

Some other units types:

Mount unit: handle mountpoint.
Socket units: are is in charge of starting a network service when a connection is initiated to it,...
Target unit: a target unit is a group of different units that characterizes a certain "runlevel" or target, where only certain units are active. 

We use target units for example to go from a "graphical-multiuser" target to a "rescue-single-user" target for example, where only a limited amount of units is active.

Examples:

graphical.target= graphical multiuser target
multi-user.target= text-based, multiuser target
rescue.target= minimal system for fixing errors.


We notice from the above diagram that the graphical target is "built" on top of the multiuser target.
Units are "servicesthat runs when we enter a certain target.

To list all the target units we use the below command:


Dependencies:

Each target unit depends on other units to function properly. 
To display the dependencies of the "multi-user.target" for example, we use the below command:


To display the default "runlevel" or target, we use the below command:


To make a certain target, for example the "graphical.target" the default target - the one the machine boots up to -, we use the below command:


Changing a target:

We can change the target to a 
 "multi-user.target" for example using the below command:



Rebooting a system:

To reboot our system, we could use the below command:


The list-units and list-unit-files:

Lists-units tell us about the state of the units, whether they were loaded as they should.
It also displays their state ( active, failed, ... )

We could display the list-units using the below command:



List-unit-files tell us whether units are "enabled", which allows them to start at boot time, or "disabled" which does the opposite.

To display the list-unit-files, we use the below command:


Static: means that the service is "enabled" but it can't be manually disabled. 
The "Enabled" services start at boot time.

The configuration files of targets:

These files are located in the "/etc/systemd/system" and the "/usr/lib/systemd/system" directories.

For example below is the configuration file of the "graphical.target" target in "/usr/lib/systemd/system":



Requires: means the graphical.target is "built" on top of the multi-user.target.
Wants: means that when the graphical.target starts it will runs the "display-manager.service" service.

When the system moves to a different target graphical.targetmulti-user.target...), the units associated with new target are started

Enabling, disabling and masking a services:

To list the services on a system, we use:


We can then check if a service is enabled - starts at boot time - using the below command:


To disable a service, so it doesn't start at boot time we use the below command:


The disabled service will not start at boot time, but we could still start it using the below command:


To disable a service and prevent users from starting it using the "systemctl start" command, we mask it by running the below command:


Comments

Leave as a comment:

Archive