Chapter 6 - Maintaining System Startup and Services

¡Supera tus tareas y exámenes ahora con Quizwiz!

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

Summarize systemd unit concepts

A systemd unit defines a service, a group of services, or an action, and 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

Commonly used service unit file [Unit] section directives:

Directive Description After Sets this unit to start after the designated units. Before Sets this unit to start before the designated units. Description Describes the unit. Documentation Sets a list of Uniform Resource Identifiers (URIs) that point to documentation sources. The URIs can be web locations, particular system files, info pages, and man pages. Conflicts Sets this unit to not start with the designated units. If any of the designated units start, this unit is not started. (Opposite of Requires.) Requires Sets this unit to start together with the designated units. If any of the designated units do not start, this unit is not started. (Opposite of Conflicts.) Wants Sets this unit to start together with the designated units. If any of the designated units do not start, this unit is still started.

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.

For setting environment parameters within a unit configuration file, which directives should you potentially employ? Choose all that apply.

Environment EnvironmentFile

Commonly used service unit file [Service] section directives

ExecReload Indicates scripts or commands (and options) to run when unit is reloaded. ExecStart Indicates scripts or commands (and options) to run when unit is started. ExecStop Indicates scripts or commands (and options) to run when unit is stopped. Environment Sets environment variable substitutes, separated by a space. Environment File Indicates a file that contains environment variable substitutes. RemainAfterExit Set to either no (default) or yes. If set to yes, the service is left active even when the process started by ExecStart terminates. If set to no, then ExecStop is called when the process started by ExecStart terminates. Restart Service is restarted when the process started by ExecStart terminates. Ignored if a systemctl restart or systemctl stop command is issued. Set to no (default), on-success, on-failure, on-abnormal, on-watchdog, on-abort, or always. Type Sets the startup type.

To configure various services to start at different runlevels, there are two different commands you can use. The one you employ depends upon which distribution you are using.

For Red Hat-based distros using SysV init, you'll want to use the chkconfig utility. For Debian-based Linux distributions using SysV init, the update-rc.d program is the one to use.

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?

For starting Service-B immediately before starting Service-A, the Service-A unit configuration file will need to employ the After directive, set it similar to something like: After=Service-B.unit. Therefore, option E is the correct answer.

The systemd initialization

Started around 2010, it is now the most popular system service initialization and management mechanism. This daemon reduces initialization time by starting services in a parallel manner.

Your systemd system is taking a long time to boot and you need to reduce the boot time. Which systemd-analyze command is the best to start narrowing down which units need to be investigated first?

The blame command displays the amount of time each running unit took to initialize, and the units and their times are listed starting from the slowest to the fastest. That way, you can start investigating the units at the list's top. Therefore,

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 upon 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.

Which directory on an old SysV init system stores the service startup scripts?

The directory that stores the service startup scripts for an old (and a new) SysV init system is the /etc/init.d/ directory

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 and systemctl 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.

Occasionally you may need to change a particular unit configuration file for your Linux system's requirements or add additional components. However, be careful when doing this task. You should not modify any unit files in the /lib/systemd/system/ or /usr/lib/systemd/system/ directory.

To modify a unit configuration file, copy the file to the /etc/systemd/system/ directory and modify it there. This modified file will take precedence over the original unit file left in the original directory. Also, it will protect the modified unit file from software updates.

Rescue Target

When you jump your system to the rescue target, the system mounts all the local filesystems, only the root user is allowed to log into the system, networking services are turned off, and only a few other services are started. The systemctl is-system-running command will return the maintenance status. Running disk utilities to fix corrupted disks is a useful task in this particular target.

Emergency Target

When your system goes into emergency mode, the system only mounts the root filesystem, and it mounts it as read-only. Similar to rescue mode, it only allows the root user to log into the system, networking services are turned off, and only a few other services are started. The systemctl is-system-running command will return the maintenance status. If your system goes into emergency mode by itself, there are serious problems. This target is used for situations where even rescue mode cannot be reached.

You are managing a systemd system and need to create an automount unit file. Which of the following directives should you review to possibly include in this file's [Automount] section? (Choose all that apply.)

Where DirectoryMode TimeOutIdleSec

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 commands. Services can have their status checked; have their configuration files be reloaded; or be stopped, started, or restarted via the status command. You can view all currently loaded services on a SysV init system via the service --status-all command. Services are enabled or disabled via either the chkconfig or the update-rc.d command, depending upon your distribution.

For service unit files, there are three primary configuration sections. They are as follows:

[Unit] [Service] [Install]

There are currently 12 different systemd unit types, as follows:

automount device mount path scope service slice snapshot socket swap target timer

Their states are called enablement states and refer to when the service is started. There are at least 12 different enablement states, but you'll commonly see these three:

enabled: Service starts at system boot. disabled: Service does not start at system boot. static: Service starts if another unit depends on it. Can also be manually

Other useful systemctl utility commands deal with obtaining, setting, and jumping the system's target. They are as follows:

et-default set-default isolate

You need to modify a systemd service unit configuration. Where should the modified file be located?

etc/systemd/system/

This directive can be set to at least six different specifications, of which the most typical are listed here:

forking: ExecStart starts a parent process. The parent process creates the service's main process as a child process and exits. simple: (Default) ExecStart starts the service's main process. oneshot: ExecStart starts the service's main process, which is typically a configuration setting or a quick command, and the process exits. idle: ExecStart starts the service's main process, but it waits until all other start jobs are finished.

Commonly used system boot target unit files

graphical.target Provides multiple users access to the system via local terminals and/or through the network. Graphical user interface (GUI) access is offered. multi-user.target Provides multiple users access to the system via local terminals and/or through the network. No GUI access is offered. runleveln.target Provides backward compatibility to SysV init systems, where n is set to 1-5 for the desired SysV runlevel equivalence.

the default.target unit

is responsible for ensuring that all required and desired services are launched at system initialization. It is set up as a symbolic link to another target unit file

Convenient systemctl service status commands

is-active Displays active for running services and failed for any service that has reached a failed state. is-enabled Displays enabled for any service that is configured to start at system boot and disabled for any service that is not configured to start at system boot. is-failed Displays failed for any service that has reached a failed state and active for running services.

Operational statuses provided by systemctl is-system-running

running System is fully in working order. degraded System has one or more failed units. maintenance System is in emergency or recovery mode. initializing System is starting to boot. starting System is still booting. stopping System is starting to shut down.

A customer has complained that a service on your SysV init system is not working. Which of the following commands is the best command to use to check the service?

service status

The isolate command is handy for jumping between system targets. When this command is used along with a target name for an argument

systemctl isolate multi-user.target

Which of the following would be the appropriate base name for a mount unit file that mounts a filesystem at the /var/log/ mount point?

var-log.mount

The SysV init (SysV)

was based on the Unix System V initialization daemon. While it's not used by many major Linux distributions anymore, you still may find it lurking around that older Linux server at your company.

The init program may be located in which of the following directories? (Choose all that apply.)

/etc/ /sbin/ /bin/

You've recently become the system administrator for an older Linux server, which still uses SysV init. You determine that its default runlevel is 3. What file did you find that information in?

/etc/inittab

Red Hat-based distribution SysV init runlevels

0 Shut down the system. 1, s, or S Single user mode used for system maintenance. 2 Multi-user mode without networking services enabled. 3 Multi-user mode with networking services enabled. 4 Custom. 5 Multi-user mode with GUI available. 6 Reboot the system.

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 file names are based upon 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.

Your older Debian-based Linux distribution system uses SysV init. It soon is going to be upgraded to a Debian-based distro that uses systemd. To start some analysis, you enter the runlevel command. Which of the following are results you may see? (Choose all that apply.)

N 2 1 2

A handy systemd component is the systemd-analyze utility. With this utility, you can investigate your system's boot performance and check for potential system initialization problems.

blame Displays the amount of time each running unit took to initialize. Units and their times are listed starting from the slowest to the fastest. time Displays the amount of time system initialization spent for the kernel, and the initial RAM filesystem, as well as the time it took for normal system user space to initialize. (Default) critical-chain Displays time-critical units in a tree format. Can pass it a unit file argument to focus the information on that particular unit. dump Displays information concerning all the units. The display format is subject to change without notice, so it should be used only for human viewing. verify Scans unit files and displays warning messages if any errors are found. Will accept a unit file name as an argument, but follows directory location precedence.

You need to enable the DHCP service on your Red Hat-based SysV init system for runlevels 3 and 5. Which of the following commands should you use?

chkconfig --levels 35 dhcp on

Service unit files

contain information, such as which environment file to use, when a service must be started, what targets want this service started, and so on. These configuration files are located in different directories.

Commonly used systemctl service management commands

daemon-reload Load the unit configuration file of the running designated unit(s) to make unit file configuration changes without stopping the service. Note that this is different from the reload command. disable Mark the designated unit(s) to not be started automatically at system boot time. enable Mark the designated unit(s) to be started automatically at system boot time. mask Prevent the designated unit(s) from starting. The service cannot be started using the start command or at system boot. Use the --now option to immediately stop any running instances as well. Use the --running option to mask the service only until the next reboot or unmask is used. restart Stop and immediately restart the designated unit(s). If a designated unit is not already started, this will simply start it. start Start the designated unit(s). status Display the designated unit's current status. stop Stop the designated unit(s). reload Load the service configuration file of the running designated unit(s) to make service configuration changes without stopping the service. Note that this is different from the daemon-reload command. unmask Undo the effects of the mask command on the designated unit(s).

The initialization daemon (init)

determines which services are started and in what order. This daemon also allows you to stop and manage the various system services.

Commonly used service utility commands

restart Stop and immediately restart the designated service. Note that if a designated service is not already started, a FAILED status will be generated on the stop attempt, and then the service will be started. start Start the designated service. status Display the designated service's current status. stop Stop the designated service. Note if a designated service is already stopped, a FAILED status will be generated on the stop attempt. reload Load the service configuration file of the running designated service. This allows you to make service configuration changes without stopping the service. Note that if you attempt the reload command on a stopped service, a FAILED status will be generated.

You are managing a SysV init system and need to perform some emergency maintenance at runlevel 1. To do this, you need to jump runlevels. What command could you employ? (Choose all that apply.)

telinit S telinit 1 init s init 1

You need to enable the DHCP service on your Debian-based SysV init system for the default runlevels. Which of the following commands should you use?

update-rc.d dhcp defaults


Conjuntos de estudio relacionados

20th Century Music History Test 3

View Set

Chapter 10 Section 4: The Members of Congress

View Set

Post Traumatic Stress Disorder (PTSD)- Final

View Set

CompTIA A+ Core 2 Lesson 8 Quiz - Managing Security Settings

View Set

Project Management Chapter 4 SB & Quiz

View Set

English Antigone Study Guide (know who said quotes)

View Set

Practice Test Assessment Performance

View Set

CFA 16: The Firm & Market Structures

View Set

Exam 1 Review Management & Labor Relations

View Set