service: set TRIGGER_UNIT= and TRIGGER_PATH= on activation by path unit
When a service is triggered by a path unit, pass the path unit name and the path that triggered it via env vars to the spawned processes. Note that this is best-effort, as there might be many triggers at the same time, but we only get woken up by one.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
[Path]
|
||||
PathExistsGlob=/tmp/test63-glob*
|
||||
@@ -0,0 +1,7 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
[Service]
|
||||
ExecStartPre=sh -c 'test "$TRIGGER_PATH" = /tmp/test63-glob-foo'
|
||||
ExecStartPre=sh -c 'test "$TRIGGER_UNIT" = test63-glob.path'
|
||||
ExecStart=systemd-notify --ready
|
||||
RemainAfterExit=yes
|
||||
Type=notify
|
||||
@@ -3,4 +3,6 @@
|
||||
ConditionPathExists=/tmp/nonexistent
|
||||
|
||||
[Service]
|
||||
ExecStartPre=sh -c 'test "$TRIGGER_PATH" = /tmp/test63'
|
||||
ExecStartPre=sh -c 'test "$TRIGGER_UNIT" = test63.path'
|
||||
ExecStart=true
|
||||
|
||||
@@ -28,6 +28,19 @@ test "$(systemctl show test63.service -P Result)" = success
|
||||
test "$(systemctl show test63.path -P ActiveState)" = active
|
||||
test "$(systemctl show test63.path -P Result)" = success
|
||||
|
||||
# Test that glob matching works too, with $TRIGGER_PATH
|
||||
systemctl start test63-glob.path
|
||||
touch /tmp/test63-glob-foo
|
||||
timeout 60 bash -c 'while ! systemctl -q is-active test63-glob.service; do sleep .2; done'
|
||||
test "$(systemctl show test63-glob.service -P ActiveState)" = active
|
||||
test "$(systemctl show test63-glob.service -P Result)" = success
|
||||
|
||||
test "$(busctl --json=short get-property org.freedesktop.systemd1 /org/freedesktop/systemd1/unit/test63_2dglob_2eservice org.freedesktop.systemd1.Unit ActivationDetails)" = '{"type":"a(ss)","data":[["trigger_unit","test63-glob.path"],["trigger_path","/tmp/test63-glob-foo"]]}'
|
||||
|
||||
systemctl stop test63-glob.path test63-glob.service
|
||||
|
||||
test "$(busctl --json=short get-property org.freedesktop.systemd1 /org/freedesktop/systemd1/unit/test63_2dglob_2eservice org.freedesktop.systemd1.Unit ActivationDetails)" = '{"type":"a(ss)","data":[]}'
|
||||
|
||||
systemctl log-level info
|
||||
|
||||
echo OK >/testok
|
||||
|
||||
Reference in New Issue
Block a user