systemctl
is a command-line tool used to control the systemd service manager on Linux systems. It allows you to manage system services, check the status of services, control system boot behavior, and manage system states. It is a critical tool for system administration, providing a comprehensive interface to interact with systemd.
- Service Management: Start, stop, restart, enable, or disable services.
- System Status: View the status of services and the overall system.
- Boot Management: Control which services start on boot.
- System States: Manage the system's power states (e.g., reboot, shutdown).
To start a service, use the following command:
sudo systemctl start <service_name>
To stop a service, use:
sudo systemctl stop <service_name>
For example, to start or stop the nginx service:
sudo systemctl start nginx
sudo systemctl stop nginx
To restart a service, which stops and then starts the service, use:
sudo systemctl restart <service_name>
To reload the service configuration without stopping the service, use:
sudo systemctl reload <service_name>
To enable a service to start automatically at boot, use:
sudo systemctl enable <service_name>
To disable a service from starting at boot, use:
sudo systemctl disable <service_name>
To check the status of a service, use:
sudo systemctl status <service_name>
This command provides detailed information about the service, including whether it is running, its recent log entries, and any issues.
To list all available services and their statuses, use:
systemctl list-units --type=service
To reboot, shut down, or power off the system, use:
sudo systemctl reboot # Reboot the system
sudo systemctl poweroff # Power off the system
sudo systemctl halt # Halt the system
To view logs related to systemd and its services, use:
journalctl -u <service_name>
This is useful for troubleshooting and monitoring service behavior.
Masking a service prevents it from being started manually or automatically:
sudo systemctl mask <service_name>
To unmask a service, allowing it to start again, use:
sudo systemctl unmask <service_name>
systemctl
is an essential tool for managing systemd on Linux systems, offering comprehensive control over services and system states. Whether you need to manage service lifecycles, configure boot behavior, or troubleshoot issues, systemctl
provides a powerful and flexible interface for system administration.