Postfix Building from Source

From MattWiki
Jump to: navigation, search

FedoraLogo infinity-2.png Note: This Page was written with Fedora in mind, and may not work correctly with other versions or distributions.

yum install gcc make db4-devel mysql-devel cyrus-sasl-devel mysql-server
echo "postfix:x:89:89::/var/spool/postfix:/sbin/nologin" >> /etc/passwd
echo "postdrop:x:90:90::/var/spool/postfix:/sbin/nologin" >> /etc/passwd
echo "postfix:x:89:" >> /etc/group
echo "postdrop:x:90:" >> /etc/group
ln -s /usr/lib/sasl2/ /usr/local/lib/sasl2

Next you will need to download the postfix source file from: http://postfix.energybeam.com/source/official/ or one of the mirrors at http://www.postfix.org/download.html. Then change to the Postfix Source directory.

To build with MySQL, TLS, & Dovecot SASL support

make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -I/usr/include/sasl/ \
    -DUSE_SASL_AUTH -DUSE_CYRUS_SASL  -DDEF_SERVER_SASL_TYPE=\"dovecot\" -DUSE_TLS' \
    'AUXLIBS=-L/usr/lib/mysql -L/usr/local/lib -lmysqlclient -lz -lm -lssl -lcrypto -lsasl2'
echo $?

Or for MySQL & TLS only

make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_TLS' 'AUXLIBS=-L/usr/lib/mysql \
    -lmysqlclient -lz -lm -lssl -lcrypto'
echo $?

Or with SQLite, TLS, & Dovecot SASL support (see Installing Postfix on Fedora using SQLite)

make -f Makefile.init makefiles 'CCARGS=-DHAS_SQLITE -I/usr/local/include -I/usr/include/sasl/ \
    -DUSE_SASL_AUTH -DUSE_CYRUS_SASL  -DDEF_SERVER_SASL_TYPE=\"dovecot\" -DUSE_TLS' \
    'AUXLIBS=-L/usr/local/lib -lsqlite3 -lz -lm -lssl -lcrypto -lsasl2'
echo $?

Then to compile your install...

make
echo $?

If that runs ok then run.

make install

This next part asks a bunch of questions, if you don't know the answer the defaults should be fine.

echo $?

Postfix INIT file

#!/bin/bash
#
# postfix      Postfix Mail Transfer Agent
#
# chkconfig: - 80 30
# description: Postfix is a Mail Transport Agent, which is the program \
#              that moves mail from one machine to another.
# processname: master
# pidfile: /var/spool/postfix/pid/master.pid
# config: /etc/postfix/main.cf
# config: /etc/postfix/master.cf
#
# Based on startup script from Simon J Mudd <sjmudd@pobox.com>

### BEGIN INIT INFO
# Provides: postfix MTA
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Short-Description: start and stop postfix
# Description: Postfix is a Mail Transport Agent, which is the program that 
#              moves mail from one machine to another.
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

RETVAL=0
prog="postfix"

status master >/dev/null 2>&1
running=$?

conf_check() {
    [ -x /usr/sbin/postfix ] || exit 5
    [ -d /etc/postfix ] || exit 6
    [ -d /var/spool/postfix ] || exit 5
}

start() {
	# Check that networking is up.
	[ ${NETWORKING} = "no" ] && exit 1
	conf_check
	# Start daemons.
	echo -n $"Starting postfix: "
        /usr/bin/newaliases >/dev/null 2>&1
	/usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $"$prog start"
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/postfix
        echo
	return $RETVAL
}

stop() {
	conf_check
        # Stop daemons.
	echo -n $"Shutting down postfix: "
	/usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure $"$prog stop"
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/postfix
	echo
	return $RETVAL
}

reload() {
	conf_check
	echo -n $"Reloading postfix: "
	/usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure $"$prog reload"
	RETVAL=$?
	echo
	return $RETVAL
}

abort() {
	conf_check
	/usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure $"$prog abort"
	return $?
}

flush() {
	conf_check
	/usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure $"$prog flush"
	return $?
}

check() {
	conf_check
	/usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure $"$prog check"
	return $?
}

# See how we were called.
case "$1" in
  start)
	[ $running -eq 0 ] && exit 0
	start
	;;
  stop)
	[ $running -eq 0 ] || exit 0
	stop
	;;
  restart|force-reload)
	stop
	start
	;;
  reload)
	[ $running -eq 0 ] || exit 7
	reload
	;;
  abort)
	abort
	;;
  flush)
	flush
	;;
  check)
	check
	;;
  status)
  	status master
	;;
  condrestart)
	[ $running -eq 0 ] || exit 0
	stop
	start
	;;
  *)
	echo $"Usage: $0 {start|stop|restart|reload|abort|flush|check|status|condrestart}"
	exit 2
esac

exit $?