如何使用systemd顺序closures和启动Web服务?

我正在尝试使用systemd构buildApache,PHP-FPM和MariaDB服务的closures和启动

这些是/etc/systemd/system文件夹中的其他configuration文件:

 # httpd.service .include /usr/lib/systemd/system/httpd.service [Unit] After=mariadb.service php-fpm.service Before=php-fpm.service # php-fpm.service .include /usr/lib/systemd/system/php-fpm.service [Unit] Before=mariadb.service 

我的目的是在PHP-FPM和MariaDB启动之后启动Apache,并在停止PHP-FPM之前停止Apache,在MariaDB之前停止PHP-FPM。

但是,我在启动和closures时都遇到错误:

 12:42:09 systemd[1]: Found ordering cycle on php-fpm.service/stop 12:42:09 systemd[1]: Found dependency on mariadb.service/stop 12:42:09 systemd[1]: Found dependency on php-fpm.service/stop 12:42:09 systemd[1]: Job httpd.service/stop deleted to break ordering cycle starting with php-fpm.service/stop 12:42:09 systemd[1]: Stopping MariaDB database server... 12:42:12 systemd[1]: Stopped MariaDB database server. 12:42:12 systemd[1]: Stopping The PHP FastCGI Process Manager... 12:42:12 systemd[1]: Failed to remove content of temporary directory /tmp/systemd-mariadb.service-Xp7JJZ5: No such file or directory 12:42:12 systemd[1]: Stopped The PHP FastCGI Process Manager. 12:42:12 systemd[1]: Failed to remove content of temporary directory /tmp/systemd-php-fpm.service-XPLabUE: No such file or directory -- Reboot -- 12:46:20 systemd[1]: Found ordering cycle on php-fpm.service/start 12:46:20 systemd[1]: Found dependency on mariadb.service/start 12:46:20 systemd[1]: Found dependency on php-fpm.service/start 12:46:20 systemd[1]: Job httpd.service/start deleted to break ordering cycle starting with php-fpm.service/start 

看来,我指定的订购周期造成了问题。 这应该如何解决?

据我所知,你有循环依赖。 您告诉systemd在Apache之前启动PHP-fpm,同时在Apache之后启动。 这不能按照你想要的方式工作。

在你的httpd.service文件中指定以下内容:

 Requires=mariadb.service php-fpm.service After=mariadb.service php-fpm.service 

systemd单元文件的选项说明。 它还说,closures顺序将是颠倒的启动顺序,所以你不必单独configuration。 “需要”部分将确保Apache仅在MariaDB和PHP-fpm成功启动时才启动。