mirror of
https://github.com/devilbox/docker-php-fpm.git
synced 2025-12-10 11:01:14 +00:00
Fixes #105 Allow to start postfix without Email catch-all
This commit is contained in:
@@ -22,70 +22,83 @@ set_postfix() {
|
||||
local debug="${7}"
|
||||
|
||||
local php_ini_file="${php_ini_dir}/devilbox-runtime-sendmail.ini"
|
||||
local catch_all=
|
||||
local enable_mail=
|
||||
|
||||
# Verify env value
|
||||
if ! env_set "${env_varname}"; then
|
||||
log "info" "\$${env_varname} not set." "${debug}"
|
||||
log "info" "Postfix will not be started." "${debug}"
|
||||
echo "" > "${php_ini_file}"
|
||||
else
|
||||
catch_all="$( env_get "${env_varname}" )"
|
||||
if [ "${catch_all}" = "1" ]; then
|
||||
log "info" "\$${env_varname} set to 1. Enabling postfix catch-all" "${debug}"
|
||||
return
|
||||
fi
|
||||
|
||||
# Configure PHP
|
||||
{
|
||||
echo "[mail function]";
|
||||
echo "sendmail_path = $( which sendmail ) -t -i";
|
||||
echo ";mail.force_extra_parameters =";
|
||||
echo "mail.add_x_header = On";
|
||||
echo "mail.log = ${php_mail_log}";
|
||||
} > "${php_ini_file}"
|
||||
# Retrieve env value
|
||||
enable_mail="$( env_get "${env_varname}" )"
|
||||
|
||||
# PHP mail function logs to file
|
||||
if [ "${docker_logs}" != "1" ]; then
|
||||
# Fix PHP mail log file dir/file and permissions
|
||||
if [ ! -d "$( dirname "${php_mail_log}" )" ]; then
|
||||
run "mkdir -p $( dirname "${php_mail_log}" )" "${debug}"
|
||||
fi
|
||||
if [ ! -f "${php_mail_log}" ]; then
|
||||
run "touch ${php_mail_log}" "${debug}"
|
||||
fi
|
||||
run "chown ${username}:${groupname} $( dirname "${php_mail_log}" )" "${debug}"
|
||||
run "chown ${username}:${groupname} ${php_mail_log}" "${debug}"
|
||||
run "chmod 0644 ${php_mail_log}" "${debug}"
|
||||
# Enable postfix
|
||||
if [ "${enable_mail}" = "1" ] || [ "${enable_mail}" = "2" ]; then
|
||||
|
||||
if [ "${enable_mail}" = "1" ]; then
|
||||
log "info" "\$${env_varname} set to 1. Enabling postfix" "${debug}"
|
||||
else
|
||||
log "info" "\$${env_varname} set to 2. Enabling postfix catch-all" "${debug}"
|
||||
fi
|
||||
|
||||
# Configure PHP
|
||||
{
|
||||
echo "[mail function]";
|
||||
echo "sendmail_path = $( command -v sendmail ) -t -i";
|
||||
echo ";mail.force_extra_parameters =";
|
||||
echo "mail.add_x_header = On";
|
||||
echo "mail.log = ${php_mail_log}";
|
||||
} > "${php_ini_file}"
|
||||
|
||||
# PHP mail function logs to file
|
||||
if [ "${docker_logs}" != "1" ]; then
|
||||
# Fix PHP mail log file dir/file and permissions
|
||||
if [ ! -d "$( dirname "${php_mail_log}" )" ]; then
|
||||
run "mkdir -p $( dirname "${php_mail_log}" )" "${debug}"
|
||||
fi
|
||||
|
||||
# Add Mail dir/file if it does not exist
|
||||
if [ ! -d "/var/mail" ]; then
|
||||
run "mkdir /var/mail" "${debug}"
|
||||
fi
|
||||
if [ ! -f "/var/mail/${username}" ]; then
|
||||
run "touch /var/mail/${username}" "${debug}"
|
||||
if [ ! -f "${php_mail_log}" ]; then
|
||||
run "touch ${php_mail_log}" "${debug}"
|
||||
fi
|
||||
run "chown ${username}:${groupname} $( dirname "${php_mail_log}" )" "${debug}"
|
||||
run "chown ${username}:${groupname} ${php_mail_log}" "${debug}"
|
||||
run "chmod 0644 ${php_mail_log}" "${debug}"
|
||||
fi
|
||||
|
||||
# Fix mail dir/file permissions after mount
|
||||
run "chmod 0644 /var/mail/${username}" "${debug}"
|
||||
run "chown ${username}:${groupname} /var/mail" "${debug}"
|
||||
run "chown ${username}:${groupname} /var/mail/${username}" "${debug}"
|
||||
# Add Mail dir/file if it does not exist
|
||||
if [ ! -d "/var/mail" ]; then
|
||||
run "mkdir /var/mail" "${debug}"
|
||||
fi
|
||||
if [ ! -f "/var/mail/${username}" ]; then
|
||||
run "touch /var/mail/${username}" "${debug}"
|
||||
fi
|
||||
|
||||
# warning: specify "strict_mailbox_ownership = no" to ignore mailbox ownership mismatch
|
||||
run "postconf -e 'strict_mailbox_ownership=no'" "${debug}"
|
||||
# Fix mail dir/file permissions after mount
|
||||
run "chmod 0644 /var/mail/${username}" "${debug}"
|
||||
run "chown ${username}:${groupname} /var/mail" "${debug}"
|
||||
run "chown ${username}:${groupname} /var/mail/${username}" "${debug}"
|
||||
|
||||
# Postfix configuration
|
||||
run "postconf -e 'inet_protocols=ipv4'" "${debug}"
|
||||
# warning: specify "strict_mailbox_ownership = no" to ignore mailbox ownership mismatch
|
||||
run "postconf -e 'strict_mailbox_ownership=no'" "${debug}"
|
||||
|
||||
# Postfix configuration
|
||||
run "postconf -e 'inet_protocols=ipv4'" "${debug}"
|
||||
|
||||
# Postfix catch-all
|
||||
if [ "${enable_mail}" = "2" ]; then
|
||||
run "postconf -e 'virtual_alias_maps=pcre:/etc/postfix/virtual'" "${debug}"
|
||||
run "echo '/.*@.*/ ${username}' >> /etc/postfix/virtual" "${debug}"
|
||||
|
||||
run "newaliases" "${debug}"
|
||||
|
||||
elif [ "${catch_all}" = "0" ]; then
|
||||
log "info" "\$${env_varname} set to 0. Disabling postfix catch-all" "${debug}"
|
||||
|
||||
else
|
||||
log "err" "Invalid value for \$${env_varname}. Can only be 0 or 1. Prodived: ${catch_all}" "${debug}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
elif [ "${enable_mail}" = "0" ]; then
|
||||
log "info" "\$${env_varname} set to 0. Disabling postfix" "${debug}"
|
||||
|
||||
else
|
||||
log "err" "Invalid value for \$${env_varname}. Can only be 0, 1 or 2. Prodived: ${enable_mail}" "${debug}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -24,9 +24,6 @@ DVL_PHP_INI_DIR="/usr/local/etc/php/conf.d"
|
||||
# php-fpm conf.d directory
|
||||
DVL_PHP_FPM_DIR="/usr/local/etc/php-fpm.d"
|
||||
|
||||
# This is the log file for any mail related functions
|
||||
DVL_PHP_MAIL_LOG="/var/log/mail.log"
|
||||
|
||||
# This file holds error and access log definitions
|
||||
DVL_PHP_FPM_CONF_LOGFILE="${DVL_PHP_FPM_DIR}/zzz-entrypoint-logfiles.conf"
|
||||
DVL_PHP_INI_CONF_LOGFILE="${DVL_PHP_INI_DIR}/zzz-entrypoint-logfiles.ini"
|
||||
@@ -34,6 +31,9 @@ DVL_PHP_INI_CONF_LOGFILE="${DVL_PHP_INI_DIR}/zzz-entrypoint-logfiles.ini"
|
||||
# PHP-FPM log dir
|
||||
DVL_FPM_LOG_DIR="/var/log/php"
|
||||
|
||||
# This is the log file for any mail related functions
|
||||
DVL_PHP_MAIL_LOG="${DVL_FPM_LOG_DIR}/mail.log"
|
||||
|
||||
# Custom ini dir (to be copied to actual ini dir)
|
||||
DVL_PHP_CUST_INI_DIR="/etc/php-custom.d"
|
||||
|
||||
@@ -138,7 +138,7 @@ done
|
||||
###
|
||||
### Supervisor: rsyslogd & postfix
|
||||
###
|
||||
if [ "$( env_get "ENABLE_MAIL" )" = "1" ]; then
|
||||
if [ "$( env_get "ENABLE_MAIL" )" = "1" ] || [ "$( env_get "ENABLE_MAIL" )" = "2" ]; then
|
||||
supervisor_add_service "rsyslogd" "/usr/sbin/rsyslogd -n" "${DVL_SUPERVISOR_CONFD}" "${DEBUG_LEVEL}" "1"
|
||||
supervisor_add_service "postfix" "/usr/local/sbin/postfix.sh" "${DVL_SUPERVISOR_CONFD}" "${DEBUG_LEVEL}"
|
||||
fi
|
||||
|
||||
@@ -22,14 +22,7 @@ set -o pipefail
|
||||
###
|
||||
### Variables
|
||||
###
|
||||
if [ -f "/etc/alpine-release" ]; then
|
||||
MAILLOG="/var/log/maillog"
|
||||
elif [ -f "/etc/debian_version" ]; then
|
||||
MAILLOG="/var/log/mail.log"
|
||||
else
|
||||
MAILLOG="/var/log/maillog"
|
||||
fi
|
||||
|
||||
MAILLOG="/var/log/mail.log"
|
||||
MAILPID="/var/spool/postfix/pid/master.pid"
|
||||
|
||||
|
||||
|
||||
@@ -24,9 +24,6 @@ DVL_PHP_INI_DIR="/usr/local/etc/php/conf.d"
|
||||
# php-fpm conf.d directory
|
||||
DVL_PHP_FPM_DIR="/usr/local/etc/php-fpm.d"
|
||||
|
||||
# This is the log file for any mail related functions
|
||||
DVL_PHP_MAIL_LOG="/var/log/mail.log"
|
||||
|
||||
# This file holds error and access log definitions
|
||||
DVL_PHP_FPM_CONF_LOGFILE="${DVL_PHP_FPM_DIR}/zzz-entrypoint-logfiles.conf"
|
||||
DVL_PHP_INI_CONF_LOGFILE="${DVL_PHP_INI_DIR}/zzz-entrypoint-logfiles.ini"
|
||||
@@ -34,6 +31,9 @@ DVL_PHP_INI_CONF_LOGFILE="${DVL_PHP_INI_DIR}/zzz-entrypoint-logfiles.ini"
|
||||
# PHP-FPM log dir
|
||||
DVL_FPM_LOG_DIR="/var/log/php"
|
||||
|
||||
# This is the log file for any mail related functions
|
||||
DVL_PHP_MAIL_LOG="${DVL_FPM_LOG_DIR}/mail.log"
|
||||
|
||||
# Custom ini dir (to be copied to actual ini dir)
|
||||
DVL_PHP_CUST_INI_DIR="/etc/php-custom.d"
|
||||
|
||||
@@ -138,7 +138,7 @@ done
|
||||
###
|
||||
### Supervisor: rsyslogd & postfix
|
||||
###
|
||||
if [ "$( env_get "ENABLE_MAIL" )" = "1" ]; then
|
||||
if [ "$( env_get "ENABLE_MAIL" )" = "1" ] || [ "$( env_get "ENABLE_MAIL" )" = "2" ]; then
|
||||
supervisor_add_service "rsyslogd" "/usr/sbin/rsyslogd -n" "${DVL_SUPERVISOR_CONFD}" "${DEBUG_LEVEL}" "1"
|
||||
supervisor_add_service "postfix" "/usr/local/sbin/postfix.sh" "${DVL_SUPERVISOR_CONFD}" "${DEBUG_LEVEL}"
|
||||
fi
|
||||
|
||||
@@ -798,7 +798,7 @@ Have a look at the following table to see all supported environment variables fo
|
||||
<td><code>ENABLE_MAIL</code></td>
|
||||
<td>bool</td>
|
||||
<td><code>0</code></td>
|
||||
<td>Enable local email catch-all.<br/>Postfix will be configured for local delivery and all mails sent (even to real domains) will be catched locally. No email will ever go out. They will all be stored in a local devilbox account.<br/>Value: <code>0</code> or <code>1</code></td>
|
||||
<td>Start local postfix with or without email catch-all.<br/><code>0</code>: Postfix service disabled.<br/><code>1</code>: Postfix service started normally.<br/><code>2</code>: Postfix service started configured for local delivery and all mails sent (even to real domains) will be catched locally. No email will ever go out. They will all be stored in a local devilbox account.<br/>Value: <code>0</code>, <code>1</code> or <code>2</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>FORWARD_PORTS_TO_LOCALHOST</code></td>
|
||||
@@ -871,7 +871,7 @@ Have a look at the following table to see all offered volumes for each Docker im
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>/var/mail</code></td>
|
||||
<td>Emails caught be the postfix catch-all (<code>ENABLE_MAIL=1</code>) will be available in this directory.</td>
|
||||
<td>Emails caught be the postfix catch-all (<code>ENABLE_MAIL=2</code>) will be available in this directory.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3"></td>
|
||||
@@ -1186,12 +1186,12 @@ $ docker run -d \
|
||||
|
||||
#### Launch Postfix for mail-catching
|
||||
|
||||
Once you set `$ENABLE_MAIL=1`, all mails sent via any of your PHP applications no matter to which domain, are catched locally into the `devilbox` account. You can also mount the mail directory locally to hook in with mutt and read those mails.
|
||||
Once you set `$ENABLE_MAIL=2`, all mails sent via any of your PHP applications no matter to which domain, are catched locally into the `devilbox` account. You can also mount the mail directory locally to hook in with mutt and read those mails.
|
||||
```shell
|
||||
$ docker run -d \
|
||||
-p 127.0.0.1:9000:9000 \
|
||||
-v /tmp/mail:/var/mail \
|
||||
-e ENABLE_MAIL=1 \
|
||||
-e ENABLE_MAIL=2 \
|
||||
-t devilbox/php-fpm:7.2-prod
|
||||
```
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ FLAVOUR="${3}"
|
||||
### Postfix
|
||||
###
|
||||
MOUNTPOINT="$( mktemp --directory )"
|
||||
did="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "-e DEBUG_ENTRYPOINT=2 -e NEW_UID=$(id -u) -e NEW_GID=$(id -g) -e ENABLE_MAIL=1 -v ${MOUNTPOINT}:/var/mail" )"
|
||||
did="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "-e DEBUG_ENTRYPOINT=2 -e NEW_UID=$(id -u) -e NEW_GID=$(id -g) -e ENABLE_MAIL=2 -v ${MOUNTPOINT}:/var/mail" )"
|
||||
run "sleep 10"
|
||||
|
||||
if ! run "docker logs ${did} 2>&1 | grep -q 'ENABLE_MAIL'"; then
|
||||
@@ -36,7 +36,7 @@ fi
|
||||
|
||||
if [ ! -f "${MOUNTPOINT}/devilbox" ]; then
|
||||
echo "Mail file does not exist: ${MOUNTPOINT}/devilbox"
|
||||
ls -lap ${MOUNTPOINT}/
|
||||
ls -lap "${MOUNTPOINT}/"
|
||||
docker_logs "${did}" || true
|
||||
docker_stop "${did}" || true
|
||||
rm -rf "${MOUNTPOINT}"
|
||||
@@ -45,7 +45,7 @@ if [ ! -f "${MOUNTPOINT}/devilbox" ]; then
|
||||
fi
|
||||
if [ ! -r "${MOUNTPOINT}/devilbox" ]; then
|
||||
echo "Mail file is not readable"
|
||||
ls -lap ${MOUNTPOINT}/
|
||||
ls -lap "${MOUNTPOINT}/"
|
||||
docker_logs "${did}" || true
|
||||
docker_stop "${did}" || true
|
||||
rm -rf "${MOUNTPOINT}"
|
||||
|
||||
Reference in New Issue
Block a user