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
.
Init and Systemd are both init daemons but it is better to use the latter since it is commonly used in recent Linux Distros. Init uses service whereas Systemd uses systemctl to manage Linux services.
/etc/init is where the upstart init configs live. While they are not scripts themselves, they essentially execute whatever is required to replace sysvinit scripts. /etc/init. d is where all the traditional sysvinit scripts and the backward compatible scripts for upstart live.
The /etc/init. To start and run these services we used to simply type service "service name" start/stop/status/restart.
The systemctl command interacts with the SystemD service manager to manage the services. Contrary to service command, it manages the services by interacting with the SystemD process instead of running the init script.
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 ).
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