| 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 | |
| 11 | command="/usr/sbin/php-fpm81" |
| 12 | command_background="yes" |
| 13 | start_stop_daemon_args="--quiet" |
| 14 | pidfile="/run/$RC_SVCNAME/php-fpm.pid" |
| 15 | retry="SIGTERM/20" |
| 16 | |
| 17 | # configtest is here only for backward compatibility |
| 18 | extra_commands="checkconfig configtest" |
| 19 | extra_started_commands="reload reopen" |
| 20 | description_checkconfig="Run php-fpm config check" |
| 21 | description_reload="Gracefully reload workers and config" |
| 22 | description_reopen="Reopen log files" |
| 23 | |
| 24 | required_files="$fpm_config" |
| 25 | |
| 26 | depend() { |
| 27 | need net |
| 28 | use apache2 lighttpd nginx |
| 29 | } |
| 30 | |
| 31 | init_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 | |
| 48 | start_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 | |
| 61 | reload() { |
| 62 | ebegin "Reloading $name" |
| 63 | start-stop-daemon --signal USR2 --pidfile "$pidfile" |
| 64 | eend $? |
| 65 | } |
| 66 | |
| 67 | reopen() { |
| 68 | ebegin "Reopening $name log files" |
| 69 | start-stop-daemon --signal USR1 --pidfile "$pidfile" |
| 70 | eend $? |
| 71 | } |
| 72 | |
| 73 | checkconfig() { |
| 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 | |
| 85 | configtest() { |
| 86 | ewarn "configtest is deprecated, use checkconfig instead" |
| 87 | checkconfig |
| 88 | } |
| 89 | |
| 90 | conf_get() { |
| 91 | local key="$1" |
| 92 | sed -nE "s/^${key}\s*=\s*\"?([^\";]+).*/\1/p" "$fpm_config" | head -n 1 |
| 93 | } |