docker-webserver-nginx/rootfs/app/entrypoint.sh

78 lines
2.1 KiB
Bash
Raw Permalink Normal View History

2024-12-13 09:00:45 +00:00
#!/bin/sh
2024-12-13 10:34:16 +00:00
WEBROOT=/data/www
2024-12-13 09:00:45 +00:00
PHP=${PHP:-none}
USERNAME=${USERNAME:-theuser}
2024-12-15 08:39:25 +00:00
PUID=${PUID:-1000}
GROUPNAME=${GROUPNAME:-thegroup}
PGID=${PGID:-1000}
2024-12-13 09:45:43 +00:00
RANDOMPWD=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 13)
2024-12-15 08:39:25 +00:00
addgroup -g "${PGID}" "${GROUPNAME}"
addgroup nginx "${GROUPNAME}"
adduser -DH -h "${WEBROOT}" -G "${GROUPNAME}" -u "${PUID}" "${USERNAME}"
2024-12-13 10:34:16 +00:00
printf '%s\n%s' "${RANDOMPWD}" "${RANDOMPWD}" | passwd "${USERNAME}"
echo "password for the user \"${USERNAME}\" is: ${RANDOMPWD}"
2024-12-13 09:00:45 +00:00
2024-12-15 08:39:25 +00:00
chown "${PUID}:${GROUPNAME}" "${WEBROOT}" -R
2024-12-13 09:00:45 +00:00
find "${WEBROOT}" -type d -exec chmod 0755 {} \;
find "${WEBROOT}" -type f -exec chmod 0644 {} \;
2024-12-19 07:46:39 +00:00
FPM_MAX_CHILDREN=${FPM_MAX_CHILDREN:-5}
FPM_START_SERVERS=${FPM_START_SERVERS:-1}
FPM_MIN_SPARE_SERVERS=${FPM_MIN_SPARE_SERVERS:-1}
FPM_MAX_SPARE_SERVERS=${FPM_MAX_SPARE_SERVERS:-3}
# set php config
case "${PHP}" in
"php84"|"php83"|"php82")
2024-12-19 11:20:39 +00:00
cat >"/etc/${PHP}/php-fpm.d/www.conf" <<EOF
2024-12-19 07:46:39 +00:00
[www]
user = ${USERNAME}
group = ${GROUPNAME}
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = ${FPM_MAX_CHILDREN}
pm.start_servers = ${FPM_START_SERVERS}
pm.min_spare_servers = ${FPM_MIN_SPARE_SERVERS}
pm.max_spare_servers = ${FPM_MAX_SPARE_SERVERS}
EOF
;;
*) ;;
esac
2024-12-13 10:34:16 +00:00
# start php
2024-12-13 09:00:45 +00:00
case "${PHP}" in
2024-12-15 09:59:53 +00:00
"php84")
cp /app/nginx/php84.conf /etc/nginx/custom.d/
2024-12-16 18:09:18 +00:00
cp /app/nginx/default_php.conf /etc/nginx/http.d/default.conf
2024-12-15 09:59:53 +00:00
/usr/sbin/php-fpm84 -D
;;
"php83")
cp /app/nginx/php83.conf /etc/nginx/custom.d/
2024-12-16 18:09:18 +00:00
cp /app/nginx/default_php.conf /etc/nginx/http.d/default.conf
2024-12-15 09:59:53 +00:00
/usr/sbin/php-fpm83 -D
;;
"php82")
cp /app/nginx/php82.conf /etc/nginx/custom.d/
2024-12-16 18:09:18 +00:00
cp /app/nginx/default_php.conf /etc/nginx/http.d/default.conf
2024-12-15 09:59:53 +00:00
/usr/sbin/php-fpm82 -D
;;
2024-12-16 18:09:18 +00:00
*)
cp /app/nginx/default_nophp.conf /etc/nginx/http.d/default.conf
;;
2024-12-13 09:00:45 +00:00
esac
2024-12-13 10:34:16 +00:00
# start ssh
for keytype in ecdsa rsa ed25519 ; do
if [ ! -r "/ssh/ssh_host_${keytype}_key" ] ; then
/usr/bin/ssh-keygen -t "${keytype}" -f "/ssh/ssh_host_${keytype}_key" -N ""
fi
chmod 0600 "/ssh/ssh_host_${keytype}_key"
chmod 0644 "/ssh/ssh_host_${keytype}_key.pub"
done
chmod 0700 "${WEBROOT}/.ssh"
/usr/sbin/sshd -e
# start nginx
2024-12-13 09:00:45 +00:00
nginx