Managing Linux Services: systemctl, chkconfig and service Commands

Service management is a daily Linux admin task. RHEL 7+ uses systemd with systemctl commands, while RHEL 6 uses SysV init with service and chkconfig. Both are tested in RHCA.

systemctl — RHEL 7+ Service Management

# Start/stop/restart:
# systemctl start httpd
# systemctl stop httpd
# systemctl restart httpd
# systemctl reload httpd             # reload config without full restart

# Check status:
# systemctl status httpd
# systemctl is-active httpd          # returns active or inactive
# systemctl is-enabled httpd         # returns enabled or disabled
# systemctl is-failed httpd

# Enable/disable at boot:
# systemctl enable httpd             # start at boot
# systemctl disable httpd            # don't start at boot

# List services:
# systemctl list-units --type=service           # all active services
# systemctl list-units --type=service --all     # including inactive
# systemctl list-unit-files --type=service      # enabled/disabled status

# Failed services:
# systemctl --failed --type=service
# systemctl reset-failed httpd       # clear failed state

Masking and Unmasking Services

Masking prevents a service from starting — even manually or as a dependency. Use when two conflicting services (e.g., ntp and chrony) must not run together.

# Mask (completely prevent start):
# systemctl mask ntp

# Unmask (restore ability to start):
# systemctl unmask ntp

# A masked service cannot be started:
# systemctl start ntp                # → Failed: Unit is masked

RHEL 6 Service Management (SysV init)

# Start/stop/restart:
# service httpd start
# service httpd stop
# service httpd restart
# service httpd reload
# service httpd status

# Enable/disable at boot (chkconfig):
# chkconfig httpd on                 # enable for runlevels 2,3,4,5
# chkconfig httpd off                # disable for all runlevels
# chkconfig --list httpd             # see runlevel settings
# chkconfig --list                   # list all services

# Enable for specific runlevels:
# chkconfig --level 35 httpd on      # enable only for runlevel 3 and 5

systemd vs SysV init Equivalents

RHEL 6 (SysV)RHEL 7+ (systemd)
service httpd startsystemctl start httpd
service httpd stopsystemctl stop httpd
service httpd statussystemctl status httpd
chkconfig httpd onsystemctl enable httpd
chkconfig httpd offsystemctl disable httpd
init 3systemctl isolate multi-user.target
init 5systemctl isolate graphical.target
init 0systemctl poweroff
init 6systemctl reboot

systemd Targets vs Run Levels

Run Level 0  → poweroff.target
Run Level 1  → rescue.target
Run Level 3  → multi-user.target
Run Level 5  → graphical.target
Run Level 6  → reboot.target

# Check current target:
# systemctl get-default

# Change default target:
# systemctl set-default multi-user.target     # CLI mode
# systemctl set-default graphical.target      # GUI mode

# Switch target temporarily:
# systemctl isolate multi-user.target

Viewing Service Logs with journalctl

# All logs for a service:
# journalctl -u httpd

# Follow live logs:
# journalctl -u httpd -f

# Logs since boot:
# journalctl -u httpd -b

# Logs with errors only:
# journalctl -u httpd -p err

# Last 50 lines:
# journalctl -u httpd -n 50

# Logs between timestamps:
# journalctl -u httpd --since "2026-06-01" --until "2026-06-07"

Troubleshooting Services

# 1. Check status + error output:
# systemctl status httpd -l

# 2. Check journal for errors:
# journalctl -u httpd -n 100 -p err

# 3. Check config file syntax:
# httpd -t                           # Apache config test
# named-checkconf                    # DNS config test
# sshd -t                            # SSH config test

# 4. Check ports:
# ss -tulnp | grep httpd             # is it listening?

# 5. Check firewall:
# firewall-cmd --list-all

# 6. Check SELinux:
# sealert -a /var/log/audit/audit.log