systemctl
systemctl
The systemctl
command is a powerful utility used to control the systemd
system and service manager. systemd
is widely adopted as the standard init system in many Linux distributions, providing a consistent and centralized way to manage services, processes, and system states.
Basic Syntax
The basic syntax for the systemctl
command is:
systemctl [OPTIONS] COMMAND [SERVICE]
OPTIONS: Optional flags to modify the behavior of the
systemctl
command.COMMAND: The action you want to perform, such as start, stop, restart, enable, disable, status, etc.
SERVICE: The name of the service you want to manage (e.g.,
sshd
,nginx
,httpd
).
Common Commands
Start a Service
To start a service:
sudo systemctl start SERVICE_NAME
Example:
sudo systemctl start sshd
Stop a Service
To stop a service:
sudo systemctl stop SERVICE_NAME
Example:
sudo systemctl stop sshd
Restart a Service
To restart a service:
sudo systemctl restart SERVICE_NAME
Example:
sudo systemctl restart sshd
Reload a Service
To reload the configuration of a service without stopping it:
sudo systemctl reload SERVICE_NAME
Example:
sudo systemctl reload sshd
Enable a Service
To enable a service to start automatically at boot:
sudo systemctl enable SERVICE_NAME
Example:
sudo systemctl enable sshd
Disable a Service
To disable a service from starting automatically at boot:
sudo systemctl disable SERVICE_NAME
Example:
sudo systemctl disable sshd
Check Status of a Service
To check the status of a service:
sudo systemctl status SERVICE_NAME
Example:
sudo systemctl status sshd
View Service Logs
To view logs for a specific service using journalctl
:
sudo journalctl -u SERVICE_NAME
Example:
sudo journalctl -u sshd
Managing System State
Reboot the System
To reboot the system:
sudo systemctl reboot
Shut Down the System
To power off the system:
sudo systemctl poweroff
Halt the System
To halt the system without powering off:
sudo systemctl halt
Suspend the System
To suspend the system (sleep mode):
sudo systemctl suspend
Hibernate the System
To hibernate the system:
sudo systemctl hibernate
Hybrid Sleep
To put the system into hybrid sleep (combination of suspend and hibernate):
sudo systemctl hybrid-sleep
Managing Units
systemctl
can manage various types of units, not just services. Units include services (.service
), mount points (.mount
), devices (.device
), sockets (.socket
), timers (.timer
), and targets (.target
).
List All Units
To list all units:
systemctl list-units
List All Unit Files
To list all unit files (including those not currently active):
systemctl list-unit-files
Targets
Targets are used to group units and define system states. They are similar to runlevels in traditional init systems.
Change Default Target
To change the default target (runlevel equivalent):
sudo systemctl set-default TARGET_NAME
Example (set to graphical target):
sudo systemctl set-default graphical.target
Isolate a Target
To switch to a specific target (changes system state):
sudo systemctl isolate TARGET_NAME
Example (switch to multi-user target):
sudo systemctl isolate multi-user.target
Benefits and Drawbacks of systemctl
systemctl
Benefits
Powerful and Flexible: Comprehensive management of services and system states.
Widely Supported: Adopted by most major Linux distributions.
Unified Interface: Consistent and centralized control over system services and states.
Enhanced Features: Supports parallel service startup, socket activation, and more.
Drawbacks
Complexity: Can be difficult to use for those unfamiliar with
systemd
.Troubleshooting: Issues with
systemctl
can be challenging to debug.Learning Curve: Requires learning new concepts and commands if transitioning from traditional init systems.
Conclusion
The systemctl
command is an essential tool for managing services and system states on modern Linux distributions. While it offers significant power and flexibility, it can be complex for new users. Familiarity with basic commands and concepts is crucial for effective system administration.
help
Last updated