91

Maybe this is a trivial question, but it is not totally clear to me. On one of our servers we have some background processes running which were started with service and some others which were started with systemctl, like this:

$ service nginx start
$ systemctl start gunicorn

What is the difference between the two commands? Which one is the preferred way to deal with background services? How to configure the preferred command?

Aidas Bendoraitis
  • 1,345
  • 1
  • 12
  • 17
  • 4
    there is a very good explanation [there](https://askubuntu.com/a/903405/840341) – Félix Brunet Jul 18 '18 at 17:10
  • The painful part of this, some say service is 'defunct' and if it is not, why the hell do they change the order of arguments as with 'find/grep/locate' etc...no consistency within linux releases :( – killjoy Oct 18 '18 at 21:59

3 Answers3

94

service is an "high-level" command used for starting and stopping services in different unixes and linuxes. Depending on the "lower-level" service manager, service redirects on different binaries.

For example, on CentOS 7 it redirects to systemctl, while on CentOS 6 it directly calls the relative /etc/init.d script. On the other hand, in older Ubuntu releases it redirects to upstart

service is adequate for basic service management, while directly calling systemctl give greater control options.

shodanshok
  • 44,038
  • 6
  • 98
  • 162
21

systemctl is basically a more powerful version of service.

With service you can only do commands related to the service (i.e. status, reload, restart) whereas with systemctl you can use more advanced commands such as:

systemctl is-failed name.service # check if service failed to load

Or masking services:

systemctl mask name.service

There's a lot of good info on this page from Ask Ubuntu.

SamCyanide
  • 319
  • 1
  • 5
  • 4
    Mind that although more powerful, `systemctl` is not a new version of `service`. It is not designed to replace `service`. Rather, `service` is designed as a high-level wrapper to "abstract" out various service managers like `init.d`, `initctl`, and (of course) `systemctl`. – wlnirvana Apr 03 '20 at 14:37
  • I assume `service` was basically a wrapper for starting /etc/init.d scripts and they kept it around for "backward compatiility" with systemctl or something... – rogerdpack Apr 28 '22 at 17:44
10

systemctl is the main utility to control daemons/services in systemd,
while the service command is the traditional utility in SysVinit world.

One of systemd's features is to be compatible with SysVinit/legacy commands,
so, if you have the systemctl command,
service foo start will be a wrapper around systemctl start foo.

Same story for chkconfig.

maioman
  • 209
  • 2
  • 4