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
systemctlcommand.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_NAMEExample:
sudo systemctl start sshdStop a Service
To stop a service:
sudo systemctl stop SERVICE_NAMEExample:
sudo systemctl stop sshdRestart a Service
To restart a service:
sudo systemctl restart SERVICE_NAMEExample:
sudo systemctl restart sshdReload a Service
To reload the configuration of a service without stopping it:
sudo systemctl reload SERVICE_NAMEExample:
sudo systemctl reload sshdEnable a Service
To enable a service to start automatically at boot:
sudo systemctl enable SERVICE_NAMEExample:
sudo systemctl enable sshdDisable a Service
To disable a service from starting automatically at boot:
sudo systemctl disable SERVICE_NAMEExample:
sudo systemctl disable sshdCheck Status of a Service
To check the status of a service:
sudo systemctl status SERVICE_NAMEExample:
sudo systemctl status sshdView Service Logs
To view logs for a specific service using journalctl:
sudo journalctl -u SERVICE_NAMEExample:
sudo journalctl -u sshdManaging System State
Reboot the System
To reboot the system:
sudo systemctl rebootShut Down the System
To power off the system:
sudo systemctl poweroffHalt the System
To halt the system without powering off:
sudo systemctl haltSuspend the System
To suspend the system (sleep mode):
sudo systemctl suspendHibernate the System
To hibernate the system:
sudo systemctl hibernateHybrid Sleep
To put the system into hybrid sleep (combination of suspend and hibernate):
sudo systemctl hybrid-sleepManaging 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-unitsList All Unit Files
To list all unit files (including those not currently active):
systemctl list-unit-filesTargets
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_NAMEExample (set to graphical target):
sudo systemctl set-default graphical.targetIsolate a Target
To switch to a specific target (changes system state):
sudo systemctl isolate TARGET_NAMEExample (switch to multi-user target):
sudo systemctl isolate multi-user.targetBenefits and Drawbacks of systemctl
systemctlBenefits
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
systemctlcan 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