Skip to content

Commit

Permalink
Adjust solution to be generalized for all APACHE_*_DIR variables, and…
Browse files Browse the repository at this point in the history
… to handle edge cases in a less hard-coded manner
  • Loading branch information
tianon committed Jan 26, 2017
1 parent f2bd9a3 commit e573f8f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 30 deletions.
34 changes: 24 additions & 10 deletions 5.6/apache/apache2-foreground
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,31 @@ if test -f "$APACHE_ENVVARS"; then
. "$APACHE_ENVVARS"
fi

: "${APACHE_PID_FILE:=${APACHE_RUN_DIR:=/var/run/apache2}/apache2.pid}"

# setup directories and permissions
mkdir -p /run/lock
for dir in ${APACHE_RUN_DIR} ${APACHE_LOCK_DIR}
do
mkdir -p ${dir}
chown -R "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$dir"
done

# Apache gets grumpy about PID files pre-existing
: "${APACHE_RUN_DIR:=/var/run/apache2}"
: "${APACHE_PID_FILE:=$APACHE_RUN_DIR/apache2.pid}"
rm -f "$APACHE_PID_FILE"

# create missing directories
# (especially APACHE_RUN_DIR, APACHE_LOCK_DIR, and APACHE_LOG_DIR)
for e in "${!APACHE_@}"; do
if [[ "$e" == *_DIR ]] && [[ "${!e}" == /* ]]; then
# handle "/var/lock" being a symlink to "/run/lock", but "/run/lock" not existing beforehand, so "/var/lock/something" fails to mkdir
# mkdir: cannot create directory '/var/lock': File exists
dir="${!e}"
while [ "$dir" != "$(dirname "$dir")" ]; do
dir="$(dirname "$dir")"
if [ -d "$dir" ]; then
break
fi
absDir="$(readlink -f "$dir" 2>/dev/null || :)"
if [ -n "$absDir" ]; then
mkdir -p "$absDir"
fi
done

mkdir -p "${!e}"
fi
done

exec apache2 -DFOREGROUND "$@"
34 changes: 24 additions & 10 deletions 7.0/apache/apache2-foreground
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,31 @@ if test -f "$APACHE_ENVVARS"; then
. "$APACHE_ENVVARS"
fi

: "${APACHE_PID_FILE:=${APACHE_RUN_DIR:=/var/run/apache2}/apache2.pid}"

# setup directories and permissions
mkdir -p /run/lock
for dir in ${APACHE_RUN_DIR} ${APACHE_LOCK_DIR}
do
mkdir -p ${dir}
chown -R "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$dir"
done

# Apache gets grumpy about PID files pre-existing
: "${APACHE_RUN_DIR:=/var/run/apache2}"
: "${APACHE_PID_FILE:=$APACHE_RUN_DIR/apache2.pid}"
rm -f "$APACHE_PID_FILE"

# create missing directories
# (especially APACHE_RUN_DIR, APACHE_LOCK_DIR, and APACHE_LOG_DIR)
for e in "${!APACHE_@}"; do
if [[ "$e" == *_DIR ]] && [[ "${!e}" == /* ]]; then
# handle "/var/lock" being a symlink to "/run/lock", but "/run/lock" not existing beforehand, so "/var/lock/something" fails to mkdir
# mkdir: cannot create directory '/var/lock': File exists
dir="${!e}"
while [ "$dir" != "$(dirname "$dir")" ]; do
dir="$(dirname "$dir")"
if [ -d "$dir" ]; then
break
fi
absDir="$(readlink -f "$dir" 2>/dev/null || :)"
if [ -n "$absDir" ]; then
mkdir -p "$absDir"
fi
done

mkdir -p "${!e}"
fi
done

exec apache2 -DFOREGROUND "$@"
34 changes: 24 additions & 10 deletions 7.1/apache/apache2-foreground
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,31 @@ if test -f "$APACHE_ENVVARS"; then
. "$APACHE_ENVVARS"
fi

: "${APACHE_PID_FILE:=${APACHE_RUN_DIR:=/var/run/apache2}/apache2.pid}"

# setup directories and permissions
mkdir -p /run/lock
for dir in ${APACHE_RUN_DIR} ${APACHE_LOCK_DIR}
do
mkdir -p ${dir}
chown -R "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$dir"
done

# Apache gets grumpy about PID files pre-existing
: "${APACHE_RUN_DIR:=/var/run/apache2}"
: "${APACHE_PID_FILE:=$APACHE_RUN_DIR/apache2.pid}"
rm -f "$APACHE_PID_FILE"

# create missing directories
# (especially APACHE_RUN_DIR, APACHE_LOCK_DIR, and APACHE_LOG_DIR)
for e in "${!APACHE_@}"; do
if [[ "$e" == *_DIR ]] && [[ "${!e}" == /* ]]; then
# handle "/var/lock" being a symlink to "/run/lock", but "/run/lock" not existing beforehand, so "/var/lock/something" fails to mkdir
# mkdir: cannot create directory '/var/lock': File exists
dir="${!e}"
while [ "$dir" != "$(dirname "$dir")" ]; do
dir="$(dirname "$dir")"
if [ -d "$dir" ]; then
break
fi
absDir="$(readlink -f "$dir" 2>/dev/null || :)"
if [ -n "$absDir" ]; then
mkdir -p "$absDir"
fi
done

mkdir -p "${!e}"
fi
done

exec apache2 -DFOREGROUND "$@"

0 comments on commit e573f8f

Please sign in to comment.