Created
July 10, 2020 17:32
-
-
Save frankli0324/ab0a8d08407805e6f4110e7805e8d3df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/sbin/openrc-run | |
# 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/local/sbin/php-fpm" | |
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_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 | |
use apache2 lighttpd nginx | |
} | |
init_vars() { | |
# Defaults for single master process with multiple pools | |
if [ "$RC_SVCNAME" = "php-fpm" ]; then | |
: ${fpm_config:="/usr/local/etc/php-fpm.conf"} | |
: ${user:="root"} | |
# Defaults for master process per pool | |
else | |
: ${fpm_config="/usr/local/etc/php-fpm.d/${RC_SVCNAME#php-fpm.}.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() { | |
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 $name" | |
start-stop-daemon --signal USR2 --pidfile "$pidfile" | |
eend $? | |
} | |
reopen() { | |
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM php:7.2-fpm-alpine | |
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/' /etc/apk/repositories | |
RUN apk add --no-cache openrc nginx | |
RUN sed -i 's/#rc_sys=""/rc_sys="lxc"/g' /etc/rc.conf &&\ | |
echo 'rc_provide="loopback net"' >> /etc/rc.conf &&\ | |
sed -i 's/^#\(rc_logger="YES"\)$/\1/' /etc/rc.conf &&\ | |
sed -i '/tty/d' /etc/inittab &&\ | |
sed -i 's/hostname $opts/# hostname $opts/g' /etc/init.d/hostname &&\ | |
sed -i 's/mount -t tmpfs/# mount -t tmpfs/g' /lib/rc/sh/init.sh &&\ | |
sed -i 's/cgroup_add_service /# cgroup_add_service /g' /lib/rc/sh/openrc-run.sh | |
RUN mkdir /run/nginx | |
RUN mkdir /run/openrc | |
RUN touch /run/openrc/softlevel | |
VOLUME [ "/sys/fs/cgroup" ] | |
COPY php-fpm /etc/init.d/php-fpm | |
RUN chmod +x /etc/init.d/php-fpm | |
RUN rc-update add nginx default | |
RUN rc-update add php-fpm default |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment