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-name
Example:
systemctl status apache2
You’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-name
Example:
systemctl start apache2
3. Stop a Service
To stop a running service:
systemctl stop service-name
Example:
systemctl stop apache2
4. Restart a Service
To restart a service:
systemctl restart service-name
Example:
systemctl restart apache2
5. Enable a Service to Start on Boot
Ensure a service starts automatically when your system boots:
systemctl enable service-name
Example:
systemctl enable apache2
6. Disable a Service from Starting on Boot
To prevent a service from starting automatically:
systemctl disable service-name
Example:
systemctl disable apache2
7. List Active Services
To see all currently active services:
systemctl list-units --type=service --state=active
8. List All Services
For a complete list of all services, regardless of their state:
systemctl list-units --type=service
9. Check Disabled Services
View services that are not set to start on boot:
systemctl list-unit-files --state=disabled
10. Check Failed Services
If something is not working, this command lists services that have failed:
systemctl list-units --type=service --state=failed
11. Reload a Service Configuration
If you’ve edited a service’s configuration file, reload it without restarting the service:
systemctl reload service-name
12. Check Systemd’s Overall Status
Get the overall status of the systemd service manager:
systemctl is-system-running
Common responses include running
, degraded
, or maintenance
.
13. Mask and Unmask Services
To completely block a service from starting (manually or automatically):
systemctl mask service-name
Example:
systemctl mask apache2
To allow the service to run again:
systemctl unmask service-name
Additional Tips
- Check Logs: Use
journalctl -u service-name
to view the logs of a specific service. - Version Info: Run
systemctl --version
to 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! 🐧