When Things Break
Something is wrong. Someone is in the chat asking “is the server down?” Don’t reboot yet. Rebooting destroys evidence, and then it’ll happen again next Tuesday and you’ll know exactly nothing more than you do now.
The first 60 seconds
Section titled “The first 60 seconds”uptime # load average and how long since the last "fix"df -h # disk spacedf -i # inodes. The disk can be "full" with plenty of space left.free -h # memorydmesg -T | tail -50 # kernel complaints: OOM kills, disk errors, the scary stuffsystemctl --failedThat covers most of it. Most outages are a full disk, memory exhaustion, or a service that died and nobody noticed.
Disk is full
Section titled “Disk is full”df -hsudo du -xh --max-depth=1 / 2>/dev/null | sort -h | tailKeep drilling down into the biggest directory. Or install ncdu and save yourself the typing. Usual suspects, in order of how often they’ve ruined my evening:
- Logs.
/var/log, especially an app that logs every request at DEBUG. - The journal.
journalctl --disk-usage, thensudo journalctl --vacuum-size=500M. - Docker.
docker system df. See Docker Storage. - Old kernels / package caches.
sudo apt autoremove && sudo apt clean. - Someone’s
backup-final-v2.tar.gzin their home directory. It’s always there.
“I deleted the file but the space didn’t come back”
Section titled ““I deleted the file but the space didn’t come back””A process still has it open. The space isn’t freed until it closes the file.
sudo lsof +L1 # open files with zero links, i.e. deleted but still heldRestart the process that owns it. Or, if you can’t, truncate it through /proc:
sudo truncate -s 0 /proc/<PID>/fd/<FD>Next time, truncate the log (: > app.log) instead of rm-ing it out from under a running process. And set up logrotate, which exists precisely so you don’t have to do any of this.
Out of inodes
Section titled “Out of inodes”df -h shows space, df -i shows 100%. Millions of tiny files somewhere. Session files, mail queue, a cache directory nobody cleans. Find it:
sudo find / -xdev -type d -size +1M 2>/dev/null # directories so big their listing alone is >1MBOut of memory
Section titled “Out of memory”free -hps aux --sort=-%mem | headdmesg -T | grep -i -E "killed process|out of memory"journalctl -k | grep -i oomIf the OOM killer has been visiting, the kernel picked something to shoot. Often your database, because it was the biggest thing in the room.
High load
Section titled “High load”Load average is the number of processes running or waiting, including waiting on disk. A load of 8 on an 8-core box is busy. A load of 40 is a problem. A load of 40 with idle CPUs means everything is stuck waiting on I/O.
nproc # how many cores, for contexttop # check %wa (I/O wait) in the CPU lineiostat -x 2 # from sysstat. Watch %util on your disks.iotop # who's doing the I/OHigh %wa points at disk: a slow NFS mount, a dying drive, or a backup job someone scheduled during business hours.
Network
Section titled “Network”ip a # addressesip r # routes. "No default route" explains a lot.ss -tulpn # what's listeningcurl -v http://localhost:8080 # does it work locally? If yes, it's the network/firewall/proxy.dig example.com # DNS. It's always DNS. Even when it isn't, check DNS.resolvectl status # on systemd-resolved systems, which DNS server is actually usedThe process for “the website is down”:
- Is the process running? (
systemctl status) - Is it listening? (
ss -tulpn) - Does
curl localhostwork? - Does it work from another machine? If not: firewall (
sudo ufw status,sudo nft list ruleset), security groups, the proxy. - Does the domain resolve to the right IP? Someone changed DNS. Someone always changed DNS.
Before you reboot
Section titled “Before you reboot”If you really have to reboot, grab what you can first:
dmesg -T > /root/dmesg-$(date +%F-%H%M).txtps auxf > /root/ps-$(date +%F-%H%M).txtThen reboot, then check systemctl --failed, then write down what happened. Future you won’t remember. Future you is even more tired than you are.