sendmail.init 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/bin/bash
  2. #
  3. # sendmail This shell script takes care of starting and stopping
  4. # sendmail.
  5. #
  6. # chkconfig: 2345 80 30
  7. # description: Sendmail is a Mail Transport Agent, which is the program \
  8. # that moves mail from one machine to another.
  9. # processname: sendmail
  10. # config: /etc/mail/sendmail.cf
  11. # pidfile: /var/run/sendmail.pid
  12. # Source function library.
  13. . /etc/rc.d/init.d/functions
  14. # Source networking configuration.
  15. [ -f /etc/sysconfig/network ] && . /etc/sysconfig/network
  16. # Source sendmail configureation.
  17. if [ -f /etc/sysconfig/sendmail ] ; then
  18. . /etc/sysconfig/sendmail
  19. else
  20. DAEMON=no
  21. QUEUE=1h
  22. fi
  23. [ -z "$SMQUEUE" ] && SMQUEUE="$QUEUE"
  24. [ -z "$SMQUEUE" ] && SMQUEUE=1h
  25. # Check that networking is up.
  26. [ "${NETWORKING}" = "no" ] && exit 0
  27. [ -f /usr/sbin/sendmail ] || exit 0
  28. RETVAL=0
  29. prog="sendmail"
  30. start() {
  31. # Start daemons.
  32. echo -n $"Starting $prog: "
  33. if test -x /usr/bin/make -a -f /etc/mail/Makefile ; then
  34. make all -C /etc/mail -s
  35. else
  36. for i in virtusertable access domaintable mailertable ; do
  37. if [ -f /etc/mail/$i ] ; then
  38. makemap hash /etc/mail/$i < /etc/mail/$i
  39. fi
  40. done
  41. fi
  42. /usr/bin/newaliases > /dev/null 2>&1
  43. daemon /usr/sbin/sendmail $([ "x$DAEMON" = xyes ] && echo -bd) \
  44. $([ -n "$QUEUE" ] && echo -q$QUEUE) $SENDMAIL_OPTARG
  45. RETVAL=$?
  46. echo
  47. [ $RETVAL -eq 0 ] && touch /var/lock/subsys/sendmail
  48. if ! test -f /var/run/sm-client.pid ; then
  49. echo -n $"Starting sm-client: "
  50. touch /var/run/sm-client.pid
  51. chown smmsp:smmsp /var/run/sm-client.pid
  52. daemon --check sm-client /usr/sbin/sendmail -L sm-msp-queue -Ac \
  53. -q $SMQUEUE $SENDMAIL_OPTARG
  54. RETVAL=$?
  55. echo
  56. [ $RETVAL -eq 0 ] && touch /var/lock/subsys/sm-client
  57. fi
  58. return $RETVAL
  59. }
  60. reload() {
  61. # Stop daemons.
  62. echo -n $"reloading $prog: "
  63. /usr/bin/newaliases > /dev/null 2>&1
  64. if [ -x /usr/bin/make -a -f /etc/mail/Makefile ]; then
  65. make all -C /etc/mail -s
  66. else
  67. for i in virtusertable access domaintable mailertable ; do
  68. if [ -f /etc/mail/$i ] ; then
  69. makemap hash /etc/mail/$i < /etc/mail/$i
  70. fi
  71. done
  72. fi
  73. daemon /usr/sbin/sendmail $([ "x$DAEMON" = xyes ] && echo -bd) \
  74. $([ -n "$QUEUE" ] && echo -q$QUEUE)
  75. RETVAL=$?
  76. killproc sendmail -HUP
  77. RETVAL=$?
  78. echo
  79. if [ $RETVAL -eq 0 -a -f /var/run/sm-client.pid ]; then
  80. echo -n $"reloading sm-client: "
  81. killproc sm-client -HUP
  82. RETVAL=$?
  83. echo
  84. fi
  85. return $RETVAL
  86. }
  87. stop() {
  88. # Stop daemons.
  89. echo -n $"Shutting down $prog: "
  90. killproc sendmail
  91. RETVAL=$?
  92. echo
  93. [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sendmail
  94. if test -f /var/run/sm-client.pid ; then
  95. echo -n $"Shutting down sm-client: "
  96. killproc sm-client
  97. RETVAL=$?
  98. echo
  99. [ $RETVAL -eq 0 ] && rm -f /var/run/sm-client.pid
  100. [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sm-client
  101. fi
  102. return $RETVAL
  103. }
  104. # See how we were called.
  105. case "$1" in
  106. start)
  107. start
  108. ;;
  109. stop)
  110. stop
  111. ;;
  112. reload)
  113. reload
  114. RETVAL=$?
  115. ;;
  116. restart)
  117. stop
  118. start
  119. RETVAL=$?
  120. ;;
  121. condrestart)
  122. if [ -f /var/lock/subsys/sendmail ]; then
  123. stop
  124. start
  125. RETVAL=$?
  126. fi
  127. ;;
  128. status)
  129. status sendmail
  130. RETVAL=$?
  131. ;;
  132. *)
  133. echo $"Usage: $0 {start|stop|restart|condrestart|status}"
  134. exit 1
  135. esac
  136. exit $RETVAL