![]() | Red Hat Certified System Administration 8 |
Chapter 11: Working with SystemdGoal
• Control and monitor network services and system daemons using systemd. SommaireSystemdsystemdSystem startup and server processes are managed by the systemd System and Service Manager.Daemons are processes that wait or run in the background performing various tasks. Generally, daemons start automatically at boot time and continue to run until shutdown or until they are manually stopped. By convention, the names of many daemon programs end in the letter "d". To listen for connections, a daemon uses a socket. This is the primary communication channel with local or remote clients. A bit of historyFor many years, process ID1 of Linux and UNIX systems has been the init process.This process Was responsible for activating other services on the system and is the origin of the term "init system." Frequently used daemons were started on systems at boot time with SystemV and LSB init scripts. These are shell scripts, and may vary from one distribution to another. Less frequently used daemons were started on demand by another service, such as initd or xinetd, which listens for client connections. These systems have sever all imitations, which are addressed with systemd. In Red Hat Enterprise Linux 7, process ID1 is systemd, the new init system. A few of the new Features provided by system include: •Parallelization capabilities, which increase the boot speed of a system. •On-demand starting of daemons without requiring a separate service. •Automatic service dependency management, which can prevent long timeouts, such as by not Starting a network service when the network is not available. •A method of tracking related processes together by using Linux control groups. RunlevelsRunlevelsEach runlevel also has a directory called /etc/rc.d/rc#.d, where # is the runlevel (from 0 to 6). These different directories contain scripts to tell the system which services should be started or stopped at the particular runlevel. Commands[root@redhat ~]# init runlevel restart system in a runlevel[root@redhat ~]# runlevel show current runlevel [root@redhat ~]# who -r show current runlevel running levels0 Halt1 Single-user mode 2 Multiuser with partial services 3 Full multiuser with networking (text mode) 4 Not used 5 Full multiuser graphical mode (provides a GUI desktop login) 6 Reboot ServicesServicesUsual Services Listhttpd web serverfirewalld firewall NetworkManager.service Networking vsftpd ftp service mysqld Mysql server sshd SSH server Systemd UnitsSystemd UnitsThe systemctl command is used to manage different types of system objects, called units.A list of available unit types can be displayed with [root@redhat ~]# systemctl -t help.
Socket units have a .socket extension Path units have a .path extension Probably the most important unit type is the service unit. It is used to start processes. You can start any type of process by using a service unit, including daemon processes and commands. Understanding Systemd Unit LocationsThe major benefit of working with Systemd, as compared to previous methods Red Hat used for managing services, is that it provides a uniform interface to start units. This interface is defined in the unit file. Unit files can occur in three locations: • /usr/lib/systemd/system contains default unit files that have been installed from RPM packages. You should never edit these files directly. • /etc/systemd/system contains custom unit files. It may also contain files that have been written by an administrator or generated by the systemctl edit command. • /run/systemd/system contains unit files that have automatically been generated. If a unit file exists in more than one of these locations, units in the /run directory have highest precedence and will overwrite any settings that were defined elsewhere. Units in /etc/systemd/system have second highest precedence, and units in /usr/lib/systemd/system come last. Systemctlsystemctl Toolsystemctl is the tool used by Systemd to manage UnitsSyntaxService states
Enable or Disable a serviceMake enable state for a service configure that service to boot at OS Boot time. It will be done byThis command make a symbolic link of Service Unit File in /etc/systemd/system/multi-user.target.wants/ directory Commands[root@redhat ~]# systemctl list-units --type service --state active Active Services List Masking ServicesAt times, a system may have conflicting services installed. For example, there are multiple methods to manage networks(network and Network Manager) and firewalls (iptables and firewalld). To prevent an administrator from accidentally starting a service, that service may be masked. Masking will create a link in the configuration directories so that if the service is started, nothing will happen. NB: ■ A disabled service will not be started automatically at boot or by other unit files, but can be started manually. ■ A masked service cannot be started manually or automatically. Example Power Management Commands with systemctl |