php8/conf/start.sh

110 lines
2.8 KiB
Bash

#!/bin/bash
/usr/sbin/useradd -d /home/www -s /bin/false -M ${APACHE_RUN_USER}
/usr/sbin/adduser ${APACHE_RUN_USER} crontab
mkdir -p /home/www/log
touch /home/www/log/msmtp.log
apt update && apt upgrade -y
if [[ ! $RUN_USER == lokaal ]]; then
USER_UID=`echo ${APACHE_RUN_USER} | tr -d '{p,f},'`
if echo ${APACHE_RUN_USER} | grep "p" ; then
sed -i "s/1000/10${USER_UID}/g" /etc/passwd
sed -i "s/1000/10${USER_UID}/g" /etc/group
fi
if echo ${APACHE_RUN_USER} | grep "f" ;then
sed -i "s/1000/20${USER_UID}/g" /etc/passwd
sed -i "s/1000/20${USER_UID}/g" /etc/group
fi
if echo ${APACHE_RUN_USER} | grep "s" ;then
sed -i "s/1000/3${USER_UID}/g" /etc/passwd
sed -i "s/1000/3${USER_UID}/g" /etc/group
fi
fi
sed -i "s/memory_limit = 128M/memory_limit = ${PHP_MEMORY_LIMIT}/g" /etc/php/8.0/apache2/php.ini
sed -i 's@;mail.log = syslog@mail.log = /home/www/log/mail.log@g' /etc/php/8.0/apache2/php.ini
sed -i 's@SMTP = localhost@SMTP = smtp.rug.nl@g' /etc/php/8.0/apache2/php.ini
echo "$APACHE_SERVERNAME" > /etc/mailname
cat> /etc/php/8.0/apache2/conf.d/10-opcache.ini << EOF
zend_extension=opcache.so
opcache.enable=1
opcache.validate_timestamps=1
opcache.revalidate_freq=60
opcache.max_accelerated_files=10000
opcache.memory_consumption=64
opcache.interned_strings_buffer=8
opcache.fast_shutdown=1
EOF
. /etc/tpl/001-docker.tpl > /etc/apache2/sites-enabled/001-docker.conf
if [ ! -d ${APACHE_DOCUMENTROOT} ]; then
mkdir ${APACHE_DOCUMENTROOT} -p
chown ${APACHE_RUN_USER}:${APACHE_RUN_USER} $APACHE_DOCUMENTROOT
fi
[[ -d $APACHE_LOG_DIR ]] || mkdir -p $APACHE_LOG_DIR && chown $APACHE_RUN_USER:$APACHE_RUN_USER $APACHE_LOG_DIR
if [ ! -d ${APACHE_CRON_DIR} ]; then
mkdir ${APACHE_CRON_DIR} -p
touch ${APACHE_CRON_DIR}/${APACHE_RUN_USER}
chmod 600 ${APACHE_CRON_DIR}/${APACHE_RUN_USER}
chown -R ${APACHE_RUN_USER}:crontab ${APACHE_CRON_DIR}/${APACHE_RUN_USER}
fi
if [ ! -d ${APACHE_CGI_DIR} ]; then
mkdir ${APACHE_CGI_DIR} -p
chmod 755 ${APACHE_CGI_DIR}
chown -R ${APACHE_RUN_USER}:${APACHE_RUN_USER} ${APACHE_CGI_DIR}
fi
cp ${APACHE_CRON_DIR}/${APACHE_RUN_USER} /var/spool/cron/crontabs/${APACHE_RUN_USER}
chmod 600 /var/spool/cron/crontabs/${APACHE_RUN_USER}
chown -R ${APACHE_RUN_USER}:crontab /var/spool/cron/crontabs/${APACHE_RUN_USER}
cat << EOF > /etc/msmtprc
defaults
port 25
logfile ${APACHE_LOG_DIR}/mail.log
tls off
account rug
host smtp.rug.nl
from no-reply@${APACHE_SERVERNAME}
auth off
# Set a default account
account default: rug
aliases /etc/aliases
EOF
chmod 666 ${APACHE_LOG_DIR}/msmtp.log
cat << EOF > /etc/logrotate.d/apache2
${APACHE_LOG_DIR}/*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
sharedscripts
create 664 root ${APACHE_RUN_USER}
postrotate
/usr/sbin/apachectl graceful > /dev/null 2>/dev/null || true
endscript
}
EOF
/etc/init.d/cron start
exec "$@"