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!

tr_20241213-google-android-xr.jpg

Introducing a New Age of Smart Glasses

network-security-key-featured-image-12102024-min.png

Step-by-Step Guide to Locating Your Network Security Key on Any Device

money-growth-fotolia.jpg

Unlocking AI’s Potential: Three Steps to Maximize ROI in 2025

surveillance-biometrics-identity-privacy-KUBE-adobe.jpg

UK Police Illegally Retain Millions of Custody Images

is-faxing-secure-featured-image-12092024-min.png

Is Faxing Secure? Absolutely, When You Use Proper Network Protection

tra_20241209-the-complete-2025-comptia-certification-training-super-bundle-by-idunova.jpg

Get Ready for 2025 with Our CompTIA Training Bundle for Just $50!

stateless-firewall-featured-image-12052024-min.png

5 Benefits of Implementing a Stateless Firewall (and 3 Important Limitations)