How to Start, Stop, and Restart Services in Linux

How to Start, Stop, and Restart Services in Linux

How to Start, Stop, and Restart Services in Linux

Home ยป News ยป How to Start, Stop, and Restart Services in Linux
Table of Contents

For complicated Linux customers, beginning, preventing, and restarting Linux services and products is very important. These operations permit customers to get admission to the capability of each and every provider. For instance, to make use of a internet server, customers want to get started the Apache provider, or to make use of a database, customers will have to get started the MySQL provider. Managing Linux services and products may be necessary for machine balance and will assist toughen machine efficiency.

Despite commonplace trust, beginning, preventing, and restarting services and products in Linux is slightly simple. Weโ€™ll be operating with Linux, however the entire instructions for beginning, preventing and restarting Linux services and products can also be run on CentOS, Ubuntu, Redhat, Fedora, Debian, and plenty of different distributions.

What is the adaptation between systemctl and repair instructions?

There are two reputable control gear that offer a constant approach to get started, prevent, restart, and set up machine services and products in Linux:

Systemctl provides extra complicated capability, together with dependency control, enabling/disabling services and products, and integration with journalctl for logging. Service is more effective and essentially used for elementary provider get started, prevent, and standing instructions. It is incessantly used with older SysVinit-based programs.

Which one you employ depends upon whether or not your distribution makes use of systemd or init. Most fashionable distributions now use systemd, so systemctl is the provider supervisor of selection. But some outdated behavior die laborious, such a lot of directors nonetheless dangle onto the getting old provider command.

Fortunately, the builders of systemd made positive to retain provider and redirect it to systemctl, so even on systemd-based programs, the use of provider will nonetheless paintings for elementary duties

To complicate issues extra, chances are you’ll discover a random provider youโ€™ve put in that hasnโ€™t been up to date to both the provider or systemctl gear and will have to manually get started it with /and so on/rc.d (or /and so on/init.d).But weโ€™re searching for perfect practices right here, and for beginning, preventing, or restarting packages on Linux, perfect practices start and finish with systemctl.

SEE: Start studying to make use of Linux for IT and Sysadmin with this package

Starting a Linux provider

Letโ€™s say you wish to have to start out the Apache server.

To do that:

  1. Open a terminal window.
  2. Run the command sudo systemctl get started httpd.

In this command:

  • sudo tells Linux you might be operating the command as the basis person.
  • systemctl manages systemd services and products.
  • get started tells the systemctl command to start out the Apache provider.
  • httpd is the title of the Apache internet server provider.
  1. Once you run the command you are going to get the next message:

The provider httpd has began effectively.

Note that if the provider is already operating you are going to see the next message:

The provider httpd is already operating.

SEE: How to briefly open a terminal in a selected Linux listing

Common error messages

Failed to start out httpd.provider. Unit httpd.provider no longer discovered.

This error happens if the Apache internet server bundle isnโ€™t put in or the provider unit record is lacking. Install the Apache bundle the use of sudo apt set up apache2 (on Debian-based programs) or sudo yum set up httpd (on Red Hat-based programs) to get to the bottom of it.

Failed to start out httpd.provider. Address already in use.

This signifies that every other procedure already makes use of the port Apache desires to bind to (most often port 80). Identify the conflicting procedure with sudo lsof -i:80 and prevent it, or trade the port configuration in Apacheโ€™s config record.

Stopping a Linux provider

To prevent the Apache provider:

  1. Open a terminal window
  2. Run the command sudo systemctl prevent httpd.
  3. You will have to now see the next message:

The provider httpd has been stopped effectively.

Note that if the provider, on this case Apache, was once no longer operating, you are going to get the next message:

Failed to prevent provider httpd. Unit httpd.provider isn't loaded.

Install it the use of sudo apt set up apache2 (Debian-based) or sudo yum set up httpd (Red Hat-based).

Or you can get one of the vital following messages:

Failed to prevent provider httpd. Unit httpd.provider isn't operating.

This signifies Apache is already stopped, so no motion is wanted.

Failed to prevent provider httpd. Unit httpd.provider is in a failed state.

This suggests Apache encountered an error and is in a failed state. To troubleshoot, run sudo journalctl -xe to view detailed logs, then take a look at restarting the provider.

Failed to prevent provider httpd. Unit httpd.provider is locked.

This error happens if every other procedure is controlling the provider. Wait in short and check out once more, or take a look at for operating control duties with playstation aux | grep httpd to spot the locking procedure.

SEE: Linux 101: How to seek for recordsdata from the Linux command line

Restarting a Linux provider

To restart the similar provider (Apache):

  1. Open a terminal window.
  2. Run the command sudo systemctl restart httpd.
  3. The provider will restart, and also youโ€™ll be returned to the bash suggested.
  4. You gets the next message:

The provider httpd has been restarted effectively.

Common error messages

If the Apache provider isnโ€™t operating, youโ€™ll see the next output:

The provider httpd isn't operating.

You can get started it without delay with sudo systemctl get started httpd or take a look at its standing with systemctl standing httpd.

You may additionally see the next:

Job for httpd.provider failed.

This most often signifies a configuration or dependency factor. To troubleshoot, evaluate the mistake main points with sudo journalctl -xe and proper any configuration problems.

Starting, preventing, and restarting services and products with provider utilization

To make issues attention-grabbing, the provider command nonetheless works โ€” even for the ones distributions that experience migrated to systemd and systemctl. This manner those that instinctively sort provider when wanting to restart a provider on Linux receivedโ€™t obtain an Unknown command error.

SEE: Run a Google seek from the Linux command line with Googler

In the case of provider, the command will redirect to systemctl. In reality, whilst you run the provider command on a systemctl-enabled distribution, youโ€™ll obviously see the redirect knowledge.

the Terminal Shows You the Redirect Information for Service Commands on Systemctl-enabled Distributions.
the terminal presentations you the redirect knowledge for provider instructions on systemctl enabled distributions

The provider command utilization is a little other from systemctl. The provider title and get started, prevent, and restart choices are switched:

sudo provider httpd get started
sudo provider httpd prevent
sudo provider httpd restart

In each and every case, youโ€™ll see provider redirected to systemctl, however the provider you are trying to start out, prevent, or restart will prevail.

To be told extra about what systemctl can do for you, make sure you factor the command guy systemctl and provides the person web page a learn.

author avatar
roosho Senior Engineer (Technical Services)
I am Rakib Raihan RooSho, Jack of all IT Trades. You got it right. Good for nothing. I try a lot of things and fail more than that. That's how I learn. Whenever I succeed, I note that in my cookbook. Eventually, that became my blog.ย 
share this article.

ADVERTISEMENT

ADVERTISEMENT

Enjoying my articles?

Sign up to get new content delivered straight to your inbox.

Please enable JavaScript in your browser to complete this form.
Name