ar- / incron

cron-like daemon which handles filesystem events
Other
222 stars 52 forks source link

Incrond and NFS Filesystem Monitoring #48

Open nigemar opened 6 years ago

nigemar commented 6 years ago

Hello,

We have noticed an issuing using incron on a NFS mounted file system. I have noticed that incrond and the nfs-client.target start at the same time and if incrond starts before the nfs-client, nfs services are not monitored for file system changes and inotify then doesn't monitor the filesystem.

12:05:18] root@test-box-01 /etc/systemd/system# systemctl status nfs-client.target ● nfs-client.target - NFS client services Loaded: loaded (/usr/lib/systemd/system/nfs-client.target; enabled; vendor preset: disabled) Active: active since Fri 2018-05-25 12:21:25 AEST; 3 days ago

May 25 12:21:25 test-box-01.creditlink.com.au systemd[1]: Reached target NFS client services. May 25 12:21:25 test-box-01.creditlink.com.au systemd[1]: Starting NFS client services.

● incrond.service - Inotify System Scheduler Loaded: loaded (/usr/lib/systemd/system/incrond.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2018-05-25 12:21:25 AEST; 3 days ago Main PID: 689 (incrond) CGroup: /system.slice/incrond.service └─689 /usr/sbin/incrond

May 25 12:21:25 test-box-01.creditlink.com.au systemd[1]: Starting Inotify System Scheduler... May 25 12:21:25 test-box-01.creditlink.com.au incrond[677]: starting service (version 0.5.10, built on Sep 24 2014 19:02:26) May 25 12:21:25 test-box-01.creditlink.com.au incrond[689]: loading system tables May 25 12:21:25 test-box-01.creditlink.com.au incrond[689]: loading user tables May 25 12:21:25 test-box-01.creditlink.com.au incrond[689]: loading table for user wasadmin May 25 12:21:25 test-box-01.creditlink.com.au incrond[689]: ready to process filesystem events May 25 12:21:25 test-box-01.creditlink.com.au systemd[1]: Started Inotify System Scheduler.

Version-Release number of selected component (if applicable):

nfs-utils-1.3.0-0.54.el7.x86_64 incron-0.5.10-8.el7.x86_64

Steps to Reproduce: incrontab entry:

/import IN_CLOSE_WRITE /root/bin/test.sh $@/$#

Script contents /root/bin# cat /root/bin/test.sh

!/bin/bash

filename=$1 echo "$(date) Found File: $1" >> /tmp/test.junk 2>&1

Incron Running once loaded after NFS

[13:18:26] root@test-box-02 /root/bin# echo "This is a test file" > /import/test.junk [13:18:28] root@test-box-02 /root/bin# echo "This is a test file" > /import/test.junk [13:18:29] root@test-box-02 /root/bin# echo "This is a test file" > /import/test.junk [13:18:30] root@test-box-02 /root/bin# echo "This is a test file" > /import/test.junk [13:18:30] root@test-box-02 /root/bin# echo "This is a test file" > /import/test.junk [13:18:32] root@test-box-02 /root/bin# echo "This is a test file" > /import/test.junk

Incron log entries: 2018-05-29T13:18:01.602113+10:00 test-box-02 incrond[28133]: (root) CMD (/root/bin/test.sh /import/test.junk) 2018-05-29T13:18:28.975097+10:00 test-box-02 incrond[28133]: (root) CMD (/root/bin/test.sh /import/test.junk) 2018-05-29T13:18:29.981485+10:00 test-box-02 incrond[28133]: (root) CMD (/root/bin/test.sh /import/test.junk) 2018-05-29T13:18:30.484573+10:00 test-box-02 incrond[28133]: (root) CMD (/root/bin/test.sh /import/test.junk) 2018-05-29T13:18:30.987448+10:00 test-box-02 incrond[28133]: (root) CMD (/root/bin/test.sh /import/test.junk) 2018-05-29T13:18:32.297748+10:00 test-box-02 incrond[28133]: (root) CMD (/root/bin/test.sh /import/test.junk) 2018-05-29T13:18:33.708373+10:00 test-box-02 incrond[28133]: (root) CMD (/root/bin/test.sh /import/test.junk)

Umount and remount NFS Share [13:22:57] root@test-box-02 /root/bin# umount /import/

[13:23:06] root@test-box-02 /root/bin# mount /import/

Run test messages again /root/bin# echo "This is a test file" > /import/test.junk [13:23:38] root@test-box-02 /root/bin# echo "This is a test file" > /import/test.junk [13:23:39] root@test-box-02 /root/bin# echo "This is a test file" > /import/test.junk

Log file not updated 2018-05-29T13:18:33.708373+10:00 test-box-02 incrond[28133]: (root) CMD (/root/bin/test.sh /import/test.junk) 2018-05-29T13:18:52.758378+10:00 test-box-02 incrond[28133]: (root) CMD (/root/bin/test.sh /import/) 2018-05-29T13:18:52.758589+10:00 test-box-02 incrond[28133]: (root) CMD (/root/bin/test.sh /import/)

Entries from 13:23:37,38,39 not included in file /root/bin# cat /tmp/test.junk Found File: /import/test.junk Tue May 29 13:18:28 AEST 2018 Found File: /import/test.junk Tue May 29 13:18:29 AEST 2018 Found File: /import/test.junk Tue May 29 13:18:30 AEST 2018 Found File: /import/test.junk Tue May 29 13:18:30 AEST 2018 Found File: /import/test.junk Tue May 29 13:18:32 AEST 2018 Found File: /import/test.junk Tue May 29 13:18:33 AEST 2018 Found File: /import/test.junk Tue May 29 13:18:52 AEST 2018 Found File: /import/ Tue May 29 13:18:52 AEST 2018 Found File: /import/ [13:24:08] root@test-box-02

Restart incrond [13:24:58] root@test-box-02 /root/bin# systemctl restart incrond

[13:25:20] root@test-box-02 /root/bin# systemctl status incrond ● incrond.service - Inotify System Scheduler Loaded: loaded (/usr/lib/systemd/system/incrond.service; disabled; vendor preset: disabled) Active: active (running) since Tue 2018-05-29 13:25:09 AEST; 13s ago Process: 29263 ExecStart=/usr/sbin/incrond (code=exited, status=0/SUCCESS) Main PID: 29264 (incrond) CGroup: /system.slice/incrond.service └─29264 /usr/sbin/incrond

2018-05-29T13:25:09.599421+10:00 test-box-02 incrond[28133]: stopping service 2018-05-29T13:25:09.608714+10:00 test-box-02 incrond[29263]: starting service (version 0.5.10, built on Sep 24 2014 19:02:26) 2018-05-29T13:25:09.613623+10:00 test-box-02 incrond[29264]: loading system tables 2018-05-29T13:25:09.613880+10:00 test-box-02 incrond[29264]: loading user tables 2018-05-29T13:25:09.614776+10:00 test-box-02 incrond[29264]: loading table for user spuser 2018-05-29T13:25:09.615332+10:00 test-box-02 incrond[29264]: loading table for user root 2018-05-29T13:25:09.617126+10:00 test-box-02 incrond[29264]: ready to process filesystem events

Send test messages:

[13:25:23] root@test-box-02 /root/bin# echo "This is a test file" > /import/test.junk [13:25:32] root@test-box-02 /root/bin# echo "This is a test file" > /import/test.junk

Log file 2018-05-29T13:25:32.045328+10:00 test-box-02 incrond[29264]: (root) CMD (/root/bin/test.sh /import/test.junk) 2018-05-29T13:25:33.552584+10:00 test-box-02 incrond[29264]: (root) CMD (/root/bin/test.sh /import/test.junk)

File has new entries:

Tue May 29 13:25:32 AEST 2018 Found File: /import/test.junk Tue May 29 13:25:33 AEST 2018 Found File: /import/test.junk

I suspect that if there is dependency placed on incrond to wait for nfs-client this will probably go away.

reinierpost commented 4 years ago

I don't think this problem is specific to NFS. A directory must exist at the moment incron is asked to monitor it. You can't ask incron to start monitoring whatever directory with the given path exists whenever one exists, as I expected. I think this limitation should at least be documented.