1

Do the two different syntaxes do the same thing?

$ service apache2 restart

$ /etc/init.d/apache2 restart
user784637
  • 1,482
  • 7
  • 35
  • 51
  • As a side note, the whole "service foo restart" thing annoys me because I don't have tab completion. – cjc Dec 30 '11 at 20:25

4 Answers4

3

Yes. The backward compatible /etc/init.d/ scripts basically run service myservice start/stop/retstart instead of doing anything themselves.

Stone
  • 6,941
  • 1
  • 19
  • 33
3

Service is nothing more than a shell script.

cat /sbin/service

At that top you will see it sets the SERVICEDIR to /etc/init.d.

The service script has a few other options such as

--status-all
--full-restart

That loop over all services. But the name you pass to it is matched to the init.d script.

jeffatrackaid
  • 4,112
  • 18
  • 22
1

Yes.

To be precise:

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

(from service(8))

James O'Gorman
  • 5,249
  • 2
  • 23
  • 28
1

In a way, yes. Actually upstart jobs will give a warning if started with /etc/init.d/ while service command always works both for sys v init scripts as well as upstart jobs.

Aditya Patawari
  • 1,065
  • 8
  • 23