Systemctl: Essential Commands for Service Management in Linux
If you’re using Linux, you’ve likely encountered Systemctl, a powerful tool for managing system services. It interacts with systemd, the initialization system responsible for controlling how services start, stop, and behave on your operating system.
This beginner-friendly guide will walk you through the most essential Systemctl commands, explaining them in detail and providing practical examples.
What Is Systemctl?
Systemctl is a command-line tool that allows you to manage services on your Linux system. With Systemctl, you can:
- Start, stop, enable, or disable Systemctl services.
- List active, inactive, or failed Systemctl services.
- Control which Systemctl services start automatically during boot.
Essential Systemctl Commands
1. Check the Status of a Service
This command displays detailed information about a specific service:
systemctl status service-nameExample:
systemctl status apache2You’ll see whether the service is running, its last start time, and any error messages.
2. Start a Service
To start a service manually:
systemctl start service-nameExample:
systemctl start apache23. Stop a Service
To stop a running service:
systemctl stop service-nameExample:
systemctl stop apache24. Restart a Service
To restart a service:
systemctl restart service-nameExample:
systemctl restart apache25. Enable a Service to Start on Boot
Ensure a service starts automatically when your system boots:
systemctl enable service-nameExample:
systemctl enable apache26. Disable a Service from Starting on Boot
To prevent a service from starting automatically:
systemctl disable service-nameExample:
systemctl disable apache27. List Active Services
To see all currently active services:
systemctl list-units --type=service --state=active8. List All Services
For a complete list of all services, regardless of their state:
systemctl list-units --type=service9. Check Disabled Services
View services that are not set to start on boot:
systemctl list-unit-files --state=disabled10. Check Failed Services
If something is not working, this command lists services that have failed:
systemctl list-units --type=service --state=failed11. Reload a Service Configuration
If you’ve edited a service’s configuration file, reload it without restarting the service:
systemctl reload service-name12. Check Systemd’s Overall Status
Get the overall status of the systemd service manager:
systemctl is-system-runningCommon responses include running, degraded, or maintenance.
13. Mask and Unmask Services
To completely block a service from starting (manually or automatically):
systemctl mask service-nameExample:
systemctl mask apache2To allow the service to run again:
systemctl unmask service-nameAdditional Tips
- Check Logs: Use
journalctl -u service-nameto view the logs of a specific service. - Version Info: Run
systemctl --versionto check your installed version of systemd. - Learn More: For comprehensive documentation, run
man systemctl.
Conclusion
Systemctl is a critical tool for managing Linux services, and with these commands, you’re well-equipped to handle most service-related tasks. If you found this guide helpful or have questions, let us know in the comments below.
Happy Linuxing! 🐧