Difference between Systemctl and service command

人盡茶涼 提交于 2019-12-10 01:25:20

问题


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?


回答1:


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




回答2:


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.

And systemctl run services file from this directory: /lib/systemd



来源:https://stackoverflow.com/questions/43537851/difference-between-systemctl-and-service-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!