diff options
author | Jakub Jirutka <jakub@jirutka.cz> | 2016-09-22 01:41:24 +0200 |
---|---|---|
committer | Jakub Jirutka <jakub@jirutka.cz> | 2016-09-22 01:52:53 +0200 |
commit | e6fd4a5cf8d0ee7990a3c37d088e9b48f6245b95 (patch) | |
tree | 0388b0f3d2bdfa113c3ca602c6ac4898ea4cad7e /community/php7/php7-fpm.initd | |
parent | e3a54f061a9c88a49044b6e80172ff7760e6c144 (diff) | |
download | aports-e6fd4a5cf8d0ee7990a3c37d088e9b48f6245b95.tar.bz2 aports-e6fd4a5cf8d0ee7990a3c37d088e9b48f6245b95.tar.xz |
community/php7: rewrite runscript, allow to run multiple masters
Diffstat (limited to 'community/php7/php7-fpm.initd')
-rw-r--r-- | community/php7/php7-fpm.initd | 86 |
1 files changed, 72 insertions, 14 deletions
diff --git a/community/php7/php7-fpm.initd b/community/php7/php7-fpm.initd index 1016c68f0d..f56fdb5234 100644 --- a/community/php7/php7-fpm.initd +++ b/community/php7/php7-fpm.initd @@ -1,35 +1,93 @@ #!/sbin/openrc-run -name="PHP7 FastCGI Process Manager" -cfgfile="/etc/php7/php-fpm.conf" -pidfile="/var/run/php-fpm7.pid" +# If you want to run separate master process per pool, then create a symlink +# to this runscript for each pool. In that mode, the php-fpm daemon is started +# as nobody by default. You can override the user (and group) by declaring +# variable "user" and optionally "group" in conf.d file, or in the $fpm_config +# file (the former has precedence). + +: ${name:="PHP FastCGI Process Manager"} + command="/usr/sbin/php-fpm7" -command_args="--fpm-config $cfgfile --pid $pidfile" -required_files="$cfgfile" +command_background="yes" +start_stop_daemon_args="--quiet" +pidfile="/run/$RC_SVCNAME/php-fpm.pid" +retry="SIGTERM/20" +# configtest is here only for backward compatibility +extra_commands="checkconfig configtest" extra_started_commands="reload reopen" -description_reload="Reload configuration" +description_checkconfig="Run php-fpm config check" +description_reload="Gracefully reload workers and config" description_reopen="Reopen log files" +required_files="$fpm_config" + depend() { need net - before apache2 lighttpd nginx + use apache2 lighttpd nginx +} + +init_vars() { + # Defaults for single master process with multiple pools + if [ "$RC_SVCNAME" = "php-fpm7" ]; then + : ${fpm_config:="/etc/php7/php-fpm.conf"} + : ${user:="root"} + # Defaults for master process per pool + else + : ${fpm_config="/etc/php7/php-fpm.d/${RC_SVCNAME#php-fpm7.}.conf"} + : ${user:="$(conf_get user)"} + : ${user:="nobody"} + : ${group:="$(conf_get group)"} + fi + command_args="--nodaemonize --fpm-config $fpm_config" + start_stop_daemon_args="$start_stop_daemon_args + --user $user ${group:+"--group $group"}" } start_pre() { - ebegin - $command $command_args -t 2>/dev/null - eend $? + checkconfig || return 1 + + # If unix socket is used (instead of TCP/IP), then ensure that the + # directory exists and has correct privileges. + local listen="$(conf_get listen)" + if [ "${listen:0:1}" = "/" ]; then + checkpath -d -o $user:$group "$(dirname "$listen")" + fi + + checkpath -d "$(dirname "$pidfile")" } reload() { - ebegin "Reloading ${SVCNAME} configuration" - start-stop-daemon --signal USR2 --pidfile $pidfile + ebegin "Reloading $name" + start-stop-daemon --signal USR2 --pidfile "$pidfile" eend $? } reopen() { - ebegin Reopening ${SVCNAME} log files"" - start-stop-daemon --signal USR1 --pidfile $pidfile + ebegin "Reopening $name log files" + start-stop-daemon --signal USR1 --pidfile "$pidfile" eend $? } + +checkconfig() { + init_vars + ebegin "Checking $fpm_config" + + local out + out="$(su -s /bin/sh -c "$command --test --fpm-config $fpm_config" $user 2>&1)" || { + printf "%s\n" "$out" + eend 1 "failed, please correct errors above" + return 1 + } +} + +configtest() { + ewarn "configtest is deprecated, use checkconfig instead" + checkconfig +} + +conf_get() { + local key="$1" + sed -nE "s/^${key}\s*=\s*\"?([^\";]+).*/\1/p" "$fpm_config" | head -n 1 +} |