Difference between starting a command using init.d script and service start

一个人想着一个人 提交于 2019-12-10 01:56:58

问题


I need to understand the difference between starting a command using init.d script and service start.

For example what is the difference between

/etc/init.d/nginx start and service nginx start.


回答1:


They do the same thing except service runs the script in a controlled environment. From the service(8) man page:

DESCRIPTION

service runs a System V init script in as predictable environment as possible, removing most environment variables and with current working directory set to /.

ENVIRONMENT

LANG, TERM
        The only environment variables passed to the init scripts.




回答2:


Furthermore:

Calling /etc/init.d/* scripts directly is deprecated by facts because:

On latest Debian/Ubuntu distro ( and derived ), sysvinit ( which was default init system ) has been replaced by either upstart or systemd. Thus, if one of the service is managed using either an usptart job or systemd unit configuration file, calling /etc/init.d/* will be a NOOP in sense that the script will exit without further information.

Instead, users must use the service command to start/stop/restart services. The service command is a wrapper which will invoke the right script, in as predictable environment as possible, whatever the init system in use ( sysinit, upstart or systemd ).



来源:https://stackoverflow.com/questions/22509654/difference-between-starting-a-command-using-init-d-script-and-service-start

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