systemctl
systemctl
is a command-line utility used to interact with systemd
, the init system and service manager used by many Linux distributions. systemctl
provides a comprehensive interface for managing services, inspecting the state of the system, and controlling system behavior.
Overview of systemctl
systemctl
Purpose
systemctl
is used to:
Manage system services (start, stop, restart, enable, disable).
Query and change system states.
Control system boot process.
Inspect logs and system status.
Basic Usage
The general syntax for systemctl
commands is:
[options]
: Various options to control the behavior ofsystemctl
.<command>
: The specific action to perform (e.g., start, stop, status).[name]
: The name of the service, unit, or target to act upon.
Common systemctl
Commands
systemctl
CommandsStarting and Stopping Services
Start a service:
Example:
Stop a service:
Example:
Restart a service:
Example:
Reload a service (if the service supports it):
Example:
Enabling and Disabling Services
Enable a service (start at boot):
Example:
Disable a service (do not start at boot):
Example:
Check if a service is enabled:
Example:
Checking Service Status
Get the status of a service:
Example:
Listing Services and Units
List all services:
List all units (including services, sockets, targets, etc.):
List failed units:
Managing System States
Reboot the system:
Power off the system:
Suspend the system:
Hibernate the system:
Masking and Unmasking Services
Mask a service (prevent it from starting):
Example:
Unmask a service (allow it to start):
Example:
Advanced Usage
Viewing Logs with
journalctl
View logs for a specific service:
Example:
Editing Unit Files
Edit a service unit file:
Reload systemd manager configuration after editing unit files:
Conclusion
systemctl
is an essential tool for managing and controlling services and system states on a Linux system running systemd
. It provides powerful capabilities for administrators to maintain and troubleshoot system services effectively.
Last updated