Lab 7 of 8 · Logs, monitoring and troubleshooting
Break a service on purpose and fix it with a method
Break your status page the way a bad deployment would, find the cause from logs and system checks, fix it, and write a runbook.
- Time
- 45 minutes
- Cost
- Free.
What you learn
When something breaks at 3 a.m., a calm method beats guessing: check the service, read the logs, check resources, change one thing, and write down what fixed it.
- A repeatable troubleshooting method
- Filtering logs with journalctl
- Checking CPU, memory and disk with uptime, free, df and vmstat
- Writing a runbook other people can follow
In the AI era: AI is good at suggesting causes from an error message. Give it the real log lines with secrets, hostnames and addresses removed, then confirm its suggestion with evidence before you change anything.
Get set up
Commands use Homebrew in the Terminal app. Already have a tool? Skip it.
- A terminalOfficial install page ↗
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Use the Terminal app. The command installs Homebrew, which the other macOS commands use.
Before you start
Finish lab 4 (you need the
status-pageservice).Start your server and open your repository: run
multipass start sysadmin-labandmultipass shell sysadmin-labon your computer, thencd linux-admin-labon the server.
Step by step
1 Take a health snapshot
Knowing what normal looks like makes problems easier to spot.
uptime free -h df -h / vmstat 1 5 systemctl --failed --no-pagerYou should see:Load averages, memory, disk use, five lines of activity, and
0 loaded units listed.2 Break the service
This simulates a bad deployment: the unit now points at a program that does not exist. If your unit has a different
ExecStart, change its program path to a wrong one by hand.sudo sed -i 's#/usr/bin/python3#/usr/bin/python4#' /etc/systemd/system/status-page.service sudo systemctl daemon-reload sudo systemctl restart status-page sleep 15 curl -s http://localhost:8080 || echo "The status page is down"You should see:The status page is down.3 Investigate: status first, then logs
Start broad and narrow down.
systemctl status status-page --no-pager journalctl -u status-page -n 20 --no-pager systemctl --failed --no-pagerYou should see:activating (auto-restart)orfailed, with status203/EXEC, and log lines saying the program could not be run.4 Ask AI for likely causes, then confirm one
Paste the log lines into your AI assistant and ask for the most likely cause and how to confirm it. They contain nothing secret here; on a real server, remove hostnames, addresses and tokens first. Confirm before changing anything:
systemctl cat status-page | grep ExecStart ls -l /usr/bin/python4 /usr/bin/python3You should see:python4does not exist andpython3does. The evidence, not the AI's confidence, confirms the cause.5 Fix it and confirm
Change one thing, then prove it worked.
sudo sed -i 's#/usr/bin/python4#/usr/bin/python3#' /etc/systemd/system/status-page.service sudo systemctl daemon-reload sudo systemctl reset-failed status-page sudo systemctl restart status-page curl -s http://localhost:8080You should see:Your
<h1>line again.6 Write the runbook
A runbook lets someone else fix this at 3 a.m. without you. Create it with
mkdir -p runbooksandnano runbooks/status-page-down.md, and add one more cause you can think of.# Runbook: status page is down ## Symptoms - `curl http://localhost:8080` fails, or someone reports the page is down. ## Check, in this order 1. `systemctl status status-page --no-pager`: is it running? What is the result? 2. `journalctl -u status-page -n 50 --no-pager`: the latest errors. 3. `free -h` and `df -h /`: is the server out of memory or disk? 4. `sudo ss -tlnp | grep 8080`: is something else using the port? ## Known causes and fixes | Cause | How to confirm | Fix | |-------|----------------|-----| | Wrong program path in the unit (`203/EXEC`) | `systemctl cat status-page` | Correct `ExecStart`, then `daemon-reload` and `restart` | | ... | ... | ... | ## After fixing - Run `sudo systemctl reset-failed status-page` and confirm with `curl`. - Write down what happened, when, and what fixed it.7 Commit and push
Save your work to GitHub from the server.
git add runbooks git commit -m "Add status page troubleshooting runbook" git push
You are done when
You found the cause from
systemctl statusandjournalctl, not by guessing.You confirmed the AI's suggestion with evidence before changing anything.
runbooks/status-page-down.mdis on GitHub.
We check your public GitHub repository and give you a page to share with recruiters, and can add the project to your resume.