With most Linux distros I've used, it's simply sudo service <name> restart
...
This is because many or most linux distros are descended from Debian, which traditionally has used a "UNIX System 5" (aka. SysV) style init system. In fact, if you go back far enough all linux distros used this kind of system.
I am not sure whether the service
command was part of the original SysV init or whether it was a convenience created by Debian, but it certainly has been around a long time and spread throughout the Debian family tree.
However, about a decade ago linux distributions began to move away from an init system that was increasingly considered inefficient and outdated in various aspects. This includes Ubuntu, which eventually came out with upstart, and Redhat/Fedora and derivatives, who developed systemd (where "d" is for daemon).
Eventually, Ubuntu decided to abandon upstart in favour of systemd, and Debian has done the same thing in version 8 by deprecating SysV. Raspbian, the operating system predominantly used on the Pi, is a very close derivative of Debian, uses the same version numbering, etc. (which is why the first version of Raspbian was 7, not 1), and hence has now also switched to systemd.
The service
command should continue to work as Debian has kept version 8 (jessie) backward compatible in this sense, but you may want to try systemd's methodology instead:
sudo systemctl restart <name>
Note the command (restart
) and the service name are inverted. Also, this will probably not provide any output but does indicate success or failure via the exit status (echo $?
; anything other than 0 means fail). You can get some information about how things went with:1
systemctl status <name>
No sudo
required as far as I have ever noticed. There should be a time there indicating when the service was stopped and started again and it will be very clear whether it is running, or whether it failed. In the latter case an error will usually be described. Note that a "dead" service has not necessarily failed, it just means it did whatever it was supposed to do then exited.
I believe doing this will better handle a problematic service which hung service
.
1. I have a suggestion here about how to simplify this hassle.