问题和问题
Ubuntu 服务器 18.04 LTS。
在 PHP-FPM 上使用systemctl restart
不会在 中创建所需的套接字/var/run/php/
,但会重新启动。
如何调整我的设置以允许在不重新启动的情况下重新启动服务?
概述
我正在单个服务器(无容器)上从源代码编译多个 PHP-FPM 实例,以用于各种年龄的 Web 应用程序。我已经成功地同时设置了 PHP 7.1、PHP 7.2 和 PHP 7.3。它们都在启动时正确启动,它们都有一个套接字/var/run/php/
,它们都按浏览器的预期响应。
/var/run/php
开机后的内容
/var/run/php$ ls -l
total 0
srw-rw---- 1 www-data www-data 0 Apr 2 12:57 php7.1-fpm.sock
srw-rw---- 1 www-data www-data 0 Apr 2 12:57 php7.2-fpm.sock
srw-rw---- 1 www-data www-data 0 Apr 2 12:57 php7.3-fpm.sock
每个服务似乎都在正常运行。这是systemctl status
每个的输出:
启动后的 PHP 7.1
~$ sudo systemctl status php7.1-fpm
● php7.1-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/etc/systemd/system/php7.1-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-04-02 12:57:51 UTC; 21min ago
Main PID: 875 (php-fpm)
Tasks: 3 (limit: 1152)
CGroup: /system.slice/php7.1-fpm.service
├─875 php-fpm: master process (/etc/php/7.1/etc/php-fpm.conf)
├─970 php-fpm: pool www
└─971 php-fpm: pool www
Apr 02 12:57:51 darwin systemd[1]: Started The PHP FastCGI Process Manager.
启动后的 PHP 7.2
~$ sudo systemctl status php7.2-fpm
● php7.2-fpm.service - The PHP FastCGI Process Manager (7.2)
Loaded: loaded (/etc/systemd/system/php7.2-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-04-02 12:57:51 UTC; 22min ago
Main PID: 837 (php-fpm)
Tasks: 3 (limit: 1152)
CGroup: /system.slice/php7.2-fpm.service
├─837 php-fpm: master process (/etc/php/7.2/etc/php-fpm.conf)
├─963 php-fpm: pool www
└─964 php-fpm: pool www
Apr 02 12:57:51 darwin systemd[1]: Started The PHP FastCGI Process Manager (7.2).
启动后 PHP 7.3
~$ sudo systemctl status php7.3-fpm
● php7.3-fpm.service - The PHP FastCGI Process Manager (7.3)
Loaded: loaded (/etc/systemd/system/php7.3-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-04-02 12:57:51 UTC; 23min ago
Main PID: 836 (php-fpm)
Tasks: 3 (limit: 1152)
CGroup: /system.slice/php7.3-fpm.service
├─836 php-fpm: master process (/etc/php/7.3/etc/php-fpm.conf)
├─965 php-fpm: pool www
└─966 php-fpm: pool www
Apr 02 12:57:51 darwin systemd[1]: Started The PHP FastCGI Process Manager (7.3).
如果我对相应的php.ini
文件进行更改,则需要重新启动服务以处理更改。在我的情况下,当我使用systemctl restart
(eg sudo systemctl restart php7.1-fpm
) 重新启动服务时,服务似乎会正常重新启动,但所有 PHP 套接字都被删除——无论我重新启动的版本是什么。
之后没有控制台输出systemctl restart
,当我检查systemctl status
重新启动的服务(例如上一段中的 PHP 7.1)时,该服务正在运行:
PHP 7.1 之后systemctl restart
~$ sudo systemctl status php7.1-fpm
● php7.1-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/etc/systemd/system/php7.1-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-04-02 13:28:06 UTC; 28s ago
Main PID: 1704 (php-fpm)
Tasks: 3 (limit: 1152)
CGroup: /system.slice/php7.1-fpm.service
├─1704 php-fpm: master process (/etc/php/7.1/etc/php-fpm.conf)
├─1718 php-fpm: pool www
└─1722 php-fpm: pool www
Apr 02 13:28:06 darwin systemd[1]: Stopped The PHP FastCGI Process Manager.
Apr 02 13:28:06 darwin systemd[1]: Started The PHP FastCGI Process Manager.
请注意 上的时间戳差异Active
。如果我以相同的方式查询其他服务(注意:它们没有被我重新启动),时间戳是从启动时的初始启动开始的:
PHP 7.2systemctl restart
在 PHP 7.1之后
~$ sudo systemctl status php7.2-fpm
● php7.2-fpm.service - The PHP FastCGI Process Manager (7.2)
Loaded: loaded (/etc/systemd/system/php7.2-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-04-02 12:57:51 UTC; 33min ago
Main PID: 837 (php-fpm)
Tasks: 3 (limit: 1152)
CGroup: /system.slice/php7.2-fpm.service
├─837 php-fpm: master process (/etc/php/7.2/etc/php-fpm.conf)
├─963 php-fpm: pool www
└─964 php-fpm: pool www
Apr 02 12:57:51 darwin systemd[1]: Started The PHP FastCGI Process Manager (7.2).
PHP 7.3systemctl restart
在 PHP 7.1之后
~$ sudo systemctl status php7.3-fpm
● php7.3-fpm.service - The PHP FastCGI Process Manager (7.3)
Loaded: loaded (/etc/systemd/system/php7.3-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-04-02 12:57:51 UTC; 34min ago
Main PID: 836 (php-fpm)
Tasks: 3 (limit: 1152)
CGroup: /system.slice/php7.3-fpm.service
├─836 php-fpm: master process (/etc/php/7.3/etc/php-fpm.conf)
├─965 php-fpm: pool www
└─966 php-fpm: pool www
Apr 02 12:57:51 darwin systemd[1]: Started The PHP FastCGI Process Manager (7.3).
…然而所有的套接字都不见了:
PHP 7.1/var/run/php
之后的内容systemctl restart
$ ls -l
total 0
我的直觉是我在.service
没有意识到的情况下破坏了文件中的某些内容。虽然我一直在进行故障排除,但我注意到我为 PID 和套接字使用了不同的目录。PID不会在引导时创建,因为/run/php-fpm/
它不存在。我有一个模糊的记忆,被建议不要将套接字和 PID 保存在同一目录中,但我不记得确切的细节。
PHP 7.1.service
文件
[Unit]
Description=The PHP FastCGI Process Manager
After=network.target
[Service]
Type=simple
RuntimeDirectory=php
RuntimePermissions=755
PIDFile=/run/php-fpm/php7.1-fpm.pid
ExecStart=/etc/php/7.1/sbin/php-fpm --nodaemonize --fpm-config /etc/php/7.1/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
提前感谢您的任何指示或进一步阅读。
经过进一步调查,我发现我的单位文件中缺少一条
RuntimeDirectoryPreserve
指令。当服务停止时,将RuntimeDirectory
被删除……连同套接字。摘自systemd.exec
修订(工作)单元文件: