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
.
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
.
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.
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 ).