How to Use the Command `rc-status` (with examples)
The rc-status
command is a useful tool in systems that leverage the OpenRC init system for managing system services. It provides a convenient interface for administrators to view and manage the services running on a system, offering detailed insights into the status and behavior of system services across different runlevels. This article explores various use cases of the rc-status
command, illustrating how it can be employed to monitor and control system services effectively.
Use case 1: Show a Summary of Services and Their Status
Code:
rc-status
Motivation:
The most straightforward use of rc-status
is to quickly ascertain the status of services on a system. This provides a snapshot of what is active, inactive, or potentially problematic. It is especially useful for system administrators or users who need a quick overview to ensure that vital services are running as expected.
Explanation:
In this basic form, rc-status
executes without any additional options, thereby providing a summary of active and inactive services, organized by their respective runlevels. This gives the user a panoramic view of the state of their system services.
Example Output:
Runlevel: default
sshd [started ]
cron [started ]
local [stopped ]
Use case 2: Include Services in All Runlevels in the Summary
Code:
rc-status --all
Motivation:
Using rc-status --all
enhances the breadth of the information by including services from all runlevels, not just the currently active one. This is particularly beneficial when troubleshooting or auditing a system to ensure consistency and readiness across different operational states.
Explanation:
The --all
flag alters the output to include services in every runlevel configured on the system, instead of limiting to the current one. This thorough approach is valuable for complete system assessments.
Example Output:
Runlevel: boot
bootmisc [started ]
fsck [started ]
hostname [started ]
hwclock [started ]
Runlevel: default
sshd [started ]
cron [started ]
local [stopped ]
Runlevel: none
Use case 3: List Services That Have Crashed
Code:
rc-status --crashed
Motivation: Services that have unexpectedly stopped or crashed can compromise system functionality or security. Identifying these services quickly allows administrators to take corrective actions to restore them or investigate underlying issues.
Explanation:
The --crashed
option filters the list, showing only those services that have failed or crashed. This is a targeted approach to quickly identify issues without sifting through operational services.
Example Output:
crashed services:
apache2 [crashed ]
Use case 4: List Manually Started Services
Code:
rc-status --manual
Motivation: Understanding which services have been started manually, as opposed to those initiated by the system at boot, can offer insights into system modifications that deviate from standard operations. This helps in auditing changes or debugging service-related issues.
Explanation:
With the --manual
flag, rc-status
displays services that were not started automatically based on runlevel scripts but were initiated manually by users. This can help in diagnosing configurations where services should be managed via automated scripts.
Example Output:
manually started services:
custom-service [started ]
Use case 5: List Supervised Services
Code:
rc-status --supervised
Motivation: Some services are managed by supervision systems that ensure they are kept running or automatically restarted if they fail. Knowing which services are supervised helps administrators rely on their self-healing capabilities, especially for essential services.
Explanation:
The --supervised
option lists services under the management of a supervision daemon. This distinction is crucial for maintenance and reliability planning.
Example Output:
supervised services:
postgresql [supervised ]
Use case 6: Get the Current Runlevel
Code:
rc-status --runlevel
Motivation: Identifying the current runlevel is essential for understanding the operational state of a system. Different runlevels typically indicate different sets of services are active, such as multi-user mode or single-user mode for maintenance.
Explanation:
Using the --runlevel
switch, the command reveals the active runlevel, which essentially defines the type of operations that should be supported by the system at that time.
Example Output:
current runlevel: default
Use case 7: List All Runlevels
Code:
rc-status --list
Motivation: Listing all available runlevels provides an awareness of the potential operational modes of a system, facilitating understanding and configuration tuning.
Explanation:
The --list
flag outputs all runlevels defined on the system. This overview is critical for administrators developing or maintaining governance over how a system should react under various operational states.
Example Output:
available runlevels:
boot
default
nonetwork
single
Conclusion
The rc-status
command is a powerful instrument in an administrator’s toolkit, offering various functionalities to manage and monitor services effectively on an OpenRC system. From reviewing service status and runlevel configurations to diagnosing and investigating service failures, the versatility of the command enhances operational efficiency and troubleshooting capabilities.