Systemd Path triggered service, only runs once, Config error or misunderstanding documentation?
by MickeJ from LinuxQuestions.org on (#6F89N)
Hi all :)
I am using Systemd path unit to monitor a file and to run a service when the file is modified. This works as expected the first time, the path unit trigger on file modification and runs the service unit.
But the service only runs once, i expected the service to run again if the file was modified during the service runtime. (I am running services under --user and not system, does it matter?)
From the documentation...
https://www.freedesktop.org/software...temd.path.html
Quote:
So...
Service unit file
Code:[Unit]
Description=Testing Hello World.
[Service]
Type=notify
ExecStart=/home/user/.local/bin/systemd_test.sh
NotifyAccess=all
[Install]
WantedBy=default.targetPath unit file
Code:[Unit]
Description=Monitor file for changes.
[Path]
PathModified=/home/user/.config/test.txt
[Install]
WantedBy=default.targetmy example test app that only runs once
Code:#!/usr/bin/env bash
set -eu
_main() {
systemd-notify --ready
sleep 20
}
_main "$@"
I am using Systemd path unit to monitor a file and to run a service when the file is modified. This works as expected the first time, the path unit trigger on file modification and runs the service unit.
But the service only runs once, i expected the service to run again if the file was modified during the service runtime. (I am running services under --user and not system, does it matter?)
From the documentation...
https://www.freedesktop.org/software...temd.path.html
Quote:
When a service unit triggered by a path unit terminates (regardless whether it exited successfully or failed), monitored paths are checked immediately again, and the service accordingly restarted instantly. |
- file is modified
- systemd path unit notice and triggers the service
- service starts
- file is modified again while service is runnning
- service stops
- ...service is NOT restarted
Service unit file
Code:[Unit]
Description=Testing Hello World.
[Service]
Type=notify
ExecStart=/home/user/.local/bin/systemd_test.sh
NotifyAccess=all
[Install]
WantedBy=default.targetPath unit file
Code:[Unit]
Description=Monitor file for changes.
[Path]
PathModified=/home/user/.config/test.txt
[Install]
WantedBy=default.targetmy example test app that only runs once
Code:#!/usr/bin/env bash
set -eu
_main() {
systemd-notify --ready
sleep 20
}
_main "$@"