cancel
Showing results for 
Search instead for 
Did you mean: 
TudorRaduta
Community Manager
Community Manager
  • 109 Views

Friday Superboss: Architecting Event-Driven Automation (No Cron!)

Make Linux react the instant a file appears

Happy Friday! Last week we built a secure directory. Today, we are going one level deeper - we are going to make that directory react on its own.

This is a "Superboss" challenge because it pushes you beyond basic RHCSA tasks and into modern systems engineering. We are still in the objective "Deploy, configure, and maintain systems", but this time with a real-world twist.

Most people use cron for automation. But cron has one big flaw: it waits. If your job runs every minute, a user might wait 59 seconds before anything happens.

Today you will design an event-driven system that reacts the instant a file appears.

The Scenario: The "Hot Folder"

You manage a shared directory: /srv/uploads. Users from Windows (Samba) and Linux (SCP/SFTP) drop raw image files in it constantly.

Your architecture must support:

  1. Instant reaction: As soon as a file appears, the system detects it.
  2. Immediate action: It triggers a script at /usr/local/bin/process_images.sh.
  3. No Cron allowed: You must use systemd.path units - the kernel-level event watcher.

The Map:

You will be using deeper systemd features today. Your guides:

  • man systemd.path - your secret weapon
  • man systemd.service
  • man systemd.unit

Your Architect Challenge:

To build this, you must create two linked units. Share your configuration in the comments.

Step 1: The Worker (Service)

The service file hotfolder.service runs your script.

  1. What does the [Service] section look like?
  2. Why does this service not need an [Install] section?

Step 2: The Watcher (Path Unit)

The path file hotfolder.path detects file changes.

  1. Which option will you use in the [Path] section to watch for new or changed files in /srv/uploads - PathChanged= or PathModified=?
  2. How does this Path unit know which Service unit to trigger when it sees a file?

Step 3: Activation

  1. Which unit do you run with systemctl enable --now to start the monitoring?

Let’s see your unit files.

0 Kudos
1 Reply
Psehgaf
Flight Engineer
Flight Engineer
  • 0 Views

# /etc/systemd/system/hotfolder.service
[Unit]
Description=Process new images dropped in /srv/uploads

[Service]
Type=simple
ExecStart=/usr/local/bin/process_images.sh

 

--------------------

NOT need an [Install] section because the service is not meant to be started directly or enabled on boot.
It is launched only when the .path unit triggers it.

systemd.path automatically calls the service, so no [Install] section is required.

You must use:

PathModified=

Because:

PathChanged= detects metadata changes (permissions, ownership, rename)

PathModified= detects content creation or modification

# /etc/systemd/system/hotfolder.path
[Unit]
Description=Watch /srv/uploads and trigger image processing

[Path]
PathModified=/srv/uploads

# Optional but recommended: check directory exists at boot
DirectoryNotEmpty=/srv/uploads

[Install]
WantedBy=multi-user.target

###

It will automatically trigger:

hotfolder.service

----------------------

Enable:

systemctl enable --now hotfolder.path

• ╚╬╦╬Psehgaft╬╦╬╝ ◦
0 Kudos
Join the discussion
You must log in to join this conversation.