Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between starting a command using init.d script and service 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.

like image 545
user2025329 Avatar asked Mar 19 '14 14:03

user2025329


People also ask

What is the difference between systemd and init?

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.

What is the difference between ETC init and etc init D?

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

How do I start a service in etc init D?

The /etc/init. To start and run these services we used to simply type service "service name" start/stop/status/restart.

What is the difference between service and Systemctl commands?

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.


2 Answers

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.

like image 78
John Kugelman Avatar answered Oct 16 '22 11:10

John Kugelman


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

like image 22
Laurent DECLERCQ a.k.a Nuxwin Avatar answered Oct 16 '22 09:10

Laurent DECLERCQ a.k.a Nuxwin