Skip to content

Commit 4cefe01

Browse files
ekronborgkraj
authored andcommitted
php-fpm: fix systemd
2848cc9 ("php-fpm: Add support for systemd") introduced a systemd service file, where ExecStart and ExecStop uses /etc/init.d/php-fpm, which does not exist if systemd is enabled. Consequently, the php-fpm service fails to start even though it is correctly installed. This is fixed by this commit in which the service file is identical to the one from the PHP source code except for the use of BitBake variables. Also, use ${systemd_system_unitdir} instead of ${systemd_unitdir}/system. Signed-off-by: Emil Kronborg <[email protected]> Signed-off-by: Khem Raj <[email protected]>
1 parent 0ffbe2a commit 4cefe01

File tree

2 files changed

+62
-12
lines changed

2 files changed

+62
-12
lines changed
Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,57 @@
1+
# It's not recommended to modify this file in-place, because it
2+
# will be overwritten during upgrades. If you want to customize,
3+
# the best way is to use the "systemctl edit" command.
4+
15
[Unit]
2-
Description=PHP-FPM
6+
Description=The PHP FastCGI Process Manager
37
After=network.target
8+
49
[Service]
5-
Type=forking
6-
PIDFile=/run/php-fpm.pid
7-
ExecStart=@SYSCONFDIR@/init.d/php-fpm start
8-
ExecStop=@SYSCONFDIR@/init.d/php-fpm stop
10+
Type=simple
11+
PIDFile=@LOCALSTATEDIR@/run/php-fpm.pid
12+
ExecStart=@SBINDIR@/php-fpm --nodaemonize --fpm-config /etc/php-fpm.conf
13+
ExecReload=@BINDIR@/kill -USR2 $MAINPID
14+
15+
# Set up a new file system namespace and mounts private /tmp and /var/tmp directories
16+
# so this service cannot access the global directories and other processes cannot
17+
# access this service's directories.
18+
PrivateTmp=true
19+
20+
# Mounts the /usr, /boot, and /etc directories read-only for processes invoked by this unit.
21+
ProtectSystem=full
22+
23+
# Sets up a new /dev namespace for the executed processes and only adds API pseudo devices
24+
# such as /dev/null, /dev/zero or /dev/random (as well as the pseudo TTY subsystem) to it,
25+
# but no physical devices such as /dev/sda.
26+
PrivateDevices=true
27+
28+
# Explicit module loading will be denied. This allows to turn off module load and unload
29+
# operations on modular kernels. It is recommended to turn this on for most services that
30+
# do not need special file systems or extra kernel modules to work.
31+
ProtectKernelModules=true
32+
33+
# Kernel variables accessible through /proc/sys, /sys, /proc/sysrq-trigger, /proc/latency_stats,
34+
# /proc/acpi, /proc/timer_stats, /proc/fs and /proc/irq will be made read-only to all processes
35+
# of the unit. Usually, tunable kernel variables should only be written at boot-time, with the
36+
# sysctl.d(5) mechanism. Almost no services need to write to these at runtime; it is hence
37+
# recommended to turn this on for most services.
38+
ProtectKernelTunables=true
39+
40+
# The Linux Control Groups (cgroups(7)) hierarchies accessible through /sys/fs/cgroup will be
41+
# made read-only to all processes of the unit. Except for container managers no services should
42+
# require write access to the control groups hierarchies; it is hence recommended to turn this on
43+
# for most services
44+
ProtectControlGroups=true
45+
46+
# Any attempts to enable realtime scheduling in a process of the unit are refused.
47+
RestrictRealtime=true
48+
49+
# Restricts the set of socket address families accessible to the processes of this unit.
50+
# Protects against vulnerabilities such as CVE-2016-8655
51+
RestrictAddressFamilies=AF_INET AF_INET6 AF_NETLINK AF_UNIX
52+
53+
# Takes away the ability to create or manage any kind of namespace
54+
RestrictNamespaces=true
55+
956
[Install]
1057
WantedBy=multi-user.target

meta-oe/recipes-devtools/php/php_8.2.9.bb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ CVE_STATUS_PHP = " \
4444
CVE-2007-4596 \
4545
"
4646

47-
inherit autotools pkgconfig python3native gettext multilib_header multilib_script
47+
inherit autotools pkgconfig python3native gettext multilib_header multilib_script systemd
4848

4949
# phpize is not scanned for absolute paths by default (but php-config is).
5050
#
@@ -193,11 +193,11 @@ do_install:append:class-target() {
193193
install -m 0644 ${WORKDIR}/php-fpm-apache.conf ${D}/${sysconfdir}/apache2/conf.d/php-fpm.conf
194194

195195
if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)};then
196-
install -d ${D}${systemd_unitdir}/system
197-
install -m 0644 ${WORKDIR}/php-fpm.service ${D}${systemd_unitdir}/system/
198-
sed -i -e 's,@SYSCONFDIR@,${sysconfdir},g' \
199-
-e 's,@LOCALSTATEDIR@,${localstatedir},g' \
200-
${D}${systemd_unitdir}/system/php-fpm.service
196+
install -d ${D}${systemd_system_unitdir}
197+
install -m 0644 ${WORKDIR}/php-fpm.service ${D}${systemd_system_unitdir}/php-fpm.service
198+
sed -i -e 's,@LOCALSTATEDIR@,${localstatedir},g' ${D}${systemd_system_unitdir}/php-fpm.service
199+
sed -i -e 's,@SBINDIR@,${sbindir},g' ${D}${systemd_system_unitdir}/php-fpm.service
200+
sed -i -e 's,@BINDIR@,${bindir},g' ${D}${systemd_system_unitdir}/php-fpm.service
201201
fi
202202

203203
if ${@bb.utils.contains('PACKAGECONFIG', 'apache2', 'true', 'false', d)}; then
@@ -259,7 +259,7 @@ FILES:${PN}-cli = "${bindir}/php"
259259
FILES:${PN}-phpdbg = "${bindir}/phpdbg"
260260
FILES:${PN}-phar = "${bindir}/phar*"
261261
FILES:${PN}-cgi = "${bindir}/php-cgi"
262-
FILES:${PN}-fpm = "${sbindir}/php-fpm ${sysconfdir}/php-fpm.conf ${datadir}/fpm ${sysconfdir}/init.d/php-fpm ${systemd_unitdir}/system/php-fpm.service ${sysconfdir}/php-fpm.d/www.conf.default"
262+
FILES:${PN}-fpm = "${sbindir}/php-fpm ${sysconfdir}/php-fpm.conf ${datadir}/fpm ${sysconfdir}/init.d/php-fpm ${sysconfdir}/php-fpm.d/www.conf.default"
263263
FILES:${PN}-fpm-apache2 = "${sysconfdir}/apache2/conf.d/php-fpm.conf"
264264
CONFFILES:${PN}-fpm = "${sysconfdir}/php-fpm.conf"
265265
CONFFILES:${PN}-fpm-apache2 = "${sysconfdir}/apache2/conf.d/php-fpm.conf"
@@ -290,6 +290,9 @@ RPROVIDES:${PN}-modphp = "${MODPHP_OLDPACKAGE}"
290290
RREPLACES:${PN}-modphp = "${MODPHP_OLDPACKAGE}"
291291
RCONFLICTS:${PN}-modphp = "${MODPHP_OLDPACKAGE}"
292292

293+
SYSTEMD_SERVICE:${PN}-fpm = "php-fpm.service"
294+
SYSTEMD_PACKAGES += "${PN}-fpm"
295+
293296
do_install:append:class-native() {
294297
create_wrapper ${D}${bindir}/php \
295298
PHP_PEAR_SYSCONF_DIR=${sysconfdir}/

0 commit comments

Comments
 (0)