projects/aports·blob master · refs

93 lines · 2.4 KiB

1#!/sbin/openrc-run
2
3# If you want to run separate master process per pool, then create a symlink
4# to this runscript for each pool. In that mode, the php-fpm daemon is started
5# as nobody by default. You can override the user (and group) by declaring
6# variable "user" and optionally "group" in conf.d file, or in the $fpm_config
7# file (the former has precedence).
8
9: ${name:="PHP FastCGI Process Manager"}
10
11command="/usr/sbin/php-fpm81"
12command_background="yes"
13start_stop_daemon_args="--quiet"
14pidfile="/run/$RC_SVCNAME/php-fpm.pid"
15retry="SIGTERM/20"
16
17# configtest is here only for backward compatibility
18extra_commands="checkconfig configtest"
19extra_started_commands="reload reopen"
20description_checkconfig="Run php-fpm config check"
21description_reload="Gracefully reload workers and config"
22description_reopen="Reopen log files"
23
24required_files="$fpm_config"
25
26depend() {
27 need net
28 use apache2 lighttpd nginx
29}
30
31init_vars() {
32 # Defaults for single master process with multiple pools
33 if [ "$RC_SVCNAME" = "php-fpm81" ]; then
34 : ${fpm_config:="/etc/php81/php-fpm.conf"}
35 : ${user:="root"}
36 # Defaults for master process per pool
37 else
38 : ${fpm_config="/etc/php81/php-fpm.d/${RC_SVCNAME#php-fpm81.}.conf"}
39 : ${user:="$(conf_get user)"}
40 : ${user:="nobody"}
41 : ${group:="$(conf_get group)"}
42 fi
43 command_args="--nodaemonize --fpm-config $fpm_config"
44 start_stop_daemon_args="$start_stop_daemon_args
45 --user $user ${group:+"--group $group"}"
46}
47
48start_pre() {
49 checkconfig || return 1
50
51 # If unix socket is used (instead of TCP/IP), then ensure that the
52 # directory exists and has correct privileges.
53 local listen="$(conf_get listen)"
54 if [ "${listen:0:1}" = "/" ]; then
55 checkpath -d -o $user:$group "$(dirname "$listen")"
56 fi
57
58 checkpath -d "$(dirname "$pidfile")"
59}
60
61reload() {
62 ebegin "Reloading $name"
63 start-stop-daemon --signal USR2 --pidfile "$pidfile"
64 eend $?
65}
66
67reopen() {
68 ebegin "Reopening $name log files"
69 start-stop-daemon --signal USR1 --pidfile "$pidfile"
70 eend $?
71}
72
73checkconfig() {
74 init_vars
75 ebegin "Checking $fpm_config"
76
77 local out
78 out="$(su -s /bin/sh -c "$command --test --fpm-config $fpm_config" $user 2>&1)" || {
79 printf "%s\n" "$out"
80 eend 1 "failed, please correct errors above"
81 return 1
82 }
83}
84
85configtest() {
86 ewarn "configtest is deprecated, use checkconfig instead"
87 checkconfig
88}
89
90conf_get() {
91 local key="$1"
92 sed -nE "s/^${key}\s*=\s*\"?([^\";]+).*/\1/p" "$fpm_config" | head -n 1
93}