You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.3 KiB

  1. #!/bin/bash
  2. set -e
  3. # Note: we don't just use "apache2ctl" here because it itself is just a shell-script wrapper around apache2 which provides extra functionality like "apache2ctl start" for launching apache2 in the background.
  4. # (also, when run as "apache2ctl <apache args>", it does not use "exec", which leaves an undesirable resident shell process)
  5. : "${APACHE_CONFDIR:=/etc/apache2}"
  6. : "${APACHE_ENVVARS:=$APACHE_CONFDIR/envvars}"
  7. if test -f "$APACHE_ENVVARS"; then
  8. . "$APACHE_ENVVARS"
  9. fi
  10. # Apache gets grumpy about PID files pre-existing
  11. : "${APACHE_RUN_DIR:=/var/run/apache2}"
  12. : "${APACHE_PID_FILE:=$APACHE_RUN_DIR/apache2.pid}"
  13. rm -f "$APACHE_PID_FILE"
  14. # create missing directories
  15. # (especially APACHE_RUN_DIR, APACHE_LOCK_DIR, and APACHE_LOG_DIR)
  16. for e in "${!APACHE_@}"; do
  17. if [[ "$e" == *_DIR ]] && [[ "${!e}" == /* ]]; then
  18. # handle "/var/lock" being a symlink to "/run/lock", but "/run/lock" not existing beforehand, so "/var/lock/something" fails to mkdir
  19. # mkdir: cannot create directory '/var/lock': File exists
  20. dir="${!e}"
  21. while [ "$dir" != "$(dirname "$dir")" ]; do
  22. dir="$(dirname "$dir")"
  23. if [ -d "$dir" ]; then
  24. break
  25. fi
  26. absDir="$(readlink -f "$dir" 2>/dev/null || :)"
  27. if [ -n "$absDir" ]; then
  28. mkdir -p "$absDir"
  29. fi
  30. done
  31. mkdir -p "${!e}"
  32. fi
  33. done
  34. exec apache2 -DFOREGROUND "$@"