Skip to main content

Which process wakes up my HDD at 8 AM?!

 Having a NAS with mechanical disks and a door open to your bedroom because of the heatwave may be problematic during the night if the disks spin up and start crunching.

In my case, the crunching noise happens every day at 8:00. Ok, maybe I like to sleep in and not hear crrrrr-crrrr-clack-clack as a wake-up call.

Time to find the culprit. Since the NAS is running a vanilla Ubuntu and the disks are used only for cold storage, I kind-of know why they spin up each time they do. Most likely some cron process is running at 8:00 and interrogating the disks.

Checking the crontab, all user's crontab, /etc/crontab, /etc/cron.d/* doesn't show anything obvious starting at 8:00. There could be some long-term running process which decides to index something at 8 o'clock, or there could be some external process on some other server that uses NFS or SSH to access some data on the NAS. 

I decided to learn something new and use auditd to monitor file access to my /media/wdc mountpoint at 8:00 and see if I can figure out what's going on.

So - Step 0: Install and start auditd:

$ sudo apt-get install auditd

$ sudo service auditd start

Step 1: Set up a trigger to log read-write-execute access to files and directories under /media/wdc and add a tag of "test-hdd" for the logs

$ sudo /usr/sbin/auditctl -w /media/wdc/ -p warx -k test-hdd

But I'm not running it all the time, just enable it at 8:00 via cron:

0 8 * * * /usr/sbin/auditctl -w /media/wdc/ -p warx -k test-hdd

What gets enabled automatically should also get disabled, so at 8:03 I'm deleting the rules:

3 8 * * * /usr/sbin/auditctl -D -k test-hdd

Step 2: Wait for morning to come. This time I'm prepared!

Step 3: Once 8:00 happened, I can search the logs collected with:

# ausearch -k test-hdd --interpret | grep proctitle  | cut -d ':' -f 5 | sort -u

Let's see what's going on:

proctitle=find /media/wdc/storage3TB/backup/ -type f -name README
 proctitle=/usr/bin/python3 /usr/local/bin/borg info /media/wdc/storage3TB/backup/borg_aldebaran/borg_aldebaran
 proctitle=/usr/bin/python3 /usr/local/bin/borg info /media/wdc/storage3TB/backup/borg_hc4/borg_hc4
 proctitle=/usr/bin/python3 /usr/local/bin/borg info /media/wdc/storage3TB/backup/borg_stingray/borg_stingray
 proctitle=/usr/bin/python3 /usr/local/bin/borg list --last 1 /media/wdc/storage3TB/backup/borg_aldebaran/borg_aldebaran
 proctitle=/usr/bin/python3 /usr/local/bin/borg list --last 1 /media/wdc/storage3TB/backup/borg_hc4/borg_hc4
 proctitle=/usr/bin/python3 /usr/local/bin/borg list --last 1 /media/wdc/storage3TB/backup/borg_stingray/borg_stingray
 proctitle=/usr/bin/python3 /usr/local/bin/borg list /media/wdc/storage3TB/backup/borg_aldebaran/borg_aldebaran
 proctitle=/usr/bin/python3 /usr/local/bin/borg list /media/wdc/storage3TB/backup/borg_hc4/borg_hc4
 proctitle=/usr/bin/python3 /usr/local/bin/borg list /media/wdc/storage3TB/backup/borg_stingray/borg_stingray

Aha! So that file access is generated by a script that checks the health of my backups. I remember I created that script, but it's not run by cron. Perhaps it's a systemd service that does this.

# systemctl | grep borg
  prometheus-borg-exporter.timer              loaded active waiting   Prometheus Borg Exporter Timer

So it's a timer! Systemd's equivalent for cron:

# cat /etc/systemd/system/prometheus-borg-exporter.timer
[Unit]
Description=Prometheus Borg Exporter Timer

[Timer]
OnCalendar= *-*-* 8:00:00

[Install]
WantedBy=timers.target

Got you! I had completely forgot I played with timers at some point. I had to remember the hard way.

Changing the timer here allowed me to wake up gently in the screams of my hungry kids, just like God intended...



Comments

Popular posts from this blog

Home Assistant + Android TV = fun

Here's a quick setup guide for controlling your Android TV from within Home Assistant. I've used it to control a genuine Android TV (Philips 7304) and an Odroid N2 running Android TV. For this to work you need ADB access. It can usually be enabled from within Developer Settings. The great part is - you don't need root access! The most important things are described in the androidtv component for Home Assistant: https://www.home-assistant.io/integrations/androidtv/ Make sure you go through the adb setup. My configuration is simple (inside configuration.yaml): media_player:   - platform: androidtv     name: TV Bedroom ATV     host: 192.168.1.61     device_class: androidtv Once Home Assistant restarts, your TV might require you to accept the connection (adb authentication). This happens only once (or until you reset your ATV to factory settings). Once running the integration will show you the current ATV state (on or off) and allows you to turn it on or off.

SmokePing + InfluxDB export + docker + slaves + Grafana = fun

I've been working for a while on this project - with the purpose of getting SmokePing measurements from different hosts (slaves) into InfluxDB so that we can better graph them with Grafana. The slaves run multiple Smokeping instances inside Docker so that they have separate networking (measure through different uplinks, independently). This will not be a comprehensive configuration guide, but a quick "how to" to handle setup and basic troubleshooting. It assumes you already know how to set up and operate a regular Smokeping install with or without slaves and that you are fluent in Smokeping configuration syntax, know your way around Docker and aren't a stranger from InfluxDB and Grafana (sorry, there's a lot of information to take in). 1. Getting Smokeping with InfluxDB support - you can get it either from the official page (most changes have been merged) - https://github.com/oetiker/SmokePing (PR discussion here: https://github.com/oetiker/SmokePing/issues/

Installing Home Assistant Supervised on an old 32bit HP laptop

 I've received a challenge from my former boss: an old HP laptop that was born in 2005:  an HP-Compaq NC6220 ( https://www.pocket-lint.com/laptops/reviews/hp/68181-hp-compaq-nc6220-notebook-laptop/ ). The specs are abysmal: So, i386, 1.7GHz single-core CPU (remember those?), 1G of DDR2 RAM (2x512M) and a 40GB ATA (not SATA!) drive. But hey, at least it has a serial port!  The challenge is to install HomeAssistant ( https://www.home-assistant.io/ ) on it so that he can monitor some Zigbee temperature sensors and relays (via a gateway). The first hurdle was to remove the BIOS password - following this nice guide: https://www.youtube.com/watch?v=ZaGKyb0ntSg Next-up - install HASSOS. Unfortunately, it doesn't support i386, but only x86_64... So, I went the Home Assistant Supervised route, and installed Debian 11 i386 edition from a netinstall USB ( https://cdimage.debian.org/debian-cd/current/i386/iso-cd/debian-11.6.0-i386-netinst.iso ).   Once Debian was up and running (didn't