EP10: systemctl & Service Management in Linux

🎯 What You’ll Learn

In this episode, you’ll learn how to:

  • Start, stop, enable, and check services using systemctl

  • Understand the difference between active and enabled

  • Troubleshoot service failures

  • Practice real RHCSA scenarios


πŸ›  What Is systemctl?

systemctl is a command used to control services (also called units) on modern Linux systems using systemd.

βœ… RHEL 7 and above (including RHEL 8/9) use systemd as the init system.
βœ… For RHCSA, mastering systemctl is a must.


🧠 Real-World Analogy

Think of your Linux system as a factory, and services as machines.

  • systemctl start = Turn the machine ON now 🟒

  • systemctl stop = Turn the machine OFF now πŸ”΄

  • systemctl enable = Tell it to automatically start every morning (at boot) ⏰

  • systemctl disable = Don't auto-start anymore

  • systemctl status = Check the machine's health βœ…βŒ


πŸ§ͺ Common RHCSA Service Management Commands

Action

Command

Start a service now

sudo systemctl start <service>

Stop a service

sudo systemctl stop <service>

Restart a service

sudo systemctl restart <service>

Reload (re-read config)

sudo systemctl reload <service>

Enable at boot

sudo systemctl enable <service>

Disable at boot

sudo systemctl disable <service>

Check status

systemctl status <service>


βœ… Examples

Start and Enable Apache (httpd)

sudo systemctl start httpd
sudo systemctl enable httpd

Stop and Disable

sudo systemctl stop httpd
sudo systemctl disable httpd

Check Service Status

systemctl status httpd

You’ll see:

  • Active: active (running) βœ…

  • Or Active: inactive (dead) ❌

  • Or failed πŸ”₯ if something went wrong


πŸ” Check If Service Is Enabled at Boot

systemctl is-enabled httpd

Output:

  • enabled = will start at boot 🟒

  • disabled = won’t start at boot πŸ”΄

  • static = part of another unit, not standalone


πŸ“‹ List All Running Services

systemctl list-units --type=service --state=running

πŸ“‹ List All Services (Running or Not)

systemctl list-units --type=service

πŸ“‹ List Failed Services

systemctl --failed

Very useful for troubleshooting!


πŸ”§ View Logs with journalctl

To see service logs (e.g., httpd):

journalctl -u httpd

Add -xe for detailed logs:

journalctl -xe

πŸ“‚ Service File Location

Most unit files live in:

/usr/lib/systemd/system/

You can view or edit them (not usually needed for RHCSA).


🧠 RHCSA Must-Know Scenario

  1. Install a service:

    sudo dnf install vsftpd
    
  2. Start it:

    sudo systemctl start vsftpd
    
  3. Enable it at boot:

    sudo systemctl enable vsftpd
    
  4. Check status:

    systemctl status vsftpd
    
  5. Verify:

    systemctl is-enabled vsftpd
    

⚠️ Troubleshooting Tips

Symptom

What to check

Service not running

systemctl status

Logs not showing

journalctl -u <service>

Won’t start at boot

Check is-enabled

Service fails silently

Try systemctl restart or journalctl -xe


βœ… Summary: Know These Commands!

Purpose

Command

Start now

systemctl start <svc>

Stop now

systemctl stop <svc>

Restart

systemctl restart <svc>

Enable at boot

systemctl enable <svc>

Disable at boot

systemctl disable <svc>

Check status

systemctl status <svc>

View logs

journalctl -u <svc>

List services

systemctl list-units --type=service

Updated on