Sunday, January 26, 2014

What Is Systemd and How It Works (Part 3)

Hello everyone,
Today, I continue the systemd discussion, part3. If you haven't read or missed part 1 and 2, you can find it in the following links: and
In part 3, I would like to talk about special targets and template unit files. systemd has a set of special target files designed for special purposes. you can find a list of special targets in man page, man systemd.special, Figure 1.

                                                                      Figure 1

Some of these special targets are used for on demand services such as printer and bluetooth. So, when a printer is connected and turned on, the printer target becomes active ( Another example can be It's activated when the system detects sound card at boot or it plugs in.
As I said, a full list of special targets are available in manpage including explanations (man systemd.special), however, I tried to explain some them: It loads basic system and boot-up. It pull-in mount points, sockets, and other basic initializations necessary for general purpose daemons.

                                                                          Figure 2 Activated when the user press Ctrl+Alt+Del keys and it is a link to the which reboots the system. It references to special target to be activated on boot (usually or It's equivalent to run level 3 or 5 in system V. Starts base system with an emergency shell on the main console. Starts up command line interface and it's multi-user (Similar to runlevel 3) Starts GUI interface (Similar to runlevel 5) For shutting down the system. For rebooting system. For setting up the base system and a rescue shell For terminating the services on system shutdown For covering early boot-up scripts For an offline system update. For shutting down the user service manager

Template unit files

There is a special type of unit file called a template file. A template file name ends with an @ sign. If a corresponding unit file is not found for a service, systemd will check to see if there is template file that can be applied to it. For example, you don't know how many terminals you may use, therefore, they are generated automatically using the getty@.service unit file. Let's take a look at getty@.service: Figure 3

                                                                         Figure 3

Here, since it's template, %I is used to substitute for the actual service name. For example, if the service name is getty@tty2, %I is substituted with tty2.

Finally, systemctl command is used to control the systemd system and service manager. You can still use the "service" command, however, it redirects to systemctl after running "service" command. Figure 4 shows that how we can use the systemctl and service command:

                                                                           Figure 4

And pretty much that's it. Hope it was useful and you enjoyed.
Khosro Taraghi

1 comment: