Prevent a Service from Starting Without Its Data Disk
Premium Challenge
Upgrade your membership to unlock this and all other premium materials.
This challenge continues the story of Recover an Ingestion Service After a VM Upgrade. Solve that one first if you haven't, because the problem below reveals the original cause of the incident.
The ingest-01 server runs ingestd, a service that keeps a large cache of events on a dedicated data disk mounted at /var/lib/ingest.
The size of this cache exceeds the server's root filesystem capacity.
After a recent VM upgrade, the data disk failed to mount, but ingestd started anyway.
It tried to rebuild its cache on the root filesystem and ran out of space.
The mount configuration has been fixed, and the service is working again. But what if the data disk fails to mount next time?
Make sure ingestd can only start when its data filesystem is mounted.
The server itself should still be able to boot without the disk.
Hint 1
If you check the service's unit file with systemctl cat ingest,
you'll see that it already has an After= dependency on var-lib-ingest.mount, the mount unit generated from /etc/fstab.
Look up After= in man systemd.unit.
Does it require the other unit to start successfully, or does it only control the order?
Hint 2
The setting that could help is RequiresMountsFor=. Look it up in man systemd.unit.
It lets you specify a path whose mount units must be started before the service.
Pro tip: Use sudo systemctl edit ingest to add a drop-in configuration rather than modifying the original unit file.
Now let's check whether the change actually works.
The old /dev/xvdf entry is still in /etc/fstab, commented out.
Replace the working UUID=... entry with this old one to simulate another failed mount.
Keep the nofail option, then reboot:
sudo reboot
The server should boot normally even though the data disk fails to mount. The ingestion service, however, must not start.
While systemd is waiting for the missing device, the service should remain stopped. And once the mount fails, the service should fail to start rather than rebuild its cache on the root filesystem.
Hint 3
After the reboot, use systemctl list-jobs to see whether systemd is still waiting for the mount.
Check systemctl status ingest and the boot logs with sudo journalctl -b.
If the service starts without the data filesystem, the dependency isn't working as intended.
Hint 4
The nofail option allows the server to boot even when the data disk is unavailable.
Without it, a failed mount may interrupt the normal boot process and leave the server unreachable over SSH.
The goal is to let the server boot while preventing the ingestion service from starting without its data.
Finally, restore the working UUID=... entry in /etc/fstab and reboot once more.
The data disk should mount automatically, and ingestd should start without any manual intervention.