March 11, 2023
TL;DR; both
systemctl
andservice
are used to manage services in Linux.systemctl
is a newer command that was introduced with Systemd. You should prefersystemctl
overservice
as it provides more advanced features.
A service is a program that runs in the background and performs a specific task. For example, the httpd
service runs the Apache HTTP server, the mysqld
service runs the MySQL database server, and the sshd
service runs the OpenSSH server. To start, stop, or restart a service, you can use the systemctl
or service
command.
service
is a legacy command that has been used in earlier versions of Linux to manage services. It is still available in many Linux distributions and can be used to start, stop, and restart services. For example, you might have used the following command to start, stop or restart the httpd
service:
service httpd start
service httpd stop
service httpd restart
systemctl
is a newer command that was introduced with Systemd, which is a system and service
manager that has become the default init system in many modern Linux distributions. It provides a more advanced way of managing services, including features like parallel startup of services, dependency-based startup, and service
unit files. Above example can be rewritten using systemctl
as follows:
systemctl start httpd
systemctl stop httpd
systemctl restart httpd
You should prefer systemctl
over service
as it provides more advanced features and is the relatively newer command. However, service
is still available in many Linux distributions and can be used to start, stop, and restart services.