Linux 101 : Useful "systemctl" commands - Unit, Unit files, Targets -
Units and unit files:
Units represent services and system resources - sockets, devices, mounts, ... -
Unit files represent the configuration of these services and system resources.
To list the enabled services - services that start at boot time -, we use the below:
To list all the units loaded in a Linux system, we use:
Units have a name and a type and use the following format "name.type".
Services or daemons have unit files with the ".service" extension.
Targets:
We could group services and start them together using target unit files.
After the system boots up , the "default.target" unit manages and starts all the required services for the default target.
The "default.target" unit points to a target, for example the "graphical.target".
We could check what our system uses as its default target using the below command:
Below are the most used targets:
- graphical.target : allows us to have multi-user environment, plus a graphical interface.
- multi-user.target : offers a multi-user access to the system with no graphical interface.
Service unit files hold information about services and live in different directories.
The directories are shown in increasing order of priority:
- /etc/systemd/system
- /run/systemd/system
- /usr/lib/systemd/system
To change a unit's configuration file, we make a copy of the file in the "/etc/systemd/system" directory and make the modification there.
For example "/etc/systemd/system/my_modified_service.service".
After we are done, we run the below command for the changes to take effect:
We might also need to restart the service as below:
Comments