#!/bin/sh
### BEGIN INIT INFO
# Provides:            postfix
# Required-Start:      $syslog $local_fs $network
# Should-Start:        $remote_fs openldap saslauthd
# Required-Stop:       $network
# Should-Stop:         $remote_fs openldap saslauthd
# Default-Start:       3 4 5
# Default-Stop:        0 1 2 6
# Short-Description:   Postfix MTA
# Description:         Controls the Postfix Mail Transfer Agent
### END INIT INFO

. /lib/lsb/init-functions

BINFILE=/usr/lib/postfix/master
PIDFILE=/var/spool/postfix/pid/master.pid

case "$1" in
  start)
    log_init_msg "Starting Postfix"
    start_daemon -p "${PIDFILE}" /usr/sbin/postfix start 2> /dev/null && \
      log_success_msg || log_failure_msg
    ;;
  stop)
    log_init_msg "Stopping Postfix"
    killproc -p "${PIDFILE}" ${BINFILE} && log_success_msg || log_failure_msg
    ;;
  reload)
    log_init_msg "Reloading Postfix"
    killproc -p "${PIDFILE}" ${BINFILE} -HUP && log_success_msg || \
      log_failure_msg
    ;;
  restart)
    $0 stop
    sleep 1
    $0 start
    ;;
  status)
    status_of_proc -p "$PIDFILE" "$DAEMON"
    ;;
  *)
    echo "Usage: $0 {start|stop|reload|restart|status}"
    exit 1
    ;;
esac
