Home CentOS/RHELHow to Manage Services with systemd on RHEL 9 and CentOS

How to Manage Services with systemd on RHEL 9 and CentOS

by Knowledge Base Linux
Manage services with systemd gears and controls illustration

On RHEL 9 and CentOS Stream 9, almost everything that starts, stops or restarts a service goes through one tool. Learning to manage services with systemd is therefore one of the highest-value skills a Linux administrator can have: it controls boot order, restarts crashed daemons automatically, and unifies logging through the journal. This guide explains how to manage services with systemd using systemctl, how targets replace old runlevels, and how to create your own service unit.

Prerequisites – How to Manage Services with systemd

  • A server running RHEL 9 or CentOS Stream 9 (any systemd-based distribution works)
  • Root or sudo access
  • A service to practise with, such as httpd, nginx or crond

Basic systemctl Commands to Manage Services with systemd

The four verbs you will use every day are start, stop, restart and status:

systemctl start httpd
systemctl stop httpd
systemctl restart httpd
systemctl status httpd

The status output is information-dense: whether the unit is active, when it started, its main PID, recent log lines and the cgroup it belongs to. To apply configuration changes without a full restart, reload instead:

systemctl reload httpd

Not every service supports reload. If it does not, reload-or-restart is the safe generic choice used in scripts.

Enable Services at Boot (and the Famous enable –now) – How to Manage Services with systemd

Starting a service now and enabling it at boot are two separate decisions. Do both in one command:

systemctl enable --now httpd
systemctl is-enabled httpd
systemctl is-active httpd

To stop a service from starting at boot without stopping it immediately, use systemctl disable httpd. To prevent a service from being started at all — even manually or as a dependency — mask it:

systemctl mask httpd
systemctl unmask httpd

Masking links the unit to /dev/null and is the right tool for permanently retiring a daemon such as an unused mail service.

Service dependency tree for admins who manage services with systemd

Understanding Targets: the systemd Replacement for Runlevels

Systemd boots into a target, a group of units that together describe a system state. The important ones on a server are:

  • multi-user.target — normal multi-user operation without a GUI (roughly runlevel 3)
  • graphical.target — multi-user with a display manager (roughly runlevel 5)
  • rescue.target and emergency.target — single-user recovery modes
systemctl get-default
systemctl set-default multi-user.target
systemctl isolate rescue.target

If a RHEL 9 server wastefully boots a desktop, switching the default target to multi-user.target frees memory and reduces the attack surface.

Creating Your Own Service Unit

Running an application from a unit file gives you automatic restarts, logging and boot integration for free. Create /etc/systemd/system/myapp.service:

[Unit]
Description=My Application Service
After=network.target

[Service]
Type=simple
User=myapp
WorkingDirectory=/opt/myapp
ExecStart=/opt/myapp/myapp --config /etc/myapp/config.yaml
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

Files in /etc/systemd/system/ override vendor units in /usr/lib/systemd/system/. After creating or editing a unit, always run:

systemctl daemon-reload
systemctl enable --now myapp
journalctl -u myapp -f

To tweak a vendor unit without editing it (your changes would be lost on update), use systemctl edit httpd, which creates a drop-in override directory.

Listing and Inspecting Units

On a busy server you will often forget an exact unit name or want to see everything that failed overnight. These commands answer both questions:

systemctl list-units --type=service
systemctl list-units --failed
systemctl list-unit-files --type=service | grep -i backup

To inspect how a unit is actually configured — including drop-in overrides merged from several files — use systemctl cat httpd, which prints the effective unit exactly as systemd sees it. And systemctl show httpd -p Restart -p User exposes individual properties, which is perfect for scripts that need to verify a setting before making changes.

Reading Logs with journalctl

Because systemd captures stdout, stderr and syslog into the journal, journalctl is your first stop when a service misbehaves:

journalctl -u httpd --since "1 hour ago"
journalctl -u httpd -b -1
journalctl -p err -b

The second command shows the previous boot’s logs for the unit — invaluable after a crash. If the journal grows too large, our guide on how to clear journal logs explains how to vacuum it safely.

Timers deserve a mention too: systemd timers are the modern replacement for cron for service-related schedules. Run systemctl list-timers to see every scheduled unit on the system, when it last ran and when it will run next — far more visibility than a crontab ever gave you.

Troubleshooting

“Unit not found”: check the exact name with systemctl list-unit-files | grep -i name and confirm the package is installed.

Service enters a failed state immediately: read the full error with systemctl status -l and journalctl -xeu servicename; the most common causes are typos in the unit, wrong file permissions, or SELinux denials on RHEL systems.

Changes to a unit have no effect: you forgot systemctl daemon-reload after editing the file.

The server boots slowly: systemd-analyze blame shows which units delayed the boot, and systemd-analyze critical-chain shows the blocking path.

Conclusion

When you manage services with systemd properly — enabling with --now, masking what you retire, writing clean unit files with restart policies, and debugging through the journal — RHEL 9 administration becomes predictable and scriptable. The official systemd project pages document every unit option if you need to go deeper.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.