Fix docker logs for PHP mail func logging

This commit is contained in:
cytopia
2018-03-05 18:40:34 +01:00
parent 389b962aaf
commit fe379ae977
4 changed files with 68 additions and 14 deletions

View File

@@ -17,7 +17,9 @@ set_postfix() {
local username="${2}"
local groupname="${3}"
local php_ini_dir="${4}"
local debug="${5}"
local php_mail_log="${5}"
local docker_logs="${6}"
local debug="${7}"
local php_ini_file="${php_ini_dir}/devilbox-runtime-sendmail.ini"
local catch_all=
@@ -37,9 +39,23 @@ set_postfix() {
echo "sendmail_path = $( which sendmail ) -t -i";
echo ";mail.force_extra_parameters =";
echo "mail.add_x_header = On";
echo "mail.log = /var/log/php/mail.log";
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
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
# Add Mail dir/file if it does not exist
if [ ! -d "/var/mail" ]; then
run "mkdir /var/mail" "${debug}"

View File

@@ -51,6 +51,26 @@ _log_to_files() {
# Functions
############################################################
###
### Get info if we log to docker logs
###
is_docker_logs_enabled() {
local env_varname="${1}"
if env_set "${env_varname}"; then
docker_logs="$( env_get "${env_varname}" )"
if [ "${docker_logs}" = "1" ]; then
# Use docker logs
echo "1"
return 0
fi
fi
# Use file based logging
echo "0"
return 1
}
###
### Change PHP-FPM logging (file or docker logs)
###

View File

@@ -21,6 +21,9 @@ CONFIG_DIR="/docker-entrypoint.d"
# php.ini.d directory
PHP_INI_DIR="/usr/local/etc/php/conf.d"
# This is the log file for any mail related functions
PHP_MAIL_LOG="/var/log/mail.log"
# This file holds error and access log definitions
FPM_CONF_LOGFILE="/usr/local/etc/php-fpm.d/logfiles.conf"
@@ -69,12 +72,6 @@ set_gid "NEW_GID" "${MY_GROUP}" "/home/${MY_USER}" "${DEBUG_LEVEL}"
set_timezone "TIMEZONE" "${PHP_INI_DIR}" "${DEBUG_LEVEL}"
###
### Setup postfix
###
set_postfix "ENABLE_MAIL" "${MY_USER}" "${MY_GROUP}" "${PHP_INI_DIR}" "${DEBUG_LEVEL}"
###
### Set Logging
###
@@ -87,6 +84,18 @@ set_docker_logs \
"${DEBUG_LEVEL}"
###
### Setup postfix
###
if is_docker_logs_enabled "DOCKER_LOGS" >/dev/null; then
# PHP mail function should log to stderr
set_postfix "ENABLE_MAIL" "${MY_USER}" "${MY_GROUP}" "${PHP_INI_DIR}" "/proc/self/fd/2" "1" "${DEBUG_LEVEL}"
else
# PHP mail function should log to file
set_postfix "ENABLE_MAIL" "${MY_USER}" "${MY_GROUP}" "${PHP_INI_DIR}" "${PHP_MAIL_LOG}" "0" "${DEBUG_LEVEL}"
fi
###
### Validate socat port forwards
###

View File

@@ -21,6 +21,9 @@ CONFIG_DIR="/docker-entrypoint.d"
# php.ini.d directory
PHP_INI_DIR="/usr/local/etc/php/conf.d"
# This is the log file for any mail related functions
PHP_MAIL_LOG="/var/log/mail.log"
# This file holds error and access log definitions
FPM_CONF_LOGFILE="/usr/local/etc/php-fpm.d/logfiles.conf"
@@ -69,12 +72,6 @@ set_gid "NEW_GID" "${MY_GROUP}" "/home/${MY_USER}" "${DEBUG_LEVEL}"
set_timezone "TIMEZONE" "${PHP_INI_DIR}" "${DEBUG_LEVEL}"
###
### Setup postfix
###
set_postfix "ENABLE_MAIL" "${MY_USER}" "${MY_GROUP}" "${PHP_INI_DIR}" "${DEBUG_LEVEL}"
###
### Set Logging
###
@@ -87,6 +84,18 @@ set_docker_logs \
"${DEBUG_LEVEL}"
###
### Setup postfix
###
if is_docker_logs_enabled "DOCKER_LOGS" >/dev/null; then
# PHP mail function should log to stderr
set_postfix "ENABLE_MAIL" "${MY_USER}" "${MY_GROUP}" "${PHP_INI_DIR}" "/proc/self/fd/2" "1" "${DEBUG_LEVEL}"
else
# PHP mail function should log to file
set_postfix "ENABLE_MAIL" "${MY_USER}" "${MY_GROUP}" "${PHP_INI_DIR}" "${PHP_MAIL_LOG}" "0" "${DEBUG_LEVEL}"
fi
###
### Validate socat port forwards
###