Intermediate · 30 minutes · Guided lesson

Service state and useful logs

Separate active from enabled, recognise OpenRC and collect useful evidence.

By the end of this lesson

  • Distinguish running now from configured to start later
  • Identify the init system before choosing a tool
  • Filter a bounded log window and interpret missing evidence

Your environment: Live examples distinguish systemd from OpenRC. The fixture lab works without a service manager. Setup help

State has more than one dimension

A service manager coordinates background services. On systemd, active describes current state; enabled usually describes whether a unit is linked into a startup target. A unit can be active but disabled, or enabled but currently failed. Some units are static or socket-activated, so enabled/disabled alone is not the whole startup story.

Not every Linux environment uses systemd. Alpine commonly uses OpenRC. Containers and some WSL environments may not have a full service manager as PID 1. First inspect PID 1, then use the tools appropriate to that environment. Do not treat systemctl failing to connect to a bus as proof that every service is broken.

Collect a useful slice of history

Logs become useful when they are bounded by service and time. journalctl -b refers to the current boot; --since limits the time window; --no-pager prints without an interactive pager. Missing or restricted journal entries are an observation, not proof that no error occurred. Some logs need additional privileges to read.

Read status and logs before restarting anything. A restart can change the evidence and interrupt users. For this introductory lab, do not restart or enable a live service. The offline fixture teaches the same reasoning when you do not have a systemd VM.

See it in context

Worked example

These are inspection commands; choose a real unit shown on your own system.

ps -p 1 -o comm=
# On systemd:
systemctl --failed --no-pager
journalctl -b -n 20 --no-pager
# On Alpine/OpenRC instead:
# rc-status

Use the branch that matches your environment. Permission messages or an empty journal should be noted rather than concealed.

Your turn

Practical lab

Explain why an enabled service may still be unavailable. Use this fictional status evidence.

Run commands in your own lab. This website displays instructions; the practice terminal below helps you rehearse the syntax.

1. Prepare your workspace

mkdir -p "$HOME/training4linux/services"
cd "$HOME/training4linux/services"
printf "%s\n" "UNIT=demo.service" "ENABLED=enabled" "ACTIVE=failed" "ERROR=config file missing" > service-evidence.txt

2. Complete the task

  1. Read the evidence and identify the current state and startup configuration separately.
  2. Write the first investigation you would perform before restarting the service.
  3. If you have a systemd VM, inspect a real listed unit with systemctl status and a short journal window. Otherwise explain the supplied fixture.

3. Check your result

  • Your diagnosis says enabled does not mean currently running.
  • Your next check concerns the missing configuration and the service’s expected path.
  • No service state was changed to complete the lab.
Need a hint?

The most useful clue is the actual error, not the startup flag.

Reveal a worked solution

Compare this with your approach after trying the task. More than one valid solution may exist.

cat service-evidence.txt
printf "%s\n" "Current state: failed" "Startup: enabled" "Next: inspect the configured file path and service log before changing anything" > diagnosis.txt
cat diagnosis.txt

After the lab: Only practice text files were created. There is no service to restart or remove.

Common mistakes to avoid

  • A read-permission error is not an empty log.
  • Use the exact unit name from your machine; SSH service names differ across distributions.

Check your understanding

Knowledge check

Answer all 3 questions correctly to pass. Retry as often as you need; your best score is kept.

1. An enabled but failed unit is…
2. What does journalctl -b select?
3. Which is commonly used on Alpine?

Your lesson progress

Not started · Best score: 0% · Attempts: 0

Practical completion is self-reported. Progress is linked to a private cookie in this browser and stored on the site. Clearing that cookie loses access to it. Manage or erase progress.

Keep the reference close

Further reading