I have ran into a little problem with systemd. I have a php-fpm service running, which has PrivateTmp directive set to true.

There is a cronjob now which is supposed to get some files from the tmp dir of the php-fpm service. However, as the tmp files are located in /tmp/systemd-private-<something>, the script from the cronjob can't find the files, as they are in the PrivateTmp dir of the php-fpm service.

As a solution, I have created a systemd unit, which has a JoinsNamespacesOf directive set to the PHP-fpm service. As indicated by the systemd documentation, it also has a PrivateTmp=true directive. In the end, this should run from .timer unit, but for the time being, I just start it manually.

To see if it's working, I executed /bin/ls /tmp from my own systemd unit, assuming it would show the contents of the private-tmp directory of the PHP-fpm service. Unfortunately, it just showed the contents of the /tmp on the root file system.

I have tried to run various PHP scripts from the the service unit to see if perhaps the PHP process would somehow be aware of the fact that it should look into the PrivateTmp directory of the php-fpm service, but alas, it did not.

Am I doing something completely wrong here or does the JoinsNamespaceOf feature not work as advertised?

Below my systemd unit:

Description=PrivateTmp test

ExecStart=/bin/ls /tmp

ThePrivateTmp value should be in the [Service] part of the unit.

  • Thanks, that almost did the trick. I can create and list files in /tmp, but it only seems to list files from the PrivateTmp of my own systemd unit, not from the php-fpm service. I have updated my systemd unit file in the OP like you suggested, which is the same unit I'm using. – MWesterink Jul 13 '17 at 15:24
  • You should leave the JoinsNamespaceOf under [Unit]. Sorry, I got this wrong in the first version of my answer. It's a pity systemd doesn't complain about these sorts of errors. – meuh Jul 13 '17 at 15:32
  • 1
    No problem, placing it under [Unit] worked. Pity indeed that systemd doesn't show any errors in these kind of cases, would save a lot of people a lot of time and headaches. – MWesterink Jul 13 '17 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.