Chapter 6 Flashcards
Maintaining System Startup and Services
Describe the init program.
- Either the init program or systemd is the parent process for every service on a Linux system. It typically has a PID of 1.
- The program is located in the
/etc/
, the/bin/
, or the/sbin/
directory. - On systemd servers, this program is a symbolic link to
/usr/lib/systemd/systemd
.
Summarize systemd unit concepts.
- A systemd unit defines a service, a group of services, or an action
- There are currently 12 different systemd unit types.
- To view load units, use the systemctl list-units command.
- The four systemd units to focus on are service, target, mount, and automount.
Explain systemd service units and their files.
- Service units control how services are started, stopped, and managed.
- Their unit files contain configuration information via directives in one of the three primary unit file sections:
[Unit]
,[Service]
, and[Install]
. - Directives, such as After and Before, configure when a service will be started. While the [Unit] and [Install] file sections are common to all unit files, the [Service] section and its directives are unique to services.
- Unit files may exist in one of three directory locations, and their location is important because if multiple files exist for a particular unit, one takes precedence over the other depending on its whereabouts.
Explain systemd target units and their files.
- Target units are responsible for starting groups of services.
- At system initialization, the default.target unit ensures that all required and desired services are launched. It is set up as a symbolic link to another target unit file.
- The primary target units used for system initialization are
graphical.target
,multi-user.target
, andrunleveln.target
, where n = 1–5 for the desired SysV init runlevel experience. - There are additional target units, which handle system power off, halt, and reboot as well as emergency and rescue modes.
- The target type unit files are similar to service unit files, but they typically contain fewer directives.
Demonstrate how to manage systemd systems via commands.
- The systemctl utility contains many commands that allow you to manage and control systemd units.
- You can jump between targets using the systemctl isolate command.
- You can set particular services to start at system boot time via the systemctl enable command and vice versa via the systemctl disable command. Additional commands allow you to start, stop, restart, and reload units as well as reload their unit files via the
systemctl daemon-reload
command. - Helpful commands such as
systemctl is-system-running
andsystemctl get-default
aid you in assessing your current systemd system. - You can employ the
systemd-analyze
series of commands to evaluate your server’s initialization process and find ways to improve it.
Summarize SysV init concepts.
- The classic SysV init method consists of the
/etc/inittab
file, which sets the default runlevel via the initdefault record. - Runlevels determine what services are started, and the default runlevel determines what services are started at system initialization. The rc script starts and stops services depending on what runlevel is chosen. It executes the scripts in the appropriate runlevel directory and passes the appropriate stop or start parameter.
- The scripts located in the various runlevel directories are symbolic links to the files within the
/etc/init.d/
directory.
Demonstrate how to manage SysV init systems via commands.
- You can determine a SysV init system’s previous and current runlevel via the runlevel command. Runlevels can be jumped into via the init or telinit command.
- Services can have their status checked; have their configuration files be reloaded; or be stopped, started, or restarted with the status command.
- You can view all currently loaded services on a SysV init system by using the service
––status-all
command. Services are enabled or disabled through either thechkconfig
or theupdate-rc.d
command, depending on your distribution
Describe systemd mount and automount unit files.
If your server employs systemd, besides managing system initialization, it can also persistently attach filesystems. These filesystems can be mounted or automounted via their associated unit files.
Mount and automount unit filenames are based on the filesystem mount point but use the .mount
or .automount
filename extension, respectively. Their unit file contents have three sections, similar to service unit files, except the mount unit file’s middle section is [Mount], whereas the automount unit file’s middle section is [Automount]. Each unit file has its own special directives that designate what partition is supposed to be mounted at the mount point and other items such as, for automount units, how long a filesystem must be idle before it can be unmounted.
The init program may be located in which of the following directories? (Choose all that apply.)
/etc/rc.d/ /etc/ /sbin/ /usr/lib/systemd/ /bin/
B, C, E. The init program may exist in the /etc/, /sbin/, or /bin/ directory, depending on your distribution and its version, so therefore options B, C, and E are correct. The /etc/rc.d/ directory is used in SysVint systems and is not a location for the init program, so option A is a wrong answer. The /etc/lib/systemd/ directory is the location of the systemd program, and thus option D is also an incorrect choice.
Which of the following is true concerning systemd service units? (Choose all that apply.)
Services can be started at system boot time. Services can be started in parallel. A service can be started based on a timer. A service can be started after all other services are started. A service can be prevented from starting at system boot time.
A, B, C, D, E. This is a tricky question, because all of these statements are true concerning systemd service units. It makes you realize that systemd-managed systems are very flexible.
Which of the following is not a systemd target unit?
runlevel7.target emergency.target graphical.target multi-user.target rescue.target
A. There is no runlevel7.target. The legitimate systemd targets, which provide backward SysV init compatibility, go from runlevel0.target through runlevel6.target. Therefore, option A is the correct answer.
The emergency.target is a special systemd target unit used to enter emergency mode. When your system goes into emergency mode, the system only mounts the root filesystem and mounts it as read-only. Therefore, option B is a systemd target unit and not a correct answer. The graphical.target is a legitimate systemd target, which provides multiple users access to the system via local terminals and/or through the network and offers a GUI. Thus, option C is an incorrect choice. The multi-user.target is also a legitimate systemd target, just like the graphical.target, except that it does not offer a GUI. Therefore, option D is also a wrong answer. The rescue.target is like emergency.target, but it mounts the root filesystem for reading and writing. Therefore, option E is an incorrect choice.
You need to modify a systemd service unit configuration. Where should the modified file be located?
/etc/system/systemd/ /usr/lib/system/systemd/ /etc/systemd/system/ /usr/lib/systemd/system/ /run/system/systemd/
C. Any modified systemd service unit configuration file should be stored in the /etc/systemd/system/ directory. This will prevent any package upgrades from overwriting it and keep the directory precedence from using the unmodified service unit copy, which may reside in the /usr/lib/systemd/system/ directory. The directories in options A and B are made up. The /usr/lib/systemd/system/ directory should only store unmodified unit files, which are provided by default, and thus option D is an incorrect answer. The /run/system/systemd/ directory is also made up.
On your server, you need Service-B to start immediately before Service-A. Within the systemd Service-A unit configuration file, what directive should you check and potentially modify?
Conflicts Wants Requires Before After
E. For starting Service-B immediately before starting Service-A, the Service-A unit configuration file will need to employ the After directive, set to something like After=Service-B.unit. Therefore, option E is the correct answer. The Conflicts directive sets the unit to not start with the designated units. If any of the designated units start, this unit is not started. Therefore, option A is a wrong answer. The Wants directive sets the unit to start together with the designated units. If any of the designated units do not start, this unit is still started. Therefore, option B is also an incorrect answer. The Requires directive sets the unit to start together with the designated units. If any of the designated units do not start, this unit is not started. Thus, option C is a wrong choice. The Before directive sets this unit to start before the designated units. While this should be set in Service-B’s unit configuration file, it does not apply, in this case, to Service-A’s configuration file. Therefore, option D is also an incorrect answer.
For setting environment parameters within a unit configuration file, which directives should you potentially employ? (Choose all that apply.)
Type Environment EnvironmentParam EnvironmentFile PATH
B, D. Linux systems use environment variables to store information about the shell session and working environment. If you need to ensure that a particular environment variable is set properly for your service, you need to use the Environment directive and/or the EnvironmentFile directive for setting environment parameters. Therefore, options B and D are correct answers.
The Type directive sets the unit startup type, which can be, for example, forking. Thus, option A is a wrong answer. The EnvironmentParam is a made-up directive. PATH is an environment variable, which you may modify for your unit’s environmental parameters. However, it is not a directive.
You attempt to jump to a systemd target using the systemctl isolate command, but it will not work. You decide to look at the target unit file. What might you see there that is causing this problem?
static AllowIsolate=yes Type=oneshot AllowIsolate=no disabled
D. If a target unit file has the AllowIsolate=no setting, the target cannot be used with the systemctl isolate command. Therefore, option D is the correct answer. Option A’s static is an enablement state displayed for a unit file via the systemctl –list-unit-files command. Thus, option A is a wrong answer. The AllowIsolate=yes directive permits the target to be used with the systemctl isolate command. Therefore, option B is also an incorrect choice. The Type=oneshot is a service unit directive, and you would not find it in a target unit file. Thus, option C is a wrong answer. Option E’s disabled is also an enablement state, like static, making option E a wrong choice as well.