2

I have added a systemd service to monitor a path, but it is not working. I touched a .txt file under /tmp/test/, but it is not kicking in my service. I can't see "/tmp/testlog.txt" getting generated. Is there anything wrong in my service?

myservice.path

[Unit]
Description=Path Exists

[Path]
PathExistsGlob=/tmp/test/*.txt
PathChanged=/tmp/test/

[Install]
WantedBy=multi-user.target

myservice.service

[Unit]
Description=Test

[Service]
ExecStartPre=/bin/sh -c 'mkdir /tmp/test && sleep 60'
ExecStart=/bin/sh -c 'echo "Test Success" >> /tmp/testlog.txt & '

[Install]
WantedBy=multi-user.target

tmp dir:

# ls /tmp/test/
ab.txt
#

What could be the reason for the failure?

4
  • 1
    See this: stackoverflow.com/questions/7542430/inotify-and-bash Commented Jun 22, 2017 at 21:21
  • Please also show systemctl status myservice.path. I think it needs to be started (and enabled, if you want it to be started on boot).
    – sourcejedi
    Commented Jun 22, 2017 at 22:01
  • Also journalctl --since=-1day -u myservice.service would show if there was an error running the service.
    – sourcejedi
    Commented Jun 22, 2017 at 22:06
  • Cross-posted on SO. Please delete one of the question instances, as per site usage guidelines.
    – AdminBee
    Commented Sep 14, 2023 at 9:29

2 Answers 2

1

That was a timing issue. I added dependency and made this service to start as the very last one. That one solved the issue.

2
  • Which dependency did you add? I'm facing a similar issue.
    – Marvin
    Commented Feb 23, 2018 at 0:57
  • I have a series of my own custom services. Added dependency using the keyword "After" and made this service running as the very last one. That solved my issue.
    – A R
    Commented Mar 5, 2018 at 20:20
0

I had this problem; try adding the following in the [Unit] section:

Wants=observer.service
1
  • Why though? There's no explanation of why this solves the issue.
    – Amar
    Commented Aug 4, 2023 at 5:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .