Score:1

PHP-FPM starts before the web folder mounts in /etc/fstab, throws error

es flag

I'm running a LAEMP reverse proxy server on Arch in the cloud.

I have my nextcloud/data folder mounted to an attached storage drive at /mnt/hdd/nextcloud/data, linked to /srv/www/nextcloud/data.

If I don't do this, but keep nextcloud/data on the same disk as /, then I don't have this problem at all.

At reboot, the system starts; PHP pages get an error, but neither httpd nor nginx show any errors with systemctl status. The error is in php-fpm.

Output of systemctl status php-fpm:

× php-fpm.service - The PHP FastCGI Process Manager
     Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; preset: disabled)
    Drop-In: /etc/systemd/system/php-fpm.service.d
             └─override.conf
     Active: failed (Result: exit-code) since Tue 2023-05-30 16:47:30 PDT; 14s ago
    Process: 316 ExecStart=/usr/bin/php-fpm --nodaemonize --fpm-config /etc/php/php-fpm.conf (code=exited, status=226/NAMESPACE)
   Main PID: 316 (code=exited, status=226/NAMESPACE)
        CPU: 8ms

May 30 16:47:29 MY_HOST systemd[1]: Starting The PHP FastCGI Process Manager...
May 30 16:47:29 MY_HOST (php-fpm)[316]: php-fpm.service: Failed to set up mount namespacing: /run/systemd/unit-root/mnt/hdd/nextcloud/data: No such file or directory
May 30 16:47:29 MY_HOST (php-fpm)[316]: php-fpm.service: Failed at step NAMESPACE spawning /usr/bin/php-fpm: No such file or directory
May 30 16:47:30 MY_HOST systemd[1]: php-fpm.service: Main process exited, code=exited, status=226/NAMESPACE
May 30 16:47:30 MY_HOST systemd[1]: php-fpm.service: Failed with result 'exit-code'.
May 30 16:47:30 MY_HOST systemd[1]: Failed to start The PHP FastCGI Process Manager.

Nextcloud is getting this from systemd drop-in /etc/systemd/system/php-fpm.service.d/override.conf :

[Service]
...
ReadWritePaths=/srv/www/nextcloud/data

When I run systemctl restart php-fpm, the error goes away forever until the next reboot.

I presume that the php-fpm service can't find the nextcloud folder because hdd/ isn't mounted when php-fpm starts and wants to look in its web folders. I would think that I should somehow adjust the run levels for php-fpm and/or (preferrably) when /etc/fstab loads the attached storage drive to /mnt/hdd.

/etc/fstab mounts the drive /mnt/hdd with this statement:

/dev/vdc1               /mnt/hdd       ext4    defaults,noatime,nofail 0 0

Nothing I search for on the Internet tells me how to solve this problem. Everything in the search results shows unrelated matters about php-fpm or /etc/fstab. Even then, at best I would get some script kiddy answer.

I want to know the proper way to have vdc1 mount much earlier at runtime, or at least have php-fpm wait until the directory is available before throwing a fit.

in flag
Please show your systemd service drop in
Jesse יִשַׁי avatar
es flag
@GeraldSchneider I added the drop-in for php-fpm
Jesse יִשַׁי avatar
es flag
I seem to have mitigated this using monit, at least for the time being. But, the problem remains that a service starts before `/etc/fstab` can mount all drives.
in flag
Please show the output of `systemd-analyze critical-chain php-fpm.service`. And it looks like you omitted lines from the drop in file, please show it completely.
Score:2
in flag

You can configure the systemd unit to be started only after the mounts by adding the following configuration options either to the existing drop in file, or by adding another one if you don't want to modify it:

[Service]
After=local-fs.target

Another option would be to add the following option to the mount definition in fstab:

x-systemd.required-by=php-fpm.service
Jesse יִשַׁי avatar
es flag
the `fstab` option worked like a charm!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.