1

I have a very weird problem that I might not have cooked down correctly, but I tried a minimal example:

In a 20.04 lxd container on 20.04, I am trying to run a job triggered by incron. For my minimal example, this is my incron line:

/home/scanfiler/test    IN_CLOSE_WRITE  /home/scanfiler/test.sh &>> /tmp/log-scanfiler-test

This is my test script

#!/bin/bash
logger "Starting"
touch /tmp/test/test-$(date +%s)-1
touch ~/test_out/test-$(date +%s)-1
sleep 20
touch /tmp/test/test-$(date +%s)-2
touch ~/test_out/test-$(date +%s)-2
logger "Done"

I am writing to the log, then I am creating one file in the home folder and one in the tmp folder, then I am waiting 20 seconds (this to give me time to check DURING runtime, in case tmp is somehow immediately cleared), then I am writing to more files.

This is what happens:

scanfiler ~scanfiler # rm test/testblah && touch test/testblah
scanfiler ~scanfiler # journalctl -xe|tail
Aug 17 14:59:26 scanfiler incrond[2526]: PATH (/home/scanfiler/test) FILE (testblah) EVENT (IN_CLOSE_WRITE)
Aug 17 14:59:26 scanfiler incrond[2526]: (scanfiler) CMD (/home/scanfiler/test.sh &>> /tmp/log-scanfiler-test)
Aug 17 14:59:26 scanfiler scanfiler[1250558]: Starting
scanfiler ~scanfiler # 
scanfiler ~scanfiler # ls /tmp/test 
scanfiler ~scanfiler # ls test_out 
test-1597669166-1
scanfiler ~scanfiler # journalctl -xe|tail
Aug 17 14:59:26 scanfiler incrond[2526]: PATH (/home/scanfiler/test) FILE (testblah) EVENT (IN_CLOSE_WRITE)
Aug 17 14:59:26 scanfiler incrond[2526]: (scanfiler) CMD (/home/scanfiler/test.sh &>> /tmp/log-scanfiler-test)
Aug 17 14:59:26 scanfiler scanfiler[1250558]: Starting
scanfiler ~scanfiler # journalctl -xe|tail
Aug 17 14:59:26 scanfiler incrond[2526]: PATH (/home/scanfiler/test) FILE (testblah) EVENT (IN_CLOSE_WRITE)
Aug 17 14:59:26 scanfiler incrond[2526]: (scanfiler) CMD (/home/scanfiler/test.sh &>> /tmp/log-scanfiler-test)
Aug 17 14:59:26 scanfiler scanfiler[1250558]: Starting
Aug 17 14:59:46 scanfiler scanfiler[1250627]: Done
scanfiler ~scanfiler # ls /tmp/test       
scanfiler ~scanfiler # ls test_out                                
test-1597669166-1  test-1597669186-2
scanfiler ~scanfiler # ls /tmp/log-scanfiler-test
ls: cannot access '/tmp/log-scanfiler-test': No such file or directory

As you can see, even during runtime, the tmp file is NOT created, while the one in the home directory is there. Eventually, not even the log file that is supposed to be in tmp is there. When run by the same user in console, everything works fine, so my tmp permissions are probably not somehow broken.

Can anybody give me a clue what is happening here? I have more weird issues in my scripts (which runs fine when run in console), but maybe they are related, so I would like to solve this first.

2
  • Ok, now I am seeing that stuff is showing up in /tmp/systemd-private-...-incron.service-... How do I turn that off?
    – mcandril
    Aug 17, 2020 at 13:35
  • Step further ... PrivateTmp=true in the service file for incron ...
    – mcandril
    Aug 17, 2020 at 13:43

1 Answer 1

1

Ok, as hinted in the comments, I figured it out. I am leaving this answer because I did not find anything on google regarding incron (or cron) and tmp directories, and the mechanisms seems rather new (it wasn't there in my old 18.04 installation).

The systemd service for incron has the line

PrivateTmp=true

which causes the service to have a private tmp directory below /tmp. I did not want this behavior, so I disabled it using

 systemctl edit --full incron.service

and removing the line (which creates a new version of the original service file from /lib/... in /etc/...).

I THINK I also observed some further weird behavior before this with permission issues inside the private tmp directory, but I didn't investigate further because I needed a global tmp for other reasons anyway.

You must log in to answer this question.

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