Skip to main content

systemd.path — File-Based Task Trigger

systemd.path is a built-in systemd mechanism that monitors files or directories for changes and automatically activates a corresponding .service unit when a filesystem event occurs. Instead of polling with cron or writing fragile inotifywait loops, you declare a tiny .path unit file and let the kernel handle the rest.

Who This Track Is For
  • Linux administrators managing WordPress VPS, web servers, or any production workload
  • DevOps engineers building event-driven automation pipelines
  • Developers who need instant reactions to file changes without manual SSH
What You Will Build
  • Event-driven file watchers that trigger services instantly
  • Drop-folder queues that process files one at a time
  • Signal-file patterns for remote cache flush, deployment, and maintenance
  • Production-hardened path units with rate limiting and security sandboxing
How To Use This Track
  • Follow the lessons in order (1 → 9). Each lesson builds on concepts from the previous one.
  • Every lesson includes hands-on examples with expected output — run them on a test server.
  • Treat this documentation as a reference after the first read-through.

Learning Path

ModuleFocusWhat You Learn
1. How It WorksArchitecture and lifecycleTwo-unit model, event loop, kernel inotify integration
2. Watch DirectivesThe 5 watch directives deep divePathExists, PathChanged, PathModified, DirectoryNotEmpty, PathExistsGlob
3. Unit File AnatomyComplete unit file referenceEvery directive in [Path], [Unit], [Service], [Install]
4. Commands and ManagementCLI operationssystemctl, journalctl, daemon-reload, user units
5. Practical Examples20 complete examplesDrop folders, signal files, config watchers, glob triggers
6. Production PatternsHardening and reliabilitySecurity sandboxing, rate limiting, timer fallback
7. Debugging and TroubleshootingRoot-cause debuggingCommon failures, inotify limits, step-by-step workflow
8. Study CasesReal-world scenariosWordPress VPS, CI/CD, media pipeline, multi-tenant SaaS
9. Cheatsheet and QuizQuick referenceOne-page cheat sheet, 10-question quiz, hands-on lab

Architecture at a Glance

Why systemd.path Over Alternatives

ApproachPolling?Built-in?Concurrency Safe?Logging?
systemd.pathNo (event-driven)YesYes (oneshot queuing)journald native
Cron + test -fYes (every minute)YesNoManual
inotifywait loopNoRequires inotify-toolsNoManual
Custom daemonNoNoDependsManual

System Check

systemctl --version # Expected: systemd 230+ (path units require 230+)

Quick Start

5-minute-quick-start.sh
# 1) Create a service that processes dropped files
sudo tee /etc/systemd/system/test-drop.service > /dev/null <<'EOF'
[Unit]
Description=Process files from the test drop folder

[Service]
Type=oneshot
ExecStart=/bin/sh -c 'echo "[$(date +%%F\ %%T)] Processing:" && ls /tmp/drop && rm -f /tmp/drop/*'
EOF

# 2) Create a path unit that watches the folder
sudo tee /etc/systemd/system/test-drop.path > /dev/null <<'EOF'
[Unit]
Description=Watch /tmp/drop for incoming files

[Path]
DirectoryNotEmpty=/tmp/drop
MakeDirectory=yes

[Install]
WantedBy=paths.target
EOF

# 3) Activate
sudo systemctl daemon-reload
sudo systemctl enable --now test-drop.path

# 4) Test it
touch /tmp/drop/hello.txt
sleep 1
journalctl -u test-drop.service -n 10 --no-pager

Terminology

TermMeaning
Path unitA .path file that defines what filesystem event to watch
Service unitA .service file that defines what command to run
Unit pairThe .path + .service combination (same base name by default)
Watch directiveThe PathExists=, PathChanged=, etc. line in the [Path] section
Trigger fileA file whose existence or modification activates the path unit
Signal fileAn empty file created to signal an action (e.g., deploy.me)
Drop folderA directory where files are placed for automated processing
inotifyThe Linux kernel subsystem that provides filesystem event notifications
paths.targetThe systemd target that groups all path units
daemon-reloadThe command that tells systemd to re-read unit files from disk

Next Step

Start with How It Works to understand the two-unit model and event-driven lifecycle.