Systemctl is a system utility in the Linux operating system that is used to manage services or daemons. It is one of the main utilities in systems using the systemd init system. Systemd is a tool for managing processes and services, and includes an init system, a unit manager, and other components.
The systemctl utility in Linux is the main tool for managing services in the system and is responsible for the following tasks:
- Start and Stop Services: Allows you to start and stop a specific service in the system. For example, the command "systemctl start apache2" will start the Apache web server, and "systemctl stop apache2" will stop it.
- Restarting Services: Also allows restarting services. For example, the command "systemctl restart apache2" will restart the Apache web server.
- Checking the status of services: Provides information about the current status of running services. The "systemctl status apache2" command will provide information about the status of the Apache web server, such as whether it is active, which ports it listens on, and other debugging information.
- Service Autorun Control: Allows you to configure whether a certain service will automatically start when the system boots or not. The "systemctl enable apache2" command will enable autorun of the Apache web server every time the system boots.
To use systemctl, you will need access to the Linux command line. Here are some basic commands and their usage:
- Starting the service: systemctl start <service> - the command allows you to start the specified service. To start the Apache HTTP Server service, you need to run systemctl start apache2.
- Stopping the service: systemctl stop <service> - the command stops the specified service. systemctl stop apache2 will stop Apache HTTP Server.
- Restarting the service: systemctl restart <service> - restart. systemctl restart apache2 will restart Apache HTTP Server.
- Restarting the service: systemctl reload <service> - restarts the service. The difference between restarting and rebooting is that restarting stops and then starts the service again, and rebooting restarts it, without stopping completely.
- Checking the service status: systemctl status <service> - the command shows the current status of the specified service.
Next, let's talk about configuring the service.
Basic commands for configuring and using systemctl.
Starting the service:
sudo systemctl start <service_name>
Stopping the service:
sudo systemctl stop <service_name>
Restarting the service:
sudo systemctl restart <service_name>
Enabling autorun of the service at system boot:
sudo systemctl enable <service_name>
Disabling autorun of the service when the system boots:
sudo systemctl disable <service_name>
Checking the service status:
sudo systemctl status <service_name>
View a list of all available services:
sudo systemctl list-unit-files --type=service
Viewing the service log:
sudo journalctl -u <service_name>
Viewing the latest system log entries:
sudo journalctl -xe
Rebooting the system:
sudo systemctl reboot
Shutting down the system:
sudo systemctl poweroff
Remember that you may need superuser rights (sudo) to execute systemctl commands. Make sure you specify the service name correctly when using these commands.