In Fedora we have 'systemctl' and 'service' scripts. It seems that service internally calls systemctl
. So what is the correct/right way on Fedora to start or stop services -- via systemctl
or service
facility? May be there are nuances to keep in mind?
2 Answers
The way to stop/start services in Fedora (later versions) is using systemctl
.
However, there may be a few services left in /etc/init.d/
which you could control with the service
command. You can still control them with systemctl
as systemd
automatically maps them to unit files for you.
For example, on my CentOS 7 (Fedora 19 or thereabouts), there is a /etc/rc.d/init.d/network
script which I could control with the service
command. If I use systemctl
instead, it still works:
# sudo systemctl status network
network.service - LSB: Bring up/down networking
Loaded: loaded (/etc/rc.d/init.d/network)
Active: active (exited) since Tue 2014-11-11 08:21:51 GMT; 2 weeks 1 days ago
As you can see, it has been mapped to /etc/rc.d/init.d/network
by systemd
and the systemctl
command controls it.
I could be so 'last year' and use service
instead:
# service network status
Configured devices:
lo eth0
Currently active devices:
lo eth0 tun0
Both work, but note that they do give different results in their status
commands.
It's typically the case that the service
scripts are redirected to systemctl (Systemd) scripts so it's basically your preference which you want to use.
Example
From my Fedora 20 system.
$ service sshd status
Redirecting to /bin/systemctl status sshd.service
sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled)
Active: active (running) since Fri 2014-11-21 09:12:10 EST; 5 days ago
Main PID: 1095 (sshd)
CGroup: /system.slice/sshd.service
└─1095 /usr/sbin/sshd -D
Nov 21 09:12:10 dufresne systemd[1]: Starting OpenSSH server daemon...
Nov 21 09:12:10 dufresne systemd[1]: Started OpenSSH server daemon.
Nov 21 09:12:11 dufresne sshd[1095]: Server listening on 0.0.0.0 port 22.
Nov 21 09:12:11 dufresne sshd[1095]: Server listening on :: port 22.
I generally use both methods, since old habits die hard. But if you're trying to adapt to the Systemd world, I'd continue to force myself to do things using systemctl
if possible.
Also Systemd brings everything that you used to do with chkconfig
and service
under one command, systemctl
, so I generally find that easier to cope with in the long run.
This cheatsheet on the Fedora project's website is helpful in making the switch.
Incidentally, the answer to your original question is answered in a footnote on that page:
Note that all /sbin/service and /sbin/chkconfig lines listed above continue to work on systemd, and will be translated to native equivalents as necessary. The only exception is chkconfig --list.
service foo start
in debian works whether your init system is systemd or sysvinit or upstart;systemctl
would likely not work if systemd isn't PID1.