Skip to content

Commit

Permalink
php-fpm: fix systemd
Browse files Browse the repository at this point in the history
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 <emil.kronborg@protonmail.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
  • Loading branch information
ekronborg authored and kraj committed Jan 31, 2024
1 parent 0ffbe2a commit 4cefe01
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 12 deletions.
57 changes: 52 additions & 5 deletions meta-oe/recipes-devtools/php/php/php-fpm.service
Original file line number Diff line number Diff line change
@@ -1,10 +1,57 @@
# It's not recommended to modify this file in-place, because it
# will be overwritten during upgrades. If you want to customize,
# the best way is to use the "systemctl edit" command.

[Unit]
Description=PHP-FPM
Description=The PHP FastCGI Process Manager
After=network.target

[Service]
Type=forking
PIDFile=/run/php-fpm.pid
ExecStart=@SYSCONFDIR@/init.d/php-fpm start
ExecStop=@SYSCONFDIR@/init.d/php-fpm stop
Type=simple
PIDFile=@LOCALSTATEDIR@/run/php-fpm.pid
ExecStart=@SBINDIR@/php-fpm --nodaemonize --fpm-config /etc/php-fpm.conf
ExecReload=@BINDIR@/kill -USR2 $MAINPID

# Set up a new file system namespace and mounts private /tmp and /var/tmp directories
# so this service cannot access the global directories and other processes cannot
# access this service's directories.
PrivateTmp=true

# Mounts the /usr, /boot, and /etc directories read-only for processes invoked by this unit.
ProtectSystem=full

# Sets up a new /dev namespace for the executed processes and only adds API pseudo devices
# such as /dev/null, /dev/zero or /dev/random (as well as the pseudo TTY subsystem) to it,
# but no physical devices such as /dev/sda.
PrivateDevices=true

# Explicit module loading will be denied. This allows to turn off module load and unload
# operations on modular kernels. It is recommended to turn this on for most services that
# do not need special file systems or extra kernel modules to work.
ProtectKernelModules=true

# Kernel variables accessible through /proc/sys, /sys, /proc/sysrq-trigger, /proc/latency_stats,
# /proc/acpi, /proc/timer_stats, /proc/fs and /proc/irq will be made read-only to all processes
# of the unit. Usually, tunable kernel variables should only be written at boot-time, with the
# sysctl.d(5) mechanism. Almost no services need to write to these at runtime; it is hence
# recommended to turn this on for most services.
ProtectKernelTunables=true

# The Linux Control Groups (cgroups(7)) hierarchies accessible through /sys/fs/cgroup will be
# made read-only to all processes of the unit. Except for container managers no services should
# require write access to the control groups hierarchies; it is hence recommended to turn this on
# for most services
ProtectControlGroups=true

# Any attempts to enable realtime scheduling in a process of the unit are refused.
RestrictRealtime=true

# Restricts the set of socket address families accessible to the processes of this unit.
# Protects against vulnerabilities such as CVE-2016-8655
RestrictAddressFamilies=AF_INET AF_INET6 AF_NETLINK AF_UNIX

# Takes away the ability to create or manage any kind of namespace
RestrictNamespaces=true

[Install]
WantedBy=multi-user.target
17 changes: 10 additions & 7 deletions meta-oe/recipes-devtools/php/php_8.2.9.bb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ CVE_STATUS_PHP = " \
CVE-2007-4596 \
"

inherit autotools pkgconfig python3native gettext multilib_header multilib_script
inherit autotools pkgconfig python3native gettext multilib_header multilib_script systemd

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

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

if ${@bb.utils.contains('PACKAGECONFIG', 'apache2', 'true', 'false', d)}; then
Expand Down Expand Up @@ -259,7 +259,7 @@ FILES:${PN}-cli = "${bindir}/php"
FILES:${PN}-phpdbg = "${bindir}/phpdbg"
FILES:${PN}-phar = "${bindir}/phar*"
FILES:${PN}-cgi = "${bindir}/php-cgi"
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"
FILES:${PN}-fpm = "${sbindir}/php-fpm ${sysconfdir}/php-fpm.conf ${datadir}/fpm ${sysconfdir}/init.d/php-fpm ${sysconfdir}/php-fpm.d/www.conf.default"
FILES:${PN}-fpm-apache2 = "${sysconfdir}/apache2/conf.d/php-fpm.conf"
CONFFILES:${PN}-fpm = "${sysconfdir}/php-fpm.conf"
CONFFILES:${PN}-fpm-apache2 = "${sysconfdir}/apache2/conf.d/php-fpm.conf"
Expand Down Expand Up @@ -290,6 +290,9 @@ RPROVIDES:${PN}-modphp = "${MODPHP_OLDPACKAGE}"
RREPLACES:${PN}-modphp = "${MODPHP_OLDPACKAGE}"
RCONFLICTS:${PN}-modphp = "${MODPHP_OLDPACKAGE}"

SYSTEMD_SERVICE:${PN}-fpm = "php-fpm.service"
SYSTEMD_PACKAGES += "${PN}-fpm"

do_install:append:class-native() {
create_wrapper ${D}${bindir}/php \
PHP_PEAR_SYSCONF_DIR=${sysconfdir}/
Expand Down

0 comments on commit 4cefe01

Please sign in to comment.