Systemd manages service daemons in RHEL7 (and most other Linux distros). There are 12 unit types in systemd:

Unit type    File extension      Description
service      .service            system service
target       .target             group of systemd units
automount    .automount          file system automount unit
device       .device             device file recognised by the kernel
mount        .mount              file system mount-point
path         .path               file or directory in the file system
scope        .scope              externally created process
slice        .slice              hierarchically organised units that manage system processes
snapshot     .snapshot           saved state of systemd manager
socket       .socket             IPC socket
swap         .swap               swap device or file
timer        .timer              systemd timer

Systemd locations are:

/usr/lib/systemd/system     → units installed with RPM packages
/run/systemd/system         → units created at run­time
/etc/systemd/system         → units created and managed by the sysadmin

Some of the most common systemctl commands are:

# systemctl start ntpd.service                → start service
# systemctl restart ntpd.service              → stop and start service
# systemctl stop ntpd.service                 → stop service
# systemctl status ntpd.service               → query status of service
# systemctl try­-restart ntpd.service          → restarts if it is already running
# systemctl reload ntpd.service               → reloads config
# systemctl enable ntpd.service               → start at boot time
# systemctl disable ntpd.service              → DO NOT start at boot time
# systemctl list-­units –­­type service          → lists loaded services
# systemctl list­-units ­­–type service ­­–all     → lists all services
# systemctl list­-unit-­files –­­type service     → lists services and status
# systemctl mask ntpd.service                 → prevent service from starting up
# systemctl unmask ntpd.service               → undo the command above
# systemctl is-­active ntpd.service            → replies active/inactive/unknown
# systemctl is­-enabled ntpd.service           → replies enabled/disabled
# systemctl is-­failed ntpd.service            → replies enabled/disabled
# systemctl daemon-­reload                     → reloads all unit files

We have to be aware of the mapping between SysV run levels and systemd’s:

runlevel       SysV                  systemd
0                   runlevel0 
1                   runlevel1 
2                   runlevel2
3                   runlevel3           multi-user.targets
4                   runlevel4
5                   runlevel5 
6                   runlevel6 

We can view the current and default targets with:

# systemctl list-­units –­­type target   → status of targets
# systemctl get-­default                → default boot target

To change the current and default targets:

# systemctl set-­default multi-­   → set boot target to multi­user non­graphical
# systemctl isolate graphical               → changes current runlevel to graphical
# systemctl rescue                          → changes current runlevel to single­user mode

In rescue mode (or single-user) all local file systems are mounted and the most important services are started.
If not even that can be achieved we would need to run:

# systemctl emergency

In the emergency runlevel only the root file system is mounted in read-only mode and just a few essential services are started. If for instance we had a problem mounting local file systems, this is the way to go.

In certain circumstances we can use systemctl over SSH to query or change the status of remote services:

# systemctl -H user@remote-server status ntpd.service

We can power-off/halt/reboot/suspend/hibernate the system with…

# systemctl poweroff
systemctl halt
# systemctl reboot
# systemctl suspend
# systemctl hibernate

The systemd daemon also can inform us of the boot timings of the different components:

marc:~> systemd-­analyze
Startup finished in 9.427s (firmware) + 9.197s (loader) + 1.361s (kernel) + 5.162s (initrd) +
23.315s (userspace) = 48.464s
marc:~> systemd­-analyze blame
11.223s home­marc­companies.mount
7.298s dmraid­activation.service
7.273s systemd­udev­settle.service
7.199s home­marc­music.mount
6.539s systemd­journal­flush.service
6.300s home­marc­vigilante.mount
marc:~> systemd­-analyze plot > /tmp/plot.svg
marc:~> systemd­-analyze critical­-chain
The time after the unit is active or started is printed after the “@” character.
The time the unit takes to start is printed after the “+” character. @23.310s
└─ multi­ @23.310s
└─ libvirtd.service @22.188s +228ms
└─ @22.084s
└─ wpa_supplicant.service @22.477s +65ms
└─ @20.898s
└─ @20.898s
└─ dbus.socket @20.898s
└─ @20.894s
└─ systemd­update­utmp.service @20.871s +21ms
└─ auditd.service @20.714s +154ms
└─ systemd­tmpfiles­setup.service @20.252s +460ms
└─ local­ @20.251s
└─ home­marc­companies.mount @9.026s +11.223s
└─ dev­mapper­vgdatax2dcompanies.device @9.022s

The first command gives us a summary of the timings it took for each of the boot phases to complete.

The second one shows us the timings of each unit.

The third one dumps a graph that we can visualise with the appropriate image viewer.

The fourth one prints a tree of the time-critical chain of units. The value after the “@” shows the time after boot the unit was ready whereas “+” shows the time it took to load it.

<< Kernel                  root password recovery >>