11

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.

2 Answers 2

9

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.

Sign up to request clarification or add additional context in comments.

Comments

9

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

1 Comment

I checked on a RHEL 7.9 and found that the service command acts as a wrapper for System V init scripts (the ones configured under /etc/init.d), but not for systemd. So I think the description is misleading (I suggested an edit). I don't know if on other Unixes the service command is still used as a wrapper for newer init systems, but on RedHat it appears to not be the case.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.