1*41fbaed0Stron#!/bin/sh 2*41fbaed0Stron# $NetBSD: postfix-wrapper,v 1.1.1.1 2009/06/23 10:08:23 tron Exp $ 3*41fbaed0Stron# 4*41fbaed0Stron 5*41fbaed0Stron#++ 6*41fbaed0Stron# NAME 7*41fbaed0Stron# postfix-wrapper 1 8*41fbaed0Stron# SUMMARY 9*41fbaed0Stron# trivial but useful multi-instance manager 10*41fbaed0Stron# SYNOPSIS 11*41fbaed0Stron# postfix command 12*41fbaed0Stron# DESCRIPTION 13*41fbaed0Stron# Postfix versions 2.6 and later provide support for multiple 14*41fbaed0Stron# Postfix instances. Instances share executable files and 15*41fbaed0Stron# documentation, but have their own directories for configuration, 16*41fbaed0Stron# queue and data files. In many cases different instances 17*41fbaed0Stron# have different myhostname and inet_interfaces settings, 18*41fbaed0Stron# though this is not always necessary. 19*41fbaed0Stron# 20*41fbaed0Stron# This command implements a trivial Postfix multi-instance 21*41fbaed0Stron# manager. It simply applies commands such as "postfix start" 22*41fbaed0Stron# to all the applicable Postfix instances. 23*41fbaed0Stron# MANAGING MULTIPLE INSTANCES 24*41fbaed0Stron# .ad 25*41fbaed0Stron# .fi 26*41fbaed0Stron# To hook the postfix-wrapper multi-instance manager into 27*41fbaed0Stron# Postfix, see the POSTFIX-WRAPPER INITIALIZATION section 28*41fbaed0Stron# below. To create a new Postfix instance, see the CREATING 29*41fbaed0Stron# A NEW POSTFIX INSTANCE section below. 30*41fbaed0Stron# 31*41fbaed0Stron# To start, stop, get status, etc., with multiple Postfix 32*41fbaed0Stron# instances, use: 33*41fbaed0Stron# 34*41fbaed0Stron# .nf 35*41fbaed0Stron# # postfix command 36*41fbaed0Stron# .fi 37*41fbaed0Stron# 38*41fbaed0Stron# For example, to find out what Postfix instances are configured: 39*41fbaed0Stron# 40*41fbaed0Stron# .nf 41*41fbaed0Stron# # postfix status 42*41fbaed0Stron# .fi 43*41fbaed0Stron# 44*41fbaed0Stron# The postfix(1) command invokes the postfix-wrapper command. 45*41fbaed0Stron# This in turn applies the postfix(1) command to the default 46*41fbaed0Stron# Postfix instance, and to each instance specified with the 47*41fbaed0Stron# default main.cf file's multi_instance_directories parameter 48*41fbaed0Stron# value. 49*41fbaed0Stron# 50*41fbaed0Stron# The postfix-wrapper command will start, stop, reload, etc., 51*41fbaed0Stron# only Postfix instances that have "multi_instance_enable = 52*41fbaed0Stron# yes" in their main.cf files. When an instance is disabled, 53*41fbaed0Stron# postfix-wrapper replaces "start" commands by "check" so 54*41fbaed0Stron# that problems will still be reported. 55*41fbaed0Stron# 56*41fbaed0Stron# The startup order is taken from the multi_instance_directories 57*41fbaed0Stron# parameter; the default instance is prepended to the list. 58*41fbaed0Stron# The startup order is used for all postfix(1) commands, 59*41fbaed0Stron# except for commands that stop Postfix instances. In those 60*41fbaed0Stron# cases the order is reversed. 61*41fbaed0Stron# MANAGING INDIVIDUAL INSTANCES 62*41fbaed0Stron# .ad 63*41fbaed0Stron# .fi 64*41fbaed0Stron# To manage an individual Postfix instance, use: 65*41fbaed0Stron# 66*41fbaed0Stron# .nf 67*41fbaed0Stron# # postfix -c /path/to/config_directory command 68*41fbaed0Stron# .fi 69*41fbaed0Stron# 70*41fbaed0Stron# This is also needed to manage the default Postfix instance, 71*41fbaed0Stron# after you turn on multi-instance support. 72*41fbaed0Stron# 73*41fbaed0Stron# To use the Postfix sendmail command with a non-default 74*41fbaed0Stron# Postfix instance, use: 75*41fbaed0Stron# 76*41fbaed0Stron# .nf 77*41fbaed0Stron# # sendmail -C /path/to/config_directory ... 78*41fbaed0Stron# .fi 79*41fbaed0Stron# 80*41fbaed0Stron# Note 1: that's capital C, not lower-case c. 81*41fbaed0Stron# 82*41fbaed0Stron# Note 2: only the default Postfix instance will check or 83*41fbaed0Stron# update the shared Postfix files, including the executable 84*41fbaed0Stron# files and documentation. 85*41fbaed0Stron# POSTFIX-WRAPPER INITIALIZATION 86*41fbaed0Stron# .ad 87*41fbaed0Stron# .fi 88*41fbaed0Stron# To hook this program into Postfix, execute the command 89*41fbaed0Stron# shown below. 90*41fbaed0Stron# 91*41fbaed0Stron# This command should be entered as one line. 92*41fbaed0Stron# 93*41fbaed0Stron# In the example, replace /etc/postfix with the default Postfix 94*41fbaed0Stron# configuration directory, and replace /usr/libexec/postfix 95*41fbaed0Stron# with the daemon directory pathname of the default Postfix 96*41fbaed0Stron# instance. 97*41fbaed0Stron# 98*41fbaed0Stron# .nf 99*41fbaed0Stron# # postconf -c /etc/postfix -e 100*41fbaed0Stron# "multi_instance_enable=yes" 101*41fbaed0Stron# "multi_instance_wrapper=/usr/libexec/postfix/postfix-wrapper" 102*41fbaed0Stron# .fi 103*41fbaed0Stron# CREATING A NEW POSTFIX INSTANCE 104*41fbaed0Stron# .ad 105*41fbaed0Stron# .fi 106*41fbaed0Stron# To create a Postfix instance called "postfix-test", start 107*41fbaed0Stron# with generic main.cf and master.cf files and customize the 108*41fbaed0Stron# locations of the queue and data directories with the commands 109*41fbaed0Stron# shown below. The last command updates main.cf and creates 110*41fbaed0Stron# any directories that Postfix will need. 111*41fbaed0Stron# 112*41fbaed0Stron# Each command below should be entered as one line. 113*41fbaed0Stron# 114*41fbaed0Stron# In the example, replace /etc/postfix with the default Postfix 115*41fbaed0Stron# configuration directory, and replace /usr/libexec/postfix 116*41fbaed0Stron# with the daemon directory pathname of the default Postfix 117*41fbaed0Stron# instance. 118*41fbaed0Stron# 119*41fbaed0Stron# .nf 120*41fbaed0Stron# # mkdir /etc/postfix-test 121*41fbaed0Stron# # cp /usr/libexec/postfix/main.cf /etc/postfix-test 122*41fbaed0Stron# # cp /usr/libexec/postfix/master.cf /etc/postfix-test 123*41fbaed0Stron# # postconf -c /etc/postfix-test -e 124*41fbaed0Stron# "multi_instance_name=postfix-test" 125*41fbaed0Stron# # postfix -c /etc/postfix post-install 126*41fbaed0Stron# "config_directory=/etc/postfix-test" 127*41fbaed0Stron# "queue_directory=/var/spool/postfix-test" 128*41fbaed0Stron# "data_directory=/var/lib/postfix-test" 129*41fbaed0Stron# create-missing 130*41fbaed0Stron# .fi 131*41fbaed0Stron# 132*41fbaed0Stron# Register this Postfix instance with the default instance. 133*41fbaed0Stron# This command should be entered as one line. 134*41fbaed0Stron# 135*41fbaed0Stron# .nf 136*41fbaed0Stron# # postconf -e "multi_instance_directories=`postconf 137*41fbaed0Stron# -h multi_instance_directories` /etc/postfix-test" 138*41fbaed0Stron# .fi 139*41fbaed0Stron# 140*41fbaed0Stron# Edit the myhostname and inet_interfaces main.cf parameters, 141*41fbaed0Stron# so that they will not conflict with the default Postfix 142*41fbaed0Stron# instance, and change whatever else needs to be changed. 143*41fbaed0Stron# 144*41fbaed0Stron# Test the instance with: 145*41fbaed0Stron# 146*41fbaed0Stron# .nf 147*41fbaed0Stron# # postfix -c /etc/postfix-test start 148*41fbaed0Stron# # postfix -c /etc/postfix-test status 149*41fbaed0Stron# [ other tests ... ] 150*41fbaed0Stron# .fi 151*41fbaed0Stron# 152*41fbaed0Stron# When everything is working satisfactorily, enable start/stop/etc. 153*41fbaed0Stron# by the multi-instance manager: 154*41fbaed0Stron# 155*41fbaed0Stron# .nf 156*41fbaed0Stron# # postconf -c /etc/postfix-test -e multi_instance_enable=yes 157*41fbaed0Stron# DIAGNOSTICS 158*41fbaed0Stron# .ad 159*41fbaed0Stron# .fi 160*41fbaed0Stron# When an operation fails, the affected Postfix instance logs 161*41fbaed0Stron# a message, and the multi-instance manager skips to the next 162*41fbaed0Stron# instance. 163*41fbaed0Stron# BUGS 164*41fbaed0Stron# Support for the multi_instance_group feature is not implemented. 165*41fbaed0Stron# SEE ALSO 166*41fbaed0Stron# postfix(1) Postfix control program 167*41fbaed0Stron# postfix-wrapper(5) multi-instance manager API 168*41fbaed0Stron# postmulti(1) full-blown multi-instance manager 169*41fbaed0Stron# LICENSE 170*41fbaed0Stron# .ad 171*41fbaed0Stron# .fi 172*41fbaed0Stron# The Secure Mailer license must be distributed with this software. 173*41fbaed0Stron# AUTHOR(S) 174*41fbaed0Stron# Wietse Venema 175*41fbaed0Stron# IBM T.J. Watson Research 176*41fbaed0Stron# P.O. Box 704 177*41fbaed0Stron# Yorktown Heights, NY 10598, USA 178*41fbaed0Stron#-- 179*41fbaed0Stron 180*41fbaed0Stron# Sanity checks. 181*41fbaed0Stron 182*41fbaed0Stron: ${command_directory?"do not invoke this command directly"} 183*41fbaed0Stron: ${daemon_directory?"do not invoke this command directly"} 184*41fbaed0Stron 185*41fbaed0Stron# Readability. 186*41fbaed0Stron 187*41fbaed0StronPOSTCONF=$command_directory/postconf 188*41fbaed0StronPOSTFIX=$command_directory/postfix 189*41fbaed0Stron 190*41fbaed0Stron# Canonicalize the instance directory list. The list is specified 191*41fbaed0Stron# in startup order. 192*41fbaed0Stron 193*41fbaed0Stroninstance_dirs=`$POSTCONF -h multi_instance_directories | sed 's/,/ /'` || 194*41fbaed0Stron exit 1 195*41fbaed0Stron 196*41fbaed0Stroncase "$1" in 197*41fbaed0Stron stop|quick-stop|abort|drain) 198*41fbaed0Stron all_dirs= 199*41fbaed0Stron for dir in $config_directory $instance_dirs 200*41fbaed0Stron do 201*41fbaed0Stron all_dirs="$dir $all_dirs" 202*41fbaed0Stron done;; 203*41fbaed0Stron *) all_dirs="$config_directory $instance_dirs";; 204*41fbaed0Stronesac 205*41fbaed0Stron 206*41fbaed0Stron# Execute the command on all applicable instances. When a Postfix 207*41fbaed0Stron# instance is disabled, replace "postfix start" by "postfix check" 208*41fbaed0Stron# so that problems will still be reported. 209*41fbaed0Stron 210*41fbaed0Stronerr=0 211*41fbaed0Stronfor dir in $all_dirs 212*41fbaed0Strondo 213*41fbaed0Stron case "$1" in 214*41fbaed0Stron start) 215*41fbaed0Stron test "`$POSTCONF -c $dir -h multi_instance_enable`" = yes || { 216*41fbaed0Stron $POSTFIX -c $dir check || err=$? 217*41fbaed0Stron continue 218*41fbaed0Stron };; 219*41fbaed0Stron stop|abort|drain|flush|reload) 220*41fbaed0Stron test "`$POSTCONF -c $dir -h multi_instance_enable`" = yes || 221*41fbaed0Stron continue;; 222*41fbaed0Stron esac 223*41fbaed0Stron $POSTFIX -c $dir "$@" || err=$? 224*41fbaed0Strondone 225*41fbaed0Stron 226*41fbaed0Stronexit $err 227