For advanced Linux customers, starting, stopping, and restarting Linux services is essential. Users can access the features of each company through these actions. For example, to use a web site, consumers need to start the Apache services, or to use a database, people may start the MySQL services. System security and improvement can be achieved by managing Linux companies.

Despite popular belief, starting, stopping, and restarting service in Linux is fairly simple. We’ll get working with Linux, but all of the instructions for starting, stopping and restarting Linux providers can get run on CentOS, Ubuntu, Redhat, Fedora, Debian, and many other distribution.

What distinguishes services instructions from systemctl commands?

There are two recognized management tools that provide a constant way to start, stop, reset, and control system companies in Linux:

Systemctl offers more advanced features, including dominance management, enabling/disabling service, and integration with journalctl for uploading. Service is simpler and mainly used for basic services stop, cease, and standing orders. It is often used with older SysVinit-based devices.

Whether or not your distribution uses software or command will determine which one you choose to utilize. Systemctl is the company director of choice because the majority of current distribution then use software. However, some administrators also adhere to the aging company command because some old habits are hard to break.

Luckily, the developers of software made sure to keep services and transfer it to systemctl, but also on systemd-based systems, using service will also work for simple tasks

You might find a random service you installed that has n’t been updated to either the service or systemctl tools and needs to be manually started using /etc/rc to complicate matters even more. d ( or /etc/init. d ). But we’re looking for best practices here, and for starting, stopping, or restarting applications on Linux, best practices begin and end with systemctl.

SEE: With this bundle, you can begin learning how to use Linux for both IT and Sysadmin.

Starting a Linux service

Let’s say you want to start the Apache server.

To do this:

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

In this command:

  • sudoindicates that you are the root user of the command.
  • systemctlmanages systemd services.
  • startuses the systemctl command to launch the Apache service.
  • httpdthe name of the web server service from Apache.
  1. You will receive the following message when you run the command:

The service httpd has started successfully.

Note that if the service is already operational, you will see the following message:

The service httpd is already running.

SEE: How to quickly open a terminal in a specific Linux directory

Common error messages

Failed to start httpd.service. Unit httpd.service not found.

If the service unit file or the Apache web server package are missing, this error occurs. Install the Apache package using sudo apt install apache2 ( on Debian-based systems ) or sudo yum install httpd ( on Red Hat-based systems ) to resolve it.

Failed to start httpd.service. Address already in use.

This indicates that another process already uses the port Apache wants to bind to (usually port 80). Identify the conflicting process with sudo lsof -i:80 and stop it, or change the port configuration in Apache’s config file.

Stopping a Linux service

To stop the Apache service:

  1. Open a terminal window
  2. Run the command sudo systemctl stop httpd.
  3. You should now see the following message:

The service httpd has been stopped successfully.

Note that if the service, in this case Apache, was not running, you will get the following message:

Failed to stop service httpd. Unit httpd.service is not loaded.

Install it using sudo apt install apache2 (Debian-based) or sudo yum install httpd (Red Hat-based).

Or you may get one of the following messages:

Failed to stop service httpd. Unit httpd.service is not running.

This indicates Apache is already stopped, so no action is needed.

Failed to stop service httpd. Unit httpd.service 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 try restarting the service.

Failed to stop service httpd. Unit httpd.service is locked.

This error occurs if another process is controlling the service. Wait briefly and try again, or check for running management tasks with ps aux | grep httpd to identify the locking process.

SEE: Linux 101: How to search for files from the Linux command line

Restarting a Linux service

To restart the same service ( Apache ):

  1. Open a terminal window.
  2. Run the command sudo systemctl restart httpd.
  3. The service will restart, and you’ll be returned to the bash prompt.
  4. You will get the following message:

The service httpd has been restarted successfully.

Common error messages

If the Apache service is n’t running, you’ll see the following output:

The service httpd is not running.

You can start it directly with sudo systemctl start httpd or check its status with systemctl status httpd.

You may also see the following:

Job for httpd.service failed.

This usually indicates a configuration or dependency issue. To troubleshoot, review the error details with sudo journalctl -xe and correct any configuration issues.

Starting, stopping, and restarting services with service usage

To make matters interesting, the service command still works — even for those distributions that have migrated to systemd and systemctl. This means those who instinctively type service when needing to restart a service on Linux won’t receive an Unknown command error.

SEE: Using Googler, conduct a Google search from the Linux command line.

In the case of service, the command will redirect to systemctl. In fact, when you run the service command on a systemctl-enabled distribution, you’ll clearly see the redirect information.

The terminal shows you the redirect information for service commands on systemctl-enabled distributions.

The service command uses systemctl differently than systemctl. The service name and start, stop, and restart options are switched:

sudo service httpd start
sudo service httpd stop
sudo service httpd restart

In each case, you’ll see service redirected to systemctl, but the service you are attempting to start, stop, or restart will succeed.

Make sure to use the command man systemctl and read the man page to find out more about what systemctl can do for you.