Chapter 6 Flashcards
(24 cards)
Maintaining System
Startup and Services
A service, or daemon, is a program that
performs a particular duty.
Looking at init
This program can be located in the /etc/, the /bin/, or the /sbin/ directory.
Also, it typically has a process ID (PID) of 1.
Finding the init program file location
# which init /sbin/init #
Checking the init program for links
# readlink -f /sbin/init /usr/lib/systemd/systemd #
Checking PID 1
ps -p 1
PID TTY TIME CMD
1 ? 00:00:06 systemd
#
Managing systemd Systems
Services can now be started when the system boots, when a particular hardware
component is attached to the system, when certain other services are started, and so on.
Exploring Unit Files
There are currently 12 different systemd unit types, as follows: ■ automount ■ device ■ mount ■ path ■ scope ■ service ■ slice ■ snapshot ■ socket ■ swap ■ target ■ timer
systemctl utility is the main gateway to managing systemd and system services
systemctl [OPTIONS…] COMMAND [NAME…]
Looking at systemd units
$ systemctl list-units
UNIT LOAD ACTIVE SUB DESCRIPTION
[…]
smartd.service loaded active running Self Monitor[…]
sshd.service loaded active running OpenSSH serv[…]
sysstat.service loaded active exited Resets Syste[…]
[…]
graphical.target loaded active active Graphical I[…]
[…]
$
Groups of services are started via target unit fi les. At system startup, the default
.target unit is responsible for ensuring that all required and desired services are launched
at system initialization.
Looking at the default.target link $ find / -name default.target 2>/dev/null /etc/systemd/system/default.target [...] $ $ readlink -f /etc/systemd/system/default.target /usr/lib/systemd/system/graphical.target $ $ systemctl get-default graphical.target $
Commonly used system boot target unit files
Name Description
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.
runlevel n .target Provides backward compatibility to
SysV init systems, where n is set to 1–
5 for the desired SysV runlevel
equivalence.
Focusing on Service Unit Files
The following list shows the directory locations in ascending priority order:
- /etc/systemd/system/
- /run/systemd/system/
- /usr/lib/systemd/system/
Looking at systemd unit files
$ systemctl list-unit-files UNIT FILE STATE [...] dev-hugepages.mount static dev-mqueue.mount static
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 started.
To see what directory or directories store a particular systemd unit file(s), use the systemctl utility
Finding and displaying a systemd unit file $ systemctl cat ntpd.service # /usr/lib/systemd/system/ntpd.service [Unit] Description=Network Time Service After=syslog.target ntpdate.service sntp.service [Service] Type=forking EnvironmentFile=-/etc/sysconfig/ntpd ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS PrivateTmp=true [Install] WantedBy=multi-user.target $
For service unit fi les, there are three primary confi guration sections. They are as follows:
■ [Unit]
■ [Service]
■ [Install]
A directive is a setting that modifi es a confi guration,
Commonly used service unit file [Unit] section directives
After Before Description Documentation Conflicts Requires Wants
The [Service] directives within a unit file set configuration items, which are specific to that service.
Commonly used service unit file [Service] section directives
ExecReload ExecStart ExecStop Environment Environment File RemainAfterExit Restart Type
The [Service] Type directive needs a little more explanation
forking
simple
oneshot
idle
Environment directive
Linux systems use a feature called environment variables to store information about the shell session and working environment
Viewing a service unit file’s Environment directive
$ echo $PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:[…]
$
$ systemctl ––no-pager cat anaconda.service
# /usr/lib/systemd/system/anaconda.service
[Unit]
Description=Anaconda
[…]
[Service]
Type=forking
Environment=HOME=/root MALLOC_CHECK_=2 MALLOC_PERTURB_=204 PATH=/usr/bin:
/bin:/sbin:/usr/sbin:/mnt/sysimage/bin: […]
LANG=en_US.UTF-8 […]
[…]
$
The [Install] directives within a unit file determine what happens to a particular service if it is enabled or disabled.
Alias
Also
RequiredBy
WantedBy
Focusing on Target Unit Files
The primary purpose of target unit files is to group together various services to start at system boot time
Finding and displaying the systemd target unit file
$ systemctl get-default graphical.target $ $ systemctl cat graphical.target # /usr/lib/systemd/system/graphical.target [...] [Unit] Description=Graphical Interface Documentation=man:systemd.special(7) Requires=multi-user.target Wants=display-manager.service Conflicts=rescue.service rescue.target After=multi-user.target rescue.service rescue.target display-manager.service AllowIsolate=yes $