RHCSA (9): Starting Up Services
Alphabetical List of the Abbreviations used in this article:
GNU = GNU's Not Unix
HTTPD = Hypertext Transfer Protocol Daemon
LLM = Large Language Model
PID = Process Identifier
RHEL = Red Hat Enterprise Linux
RHCSA = Red Hat Certified System Administrator
SSH = Secure Shell
SysV = System V
URL = Uniform Resource Locator
How I Used Reference 1 in This Article:
Reference 1 cited many features that make up GNU/Linux and other computer operating systems. The eighth of these features is "starting up services". This eighth feature will be the 100% focus of this article.
Executive Summary
An RHCSA (Red Hat Certified System Administrator) must understand how to manage and start services on a GNU/Linux system using several critical tools and techniques. The primary utility is systemd, which has become the default init system and service manager for most modern GNU/Linux distributions, including Red Hat and CentOS. Systemd replaces older systems such as SysVinit and Upstart. It allows administrators to start, stop, restart, and check the status of services using straightforward commands like systemctl start, stop, restart, status, enable, and disable. These commands control whether services are actively running and whether they will automatically start at boot time.
Although systemd is now the standard, chkconfig remains available for backward compatibility. It can still be used to manage services that are linked between traditional SysV-style scripts in /etc/init.d and systemd unit files. This utility ensures that administrators can support legacy configurations while working with newer service management frameworks.
Another helpful tool is xargs, which enables administrators to construct and execute command lines from input data. This is particularly useful for performing batch operations, such as starting multiple services with a single command or processing large sets of service configurations efficiently.
A Python script can combine these concepts by using the subprocess module to run systemd commands and analyze the output. The script gathers information about currently running services and those enabled at boot. It prints lists of active services and services set to start automatically, helping administrators quickly assess system status. This script exemplifies how system administration tasks can be automated to improve efficiency and oversight.
Credits
The folllowing research assistants were invaluable tools that allowed me to complete this article in a timely manner: Mistral (an open-source local large language model - LLM) and ChatGPT (an online portal to OpenAI's remote LLMs).
Managing GNU/Linux Services with Systemd
Managing services with `systemd` is a core competency for any RHCSA (Red Hat Certified System Administrator). `Systemd` is the default init system and service manager in Red Hat Enterprise Linux (RHEL) and most modern GNU/Linux distributions. It is responsible for initializing the system during boot, managing system processes, and controlling service behavior. Understanding `systemd` is critical for ensuring that a GNU/Linux system boots correctly, operates reliably, and responds appropriately to changes in system state or administrative commands.
At the heart of `systemd` is the concept of units. The most common type of unit for RHCSA purposes is the `service` unit, which defines how a background service is started, stopped, and maintained. Services like `sshd`, `httpd`, and `firewalld` are all managed as `systemd` units. Each unit has a configuration file, typically stored in `/usr/lib/systemd/system` or `/etc/systemd/system`, which describes its behavior and dependencies. Administrators interact with these units primarily through the `systemctl` command, which allows services to be started, stopped, reloaded, restarted, enabled, disabled, masked, and more.
An RHCSA should know how to use `systemctl` to view the current status of a service using `systemctl status servicename`, which provides detailed information including the service's current state, recent log messages, and process ID. To control whether a service runs at boot, `systemctl enable servicename` adds it to the system's list of startup services, while `systemctl disable servicename` removes it. To start or stop services immediately, the administrator uses `systemctl start servicename` or `systemctl stop servicename`. Restarting a service with `systemctl restart servicename` is useful when applying new configurations, and reloading with `systemctl reload servicename` is used if the service supports reloading without a full restart.
RHCSAs must also be able to check which services are currently running and which are enabled to start at boot. The `systemctl list-units --type=service` command shows all active services, while `systemctl list-unit-files --type=service` reveals all installed services and their boot-time status. Understanding the distinction between active, inactive, enabled, disabled, and failed services is vital for troubleshooting and system optimization.
Masking a service with `systemctl mask servicename` prevents it from being started manually or automatically, which is useful when a service should be permanently disabled. To reverse this action, `systemctl unmask servicename` is used. RHCSAs should also be familiar with `journalctl`, the `systemd`-integrated logging tool, which allows them to view logs generated by `systemd` and services under its control. Commands like `journalctl -u servicename` show logs specific to a given service, which aids in troubleshooting and system auditing.
`Systemd` also supports the concept of targets, which are groups of units that define system states such as `multi-user.target` or `graphical.target`. Targets replace the older concept of runlevels and are important when configuring how the system behaves at different stages of boot or shutdown. For instance, a system booting into a server environment might use `multi-user.target`, while a desktop system might default to `graphical.target`.
In summary, managing services with `systemd` involves understanding unit files, mastering `systemctl` commands, interpreting service status and logs, configuring boot-time behavior, and ensuring the system operates smoothly during startup and runtime. These skills are fundamental to the RHCSA role and must be practiced regularly to maintain a secure, efficient, and reliable GNU/Linux environment.
Using Chkconfig on GNU/Linux for Backwards Compatibility
Using `chkconfig` on GNU/Linux is important for maintaining backward compatibility with older service management frameworks, especially in environments where legacy applications or scripts still rely on SysV-style init systems. Although `systemd` has become the standard service manager in Red Hat Enterprise Linux (RHEL) and most modern GNU/Linux distributions, `chkconfig` remains available to support services that were originally managed under the older SysVinit system.
The `chkconfig` tool manages symbolic links in `/etc/rc.d` that determine whether a SysV-style service starts at a specific runlevel. When a system boots, these runlevels control which services are started. While `systemd` uses targets instead of runlevels, many services still include legacy init scripts in `/etc/init.d`, and `chkconfig` can be used to configure their startup behavior in a familiar way. This is especially useful on systems that must support software not yet updated for `systemd`.
To view which services are currently configured to start at various runlevels, an RHCSA can use the `chkconfig --list` command. To enable a service at boot time, one would use `chkconfig servicename on`, and to disable it, `chkconfig servicename off`. These commands update the symbolic links that define the service’s behavior. The `chkconfig` tool ensures that administrators can easily manage older services without manually editing these symbolic links, which reduces the chance of errors and simplifies service control.
Another useful function of `chkconfig` is its ability to add a new service to the startup system, provided the corresponding init script contains the proper metadata comments that define its runlevel behavior. Without these headers, `chkconfig` cannot properly integrate the script into the system’s boot process. RHCSAs should understand the structure of these headers and how they inform the system about which runlevels the service should run in by default.
In modern GNU/Linux systems, `chkconfig` often acts as a compatibility wrapper that interacts with `systemd` behind the scenes. However, it remains a valuable tool for transitional environments and for administrators who need to maintain legacy services or understand systems that predate the `systemd` adoption. For the RHCSA, proficiency with both `chkconfig` and `systemd` ensures broad service management capabilities across a range of GNU/Linux system versions.
Using Xargs in GNU/Linux
Using `xargs` in GNU/Linux is a powerful way to build and execute command lines from standard input, making it an essential tool for RHCSAs who need to perform bulk operations efficiently. While many commands generate lists of files, directories, or other output, they often do not execute further actions on that output directly. This is where `xargs` becomes valuable. It takes input from another command, formats it as arguments, and applies it to a specified command.
For example, when paired with `find`, `xargs` can perform operations on a large number of files without hitting command length limits or requiring complex scripting. A typical example would be `find /var/log -type f | xargs rm`, which deletes all regular files under `/var/log`. This is more efficient and often more reliable than using command substitution or loops in shell scripts, especially when dealing with very long lists of files or complex directory structures.
`Xargs` is also useful when combined with `grep`, `chmod`, `chown`, `cp`, and other administrative commands. It allows RHCSAs to apply actions to groups of files or services in a single, readable command line. For instance, `cat servicelist.txt | xargs systemctl restart` would restart every service listed in the `servicelist.txt` file. This approach helps automate tasks across many services without writing a full shell script.
One of the key benefits of `xargs` is that it processes input incrementally, meaning it can handle input streams more gracefully than some alternatives. RHCSAs should also be aware of the `-n` and `-p` options. The `-n` option controls how many arguments are passed per command execution, which can improve safety or performance, while `-p` prompts the user before each command runs, offering an additional layer of control.
In environments where file names or input strings may contain spaces or special characters, it is important to use `-0` with `xargs`, which expects null-terminated input. This is typically paired with `find -print0` to safely process such inputs. For example, `find . -type f -print0 | xargs -0 rm` avoids accidental deletion due to malformed or unexpected file names.
Mastering `xargs` enables RHCSAs to streamline repetitive tasks, reduce the complexity of administrative scripts, and handle large volumes of input in a stable and consistent manner. It exemplifies the GNU/Linux philosophy of building powerful tools that work well together through the use of standard input and output.
Managing GNU/Linux Services Using Python Scripts
Managing GNU/Linux services using Python scripts allows RHCSAs to automate routine administrative tasks and interact with the system in a programmable and efficient way. While tools like `systemctl` are typically used directly from the command line, Python provides a flexible interface for wrapping and extending these commands, especially when performing repetitive or conditional service management across many systems or services.
By using the `subprocess` module in Python, administrators can execute shell commands like `systemctl status`, `systemctl list-units`, or `systemctl restart`, then capture and process the output. This enables the creation of custom tools that not only run these commands but also interpret the results. For instance, a Python script can list all currently active services, extract service names from the output, and present them in a formatted report. It can also check which services are enabled at boot, identify failed services, or restart only the ones that are not running properly.
A common use case might involve reading a list of critical services from a file and ensuring that each one is active. A script can loop through the list, run `systemctl is-active servicename` for each entry, and restart any services that are found to be inactive. This approach reduces human error, speeds up system checks, and allows administrators to run consistent procedures across multiple servers.
Python scripts can also support logging and conditional logic, such as sending alerts or writing service status to a file if a problem is detected. When combined with scheduled tasks like `cron`, these scripts can form the backbone of a lightweight monitoring or maintenance system. For example, a scheduled Python script could ensure that web and database services are running and automatically attempt recovery if they are not.
Because GNU/Linux treats everything as text and makes extensive use of standard input and output, Python is a natural fit for managing services on the platform. It allows RHCSAs to move beyond manual command entry and build tailored, automated solutions that improve reliability and consistency. Developing fluency in this approach helps administrators respond to real-world scenarios with practical and scalable tools.
Conclusions
This concludes Article 9 of my RHCSA series. We discussed many aspects of starting up services on GNU/Linux computer systems:
- Managing services with `systemd` is a core competency for any RHCSA (Red Hat Certified System Administrator). `Systemd` is the default init system and service manager in Red Hat Enterprise Linux (RHEL) and most modern GNU/Linux distributions.
- Using `chkconfig` on GNU/Linux is important for maintaining backward compatibility with older service management frameworks, especially in environments where legacy applications or scripts still rely on SysV-style init systems. Although `systemd` has become the standard service manager in Red Hat Enterprise Linux (RHEL) and most modern GNU/Linux distributions, `chkconfig` remains available to support services that were originally managed under the older SysVinit system.
- Using `xargs` in GNU/Linux is a powerful way to build and execute command lines from standard input, making it an essential tool for RHCSAs who need to perform bulk operations efficiently.
- Managing GNU/Linux services using Python scripts allows RHCSAs to automate routine administrative tasks and interact with the system in a programmable and efficient way.
References:
[1] 2020 - Lecture - CSCI 275: Linux Systems Administration and Security - Moe Hassan - CUNY John Jay College - NYC Tech-in-Residence Corps. Retrieved June 26, 2025 from https://academicworks.cuny.edu/cgi/viewcontent.cgi?article=1053&context=jj_oers