Managing Services in Linux: Starting, Stopping, and Restarting

For advanced Linux users, managing services is a key skill. If you want to use a web server, like Apache, you need to start that service. To access a database, you’ll need to start MySQL. Effectively managing these services not only makes them accessible but also keeps your system stable and performing well.

Many users think that handling these tasks is complicated, but it’s pretty straightforward. Regardless of whether you’re on CentOS, Ubuntu, Red Hat, Fedora, or Debian, the basic commands are essentially the same.

Now, let’s clear up something. There are two main tools for managing these services: systemctl and service.

Systemctl is the more powerful option. It lets you manage dependencies, enable or disable services, and even integrates with logs using journalctl. On the other hand, service is much simpler, mainly used for basic commands like start, stop, and status. It’s mostly found on older systems that use SysVinit.

Your choice between them depends on your Linux distribution. Most modern systems use systemd, so you’ll likely rely on systemctl. However, some administrators still prefer the old service command out of habit. The good news is that even when using `system

d, theservice` command still works for basic functions.

Sometimes, you might encounter services that need manual intervention, located in /etc/rc.d or /etc/init.d. But for best practices in managing services, stick with systemctl.

Starting a Linux Service

Let’s start with how to begin a service, like Apache.

  1. Open a terminal.
  2. Type: sudo systemctl start httpd.

Breaking that down:

  • sudo lets you run the command with root privileges.
  • systemctl controls the service manager.
  • start is the action you’re taking – starting the service.
  • httpd is the name of the Apache service.

If successful, you’ll see: “The service httpd has started successfully.” If it’s already running, you’ll see: “The service httpd is already running.”

Common Error Messages

  1. Failed to start httpd.service. Unit httpd.service not found.
    This means the Apache package is missing. You can install it using:

    • sudo apt install apache2 for Debian-based systems.
    • sudo yum install httpd for Red Hat-based systems.
  2. Failed to start httpd.service. Address already in use.
    This means another process is using port 80. Use sudo lsof -i:80 to find the conflicting process and either stop it or change Apache’s port.

Stopping a Linux Service

To stop Apache, the steps are similar:

  1. Open a terminal.
  2. Type: sudo systemctl stop httpd.

You’ll see: “The service httpd has been stopped successfully.” If it wasn’t running, you’ll get: “Failed to stop service httpd. Unit httpd.service is not loaded.” You’ll need to install Apache in that case.

Other messages you could see include:

  • “Failed to stop service httpd. Unit httpd.service is not running.” This just means it’s already stopped.
  • “Failed to stop service httpd. Unit httpd.service is in a failed state.” Check logs with sudo journalctl -xe for troubleshooting.
  • “Failed to stop service httpd. Unit httpd.service is locked.” This means another process is controlling it. Wait a moment and try again or check for running processes with ps aux | grep httpd.

Restarting a Linux Service

To restart Apache:

  1. Open a terminal.
  2. Type: sudo systemctl restart httpd.

You should see: “The service httpd has been restarted successfully.”

If the service isn’t running, the message will be: “The service httpd is not running.” You can start it with sudo systemctl start httpd or check its status with systemctl status httpd.

If you see “Job for httpd.service failed,” then something’s wrong with the configuration. Check the error logs with sudo journalctl -xe for more details.

Using the Service Command

If you prefer to stick to the service command, it still works in most modern distributions:

  • Starting: sudo service httpd start
  • Stopping: sudo service httpd stop
  • Restarting: sudo service httpd restart

When you run these commands, they redirect to systemctl, so you’ll get the same results without any errors. Want to dig deeper? Use the command man systemctl for a detailed read on its capabilities.

Unlock your business potential with our expert guidance. Get in touch now!

FeatureImage_Young_Woman_Holding_Credit_Card_and_Using_a_Laptop.jpg

Top 6 Credit Unions for Business Accounts in 2025

tr_20240220-consultio-pro-lifetime-access.jpg

Unlock Lifetime Access to 50+ AI Experts with Consultio Pro for Just $29.99!

huawei-featured-feb-25.jpg

Huawei Launches Its First Tri-Fold Smartphone Globally

tr_20230929-internxt-cloud-storage-lifetime-subscription-2tb-plan.jpg

Secure 2TB Lifetime Cloud Storage Plan from Internxt for Just $91!

tr_20250216-arm-cpu-qualcomm-nvidia.jpg

Arm Surprises Semiconductor Industry with Potential Plan to Sell Its Own Chips

strategy_a200792738.jpg

A Journey Toward Enhanced Data Engineering

tr_20241203-how-to-use-square.jpg

Understanding Square: Functionality and Purpose Explained