The systemd
service doesn't use runlevels as SysV or Upstart do. The alternatives for systemd
are called targets. Their purpose is to group a set of systemd
units (not only services, but also sockets, devices, and so on) through a chain of dependencies.
Managing targets with systemd
is pretty simple, as shown through the following steps:
~]# systemctl list-unit-files --type target UNIT FILE STATE anaconda.target static basic.target static bluetooth.target static cryptsetup.target static ctrl-alt-del.target disabled default.target enabled ... sysinit.target static system-update.target static time-sync.target static timers.target static umount.target static 58 unit files listed. ~]#
This list shows all target units available followed by information regarding whether the target is enabled or not.
The systemd
targets can be chained unlike SysV runlevels, so you'll not only see one target but a whole bunch of them, as follows:
~]# systemctl list-units --type target UNIT LOAD ACTIVE SUB DESCRIPTION basic.target loaded active active Basic System cryptsetup.target loaded active active Encrypted Volumes getty.target loaded active active Login Prompts local-fs-pre.target loaded active active Local File Systems (Pre) local-fs.target loaded active active Local File Systems multi-user.target loaded active active Multi-User System network-online.target loaded active active Network is Online network.target loaded active active Network nfs-client.target loaded active active NFS client services paths.target loaded active active Paths remote-fs-pre.target loaded active active Remote File Systems (Pre) remote-fs.target loaded active active Remote File Systems slices.target loaded active active Slices sockets.target loaded active active Sockets swap.target loaded active active Swap sysinit.target loaded active active System Initialization time-sync.target loaded active active System Time Synchronized timers.target loaded active active Timers LOAD = 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. 18 loaded units listed. Pass --all to see loaded but inactive units, too. To show all installed unit files use 'systemctl list-unit-files'. ~]#
systemd
target by running the following commands:~]# systemctl set-default graphical.target rm '/etc/systemd/system/default.target' ln -s '/usr/lib/systemd/system/graphical.target' '/etc/systemd/system/default.target' ~]#
Sometimes, you want to change targets on the fly as you would in the past with runlevel or telinit. With systemd
, this is accomplished in the following way:
~]# systemctl isolate <target name>
Here's an example:
~]# systemctl isolate graphical.target
Let's take an overview of the former runlevels versus the systemd
targets in the following table:
Runlevel |
Target units |
Description |
---|---|---|
|
|
This is used to shut down and power off the system |
|
|
This is used to enter a rescue shell |
|
|
This is used to set up a command-line multiuser system |
|
|
This is used to set up a command-line multiuser system |
|
|
This is used to set up a command-line multiuser system |
|
|
This is used to set up a graphical multiuser system |
|
|
This is used to reboot the system |
For more in-depth information about RHEL 7 and systemd
targets, refer to the following link: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Managing_Services_with_systemd-Targets.html