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
systemctlPurpose
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:
systemctl [options] <command> [name][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:
systemctl start <service_name>Example:
systemctl start apache2Stop a service:
systemctl stop <service_name>Example:
systemctl stop apache2Restart a service:
systemctl restart <service_name>Example:
systemctl restart apache2Reload a service (if the service supports it):
systemctl reload <service_name>Example:
systemctl reload apache2
Enabling and Disabling Services
Enable a service (start at boot):
systemctl enable <service_name>Example:
systemctl enable apache2Disable a service (do not start at boot):
systemctl disable <service_name>Example:
systemctl disable apache2Check if a service is enabled:
systemctl is-enabled <service_name>Example:
systemctl is-enabled apache2
Checking Service Status
Get the status of a service:
systemctl status <service_name>Example:
systemctl status apache2
Listing Services and Units
List all services:
systemctl list-units --type=serviceList all units (including services, sockets, targets, etc.):
systemctl list-unitsList failed units:
systemctl --failed
Managing System States
Reboot the system:
systemctl rebootPower off the system:
systemctl poweroffSuspend the system:
systemctl suspendHibernate the system:
systemctl hibernate
Masking and Unmasking Services
Mask a service (prevent it from starting):
systemctl mask <service_name>Example:
systemctl mask apache2Unmask a service (allow it to start):
systemctl unmask <service_name>Example:
systemctl unmask apache2
Advanced Usage
Viewing Logs with
journalctlView logs for a specific service:
journalctl -u <service_name>Example:
journalctl -u apache2
Editing Unit Files
Edit a service unit file:
systemctl edit <service_name>Reload systemd manager configuration after editing unit files:
systemctl daemon-reload
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