大网数据广告活动
服务器运维问答

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

· 52CE 我爱测

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 nex…

问题原文

原帖链接 · Jesse · CC BY-SA 4.0

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.

已采纳解答

原帖链接 · Jesse · CC BY-SA 4.0

While another answer helped for a time with a statement inside /etc/fstab, modifying the .service file ended up being my more reliable solution...

We need some statements in the service config, but under [Unit], not [Service], somewhat like:

[Unit]
Requires=local-fs.target
After=local-fs.target

But, the question is where to put them and what the values should be for Requires= and After=.

We need a service drop-in override config.

The service is php-fpm, with its original config file at /lib/systemd/system/php-fpm.service. However, modifying that is not persistent since it is replaced by upgrades. Instead, an override file needed to be made, with any name and the .conf extension in /etc/systemd/system/php-fpm.service.d/. While /etc/systemd/system/ should already exist with many things in it, the php-fpm.service.d/ subfolder may need to be created.

Based on /etc/fstab :

UUID=long-uuid-serial-c0de1  /mnt/ssd       ext4    defaults,noatime,nofail,x-systemd.required-by=php-fpm.service 0 0 
UUID=long-uuid-serial-c0de2  /mnt/hdd       ext4    defaults,noatime,nofail,x-systemd.required-by=php-fpm.service 0 0

This command:

systemctl list-units --type=mount

returns many lines, including these:

  mnt-hdd.mount                 loaded active mounted /mnt/hdd
  mnt-ssd.mount                 loaded active mounted /mnt/ssd

which we recognize from /etc/fstab as /mnt/hdd and /mnt/ssd.

So, we need this file:

/etc/systemd/system/php-fpm.service.d/mount.conf :

[Unit]
Requires=mnt-hdd.mount
After=mnt-hdd.mount
Requires=mnt-ssd.mount
After=mnt-ssd.mount

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2023-05-30)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。