Home » Notes » How to Restart Service in Linux

How to Restart Service in Linux

You can use the restart command to restart Systemd services. This command stops the service and then starts it back. Or it just starts the service if it is not running. For example, you can restart the Nginx web server using this command:

sudo systemctl restart nginx

If everything is okay, the command will output nothing. But if an error occurs while the process is stopped or started, an error message will be displayed.

When you want to restart the service only if it is running use the try-restart command:

sudo systemctl try-restart nginx

The Systemd initialization system supports not only services restarting, when the services are entirely stopped but also soft reloading. In this case, the service continues working without downtime and only updates its configuration from configuration files. You can use this reloading by entering the reload command:

sudo systemctl reload nginx

This method is not supported by all services. If you don't know whether a specific service supports reloading but still want to restart it, use the reload-or-restart command. For example:

sudo systemctl reload-or-restart nginx

This command will use soft reloading if it is supported. But if it is not, the service will be restarted in the usual way. You can read more about service management in Linux in this article.

Rate the Article

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...
Creative Commons License
The article is distributed under Creative Commons ShareAlike 4.0 license. Link to the source is required .

Leave a Comment