Php – “phpsessionclean” systemd service won’t run on Ubuntu 18.04 (after update from Ubuntu 14.04)

PHPphp7sessionsystemdubuntu-18.04

After we updated all of our legacy Ubuntu 14 servers to Ubuntu 18, the PHP session files stopped getting cleaned up. I am not sure this is caused by the upgrade itself, but all of our other servers that were either created as Ubuntu 18, or upgraded from Ubuntu 16, this is all working as expected.

The issue is that the systemd service phpsessionclean fails to run. Here's the error it gives me, the same on all said servers:

systemd[22064]: phpsessionclean.service: Failed to set up mount namespacing: No such file or directory
systemd[22064]: phpsessionclean.service: Failed at step NAMESPACE spawning /usr/lib/php/sessionclean: No such file or directory

The /usr/lib/php/sessionclean script definitely exists and I don't see anything unusual about its permissions.

We're on PHP7.2 installed using apt from ppa:ondrej/php

What I have tried:

  • Force reinstalled php7.2, php-common, php7.2-common
  • Disabled and removed phpsessionclean.service and phpsessionclean.timer from systemd and had them both recreated by the apt reinstalls and also copied manually from the servers where these are running ok
  • Deleted and reinstalled the /usr/lib/php/sessionclean script

At this point I don't know what else to try / where else to look. Haven't been able to look up anyone having similar issues. But it's very consistent behaviour across all our servers upgraded from Ubuntu 14.

Workaround I am considering:

Remove the systemd services and change /etc/cron.d/php from:

09,39 *     * * *     root   [ -x /usr/lib/php/sessionclean ] && if [ ! -d /run/systemd/system ]; then /usr/lib/php/sessionclean; fi

to:

09,39 *     * * *     root   if [ -x /usr/lib/php/sessionclean ]; then /usr/lib/php/sessionclean; fi

…and clear the sessions with a cron task (This is currently not clearing because it fails on the check for systemd).

But I am curious to learn why the installed service wouldn't run. Thanks!

Best Answer

systemctl edit phpsessionclean.service

[Service]
PrivateTmp=false
NoNewPrivileges=yes
ProtectHome=false
ProtectSystem=false