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?
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.
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.
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.
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.
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
With borrowing from this answer:
service
is an "high-level" command used forstart
,restart,
stop
andstatus
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 callingsystemctl
give greater control options.
Moreover, systemctl
runs services file from this path: /lib/systemd/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With