/rc6.d/K20postfix

http://github.com/brinkman83/bashrc · Shell · 168 lines · 120 code · 23 blank · 25 comment · 27 complexity · e47d7ef0cbd2e212324812d74c409d77 MD5 · raw file

  1. #!/bin/sh -e
  2. # Start or stop Postfix
  3. #
  4. # LaMont Jones <lamont@debian.org>
  5. # based on sendmail's init.d script
  6. ### BEGIN INIT INFO
  7. # Provides: postfix mail-transport-agent
  8. # Required-Start: $local_fs $remote_fs $syslog $named $network $time
  9. # Required-Stop: $local_fs $remote_fs $syslog $named $network
  10. # Should-Start: postgresql mysql clamav-daemon postgrey spamassassin
  11. # Should-Stop: postgresql mysql clamav-daemon postgrey spamassassin
  12. # Default-Start: 2 3 4 5
  13. # Default-Stop: 0 1 6
  14. # Short-Description: start and stop the Postfix Mail Transport Agent
  15. # Description: postfix is a Mail Transport agent
  16. ### END INIT INFO
  17. PATH=/bin:/usr/bin:/sbin:/usr/sbin
  18. DAEMON=/usr/sbin/postfix
  19. NAME=Postfix
  20. TZ=
  21. unset TZ
  22. # Defaults - don't touch, edit /etc/default/postfix
  23. SYNC_CHROOT="y"
  24. test -f /etc/default/postfix && . /etc/default/postfix
  25. test -x $DAEMON && test -f /etc/postfix/main.cf || exit 0
  26. . /lib/lsb/init-functions
  27. #DISTRO=$(lsb_release -is 2>/dev/null || echo Debian)
  28. running() {
  29. queue=$(postconf -h queue_directory 2>/dev/null || echo /var/spool/postfix)
  30. if [ -f ${queue}/pid/master.pid ]; then
  31. pid=$(sed 's/ //g' ${queue}/pid/master.pid)
  32. # what directory does the executable live in. stupid prelink systems.
  33. dir=$(ls -l /proc/$pid/exe 2>/dev/null | sed 's/.* -> //; s/\/[^\/]*$//')
  34. if [ "X$dir" = "X/usr/lib/postfix" ]; then
  35. echo y
  36. fi
  37. fi
  38. }
  39. case "$1" in
  40. start)
  41. log_daemon_msg "Starting Postfix Mail Transport Agent" postfix
  42. RUNNING=$(running)
  43. if [ -n "$RUNNING" ]; then
  44. log_end_msg 0
  45. else
  46. # if you set myorigin to 'ubuntu.com' or 'debian.org', it's wrong, and annoys the admins of
  47. # those domains. See also sender_canonical_maps.
  48. MYORIGIN=$(postconf -h myorigin | tr 'A-Z' 'a-z')
  49. if [ "X${MYORIGIN#/}" != "X${MYORIGIN}" ]; then
  50. MYORIGIN=$(tr 'A-Z' 'a-z' < $MYORIGIN)
  51. fi
  52. if [ "X$MYORIGIN" = Xubuntu.com ] || [ "X$MYORIGIN" = Xdebian.org ]; then
  53. log_failure_msg "Invalid \$myorigin ($MYORIGIN), refusing to start"
  54. log_end_msg 1
  55. exit 1
  56. fi
  57. # see if anything is running chrooted.
  58. NEED_CHROOT=$(awk '/^[0-9a-z]/ && ($5 ~ "[-yY]") { print "y"; exit}' /etc/postfix/master.cf)
  59. if [ -n "$NEED_CHROOT" ] && [ -n "$SYNC_CHROOT" ]; then
  60. # Make sure that the chroot environment is set up correctly.
  61. oldumask=$(umask)
  62. umask 022
  63. cd $(postconf -h queue_directory)
  64. # if we're using tls, then we need to add etc/ssl/certs/ca-certificates.crt.
  65. smtp_use_tls=$(postconf -h smtp_use_tls)
  66. smtpd_use_tls=$(postconf -h smtpd_use_tls)
  67. if [ "X$smtp_use_tls" = "Xyes" -o "X$smtpd_use_tls" = "Xyes" ]; then
  68. if [ -f "/etc/ssl/certs/ca-certificates.crt" ]; then
  69. mkdir -p etc/ssl/certs
  70. cp /etc/ssl/certs/ca-certificates.crt etc/ssl/certs/
  71. fi
  72. fi
  73. # if we're using unix:passwd.byname, then we need to add etc/passwd.
  74. local_maps=$(postconf -h local_recipient_maps)
  75. if [ "X$local_maps" != "X${local_maps#*unix:passwd.byname}" ]; then
  76. if [ "X$local_maps" = "X${local_maps#*proxy:unix:passwd.byname}" ]; then
  77. sed 's/^\([^:]*\):[^:]*/\1:x/' /etc/passwd > etc/passwd
  78. chmod a+r etc/passwd
  79. fi
  80. fi
  81. FILES="etc/localtime etc/services etc/resolv.conf etc/hosts \
  82. etc/nsswitch.conf etc/nss_mdns.config"
  83. for file in $FILES; do
  84. [ -d ${file%/*} ] || mkdir -p ${file%/*}
  85. if [ -f /${file} ]; then rm -f ${file} && cp /${file} ${file}; fi
  86. if [ -f ${file} ]; then chmod a+rX ${file}; fi
  87. done
  88. rm -f usr/lib/zoneinfo/localtime
  89. mkdir -p usr/lib/zoneinfo
  90. ln -sf /etc/localtime usr/lib/zoneinfo/localtime
  91. rm -f lib/libnss_*so*
  92. tar cf - /lib/libnss_*so* 2>/dev/null |tar xf -
  93. umask $oldumask
  94. fi
  95. if start-stop-daemon --start --exec ${DAEMON} -- quiet-quick-start; then
  96. log_end_msg 0
  97. else
  98. log_end_msg 1
  99. fi
  100. fi
  101. ;;
  102. stop)
  103. RUNNING=$(running)
  104. log_daemon_msg "Stopping Postfix Mail Transport Agent" postfix
  105. if [ -n "$RUNNING" ]; then
  106. if ${DAEMON} quiet-stop; then
  107. log_end_msg 0
  108. else
  109. log_end_msg 1
  110. fi
  111. else
  112. log_end_msg 0
  113. fi
  114. ;;
  115. restart)
  116. $0 stop
  117. $0 start
  118. ;;
  119. force-reload|reload)
  120. log_action_begin_msg "Reloading Postfix configuration"
  121. if ${DAEMON} quiet-reload; then
  122. log_action_end_msg 0
  123. else
  124. log_action_end_msg 1
  125. fi
  126. ;;
  127. status)
  128. RUNNING=$(running)
  129. if [ -n "$RUNNING" ]; then
  130. log_success_msg "postfix is running"
  131. exit 0
  132. else
  133. log_success_msg "postfix is not running"
  134. exit 3
  135. fi
  136. ;;
  137. flush|check|abort)
  138. ${DAEMON} $1
  139. ;;
  140. *)
  141. log_action_msg "Usage: /etc/init.d/postfix {start|stop|restart|reload|flush|check|abort|force-reload}"
  142. exit 1
  143. ;;
  144. esac
  145. exit 0