1
0

postfix.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env bash
  2. # postfix-wrapper.sh, version 0.1.0
  3. #
  4. # You cannot start postfix in some foreground mode and
  5. # it's more or less important that docker doesn't kill
  6. # postfix and its chilren if you stop the container.
  7. #
  8. # Use this script with supervisord and it will take
  9. # care about starting and stopping postfix correctly.
  10. #
  11. # supervisord config snippet for postfix-wrapper:
  12. #
  13. # [program:postfix]
  14. # process_name = postfix
  15. # command = /path/to/postfix-wrapper.sh
  16. # startsecs = 0
  17. # autorestart = false
  18. #
  19. # Init vars
  20. if [[ -z "$SERVICE_POSTFIX_OPTS" ]]; then SERVICE_POSTFIX_OPTS=""; fi
  21. source /opt/docker/bin/config.sh
  22. trap "postfix stop" SIGINT
  23. trap "postfix stop" SIGTERM
  24. trap "postfix reload" SIGHUP
  25. includeScriptDir "/opt/docker/bin/service.d/postfix.d/"
  26. # start postfix
  27. postfix start $SERVICE_POSTFIX_OPTS
  28. # lets give postfix some time to start
  29. sleep 3
  30. # wait until postfix is dead (triggered by trap)
  31. if [[ -f /var/spool/postfix/pid/master.pid ]]; then
  32. while kill -0 "$(cat /var/spool/postfix/pid/master.pid 2>/dev/null)" &>/dev/null; do
  33. sleep 5
  34. done
  35. fi