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.
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:
/usr/local/bin/process_images.sh.You will be using deeper systemd features today. Your guides:
man systemd.path - your secret weaponman systemd.serviceman systemd.unitTo build this, you must create two linked units. Share your configuration in the comments.
The service file hotfolder.service runs your script.
[Service] section look like?[Install] section?The path file hotfolder.path detects file changes.
[Path] section to watch for new or changed files in /srv/uploads - PathChanged= or PathModified=?systemctl enable --now to start the monitoring?Let’s see your unit files.
# /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
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.