Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Systemctl and service command

I always run my Apache server in this way:

sudo service apache2 start 

But in many guides I saw commands like this:

sudo systemctl start apache2 

Can somebody shortly write the difference between these commands and give me advice about what command I should use in everyday work?

like image 475
Roman Romanov Avatar asked Apr 21 '17 08:04

Roman Romanov


People also ask

What is the difference between Systemctl and systemd?

In a nutshell, Systemctl is a control panel or service manager for the systemd init system to initialize components after the Linux kernel is booted. Systemctl is a collection of libraries, daemons, and utilities that you can use to manage services.

What is the use of Systemctl command?

The systemctl command manages both system and service configurations, enabling administrators to manage the OS and control the status of services. Further, systemctl is useful for troubleshooting and basic performance tuning.

What is the difference between Systemctl start and Systemctl enable?

3 Answers. systemctl start and systemctl enable do different things. enable will hook the specified unit into relevant places, so that it will automatically start on boot, or when relevant hardware is plugged in, or other situations depending on what's specified in the unit file. start starts the unit right now.

What is service command in Linux?

The service command is used to run a System V init script. Usually all system V init scripts are stored in /etc/init. d directory and service command can be used to start, stop, and restart the daemons and other services under Linux.


2 Answers

service operates on the files in /etc/init.d and was used in conjunction with the old init system. systemctl operates on the files in /lib/systemd. If there is a file for your service in /lib/systemd it will use that first and if not it will fall back to the file in /etc/init.d. Also If you are using OS like ubuntu-14.04 only service command will be available.

So if systemctl is available ,it will be better to use it

like image 125
shahin Avatar answered Oct 14 '22 02:10

shahin


With borrowing from this answer:

service is an "high-level" command used for start, restart, stop and status services in different Unixes and Linuxes. Depending on the "lower-level" service manager, service redirects on different binaries.

For example, on CentOS 7 it redirects to systemctl, while on CentOS 6 it directly called the relative /etc/init.d script. On the other hand, in older Ubuntu releases it redirects to upstart.

service is adequate for basic service management, while directly calling systemctl give greater control options.

Moreover, systemctl runs services file from this path: /lib/systemd/

like image 27
Benyamin Jafari Avatar answered Oct 14 '22 00:10

Benyamin Jafari