Start a Service When a File Appears

Master systemd path units to create services that automatically respond to filesystem changes. Learn how to monitor directories and trigger actions when files appear, providing powerful automation capabilities for file processing workflows.

What you'll learn:

  • Creating and managing systemd path units
  • Monitoring directories with PathModified directive
  • Linking path units to service units
  • Setting up file processing workflows
  • Managing path unit lifecycle (enable, start, status, stop)
  • Understanding oneshot service type for file processing

🎯 Real-World Use Cases:

  • Automatic log file processing and rotation
  • Image resizing when photos are uploaded
  • Database import when CSV files appear
  • Email notifications for new documents
  • Backup triggers for important file changes
  • Security scanning of uploaded files

About Systemd Path Units

Systemd path units provide a powerful mechanism for filesystem monitoring and automated response. Unlike traditional file watchers, path units integrate seamlessly with the systemd ecosystem, offering reliable event handling and service lifecycle management.

💡 Essential Concepts:

  • .path units monitor filesystem events
  • PathModified= watches for file/directory changes
  • Unit= specifies which service to trigger
  • Type=oneshot services run once and exit
  • Path units must be enabled and started to monitor
  • Service units are triggered automatically by path events