7 # execute Postfix administrative commands
9 # \fBpostfix-script\fR \fIcommand\fR
11 # The \fBpostfix-script\fR script executes Postfix administrative
12 # commands in an environment that is set up by the \fBpostfix\fR(1)
15 # master(8) Postfix master program
16 # postfix(1) Postfix administrative interface
20 # The Secure Mailer license must be distributed with this software.
23 # IBM T.J. Watson Research
25 # Yorktown Heights, NY 10598, USA
30 # New York, NY 10011, USA
33 # Avoid POSIX death due to SIGHUP when some parent process exits.
37 case $daemon_directory in
38 "") echo This script must be run by the postfix command. 1>&2
39 echo Do not run directly. 1>&2
43 LOGGER="$command_directory/postlog -t $MAIL_LOGTAG/postfix-script"
44 INFO="$LOGGER -p info"
45 WARN="$LOGGER -p warn"
46 ERROR="$LOGGER -p error"
47 FATAL="$LOGGER -p fatal"
48 PANIC="$LOGGER -p panic"
50 if [ "X${1#quiet-}" != "X${1}" ]; then
61 # Can't do much without these in place.
63 cd $command_directory || {
64 $FATAL no Postfix command directory $command_directory!
67 cd $daemon_directory || {
68 $FATAL no Postfix daemon directory $daemon_directory!
72 $FATAL no Postfix master program $daemon_directory/master!
75 cd $config_directory || {
76 $FATAL no Postfix configuration directory $config_directory!
79 case $shlib_directory in
81 *) cd $shlib_directory || {
82 $FATAL no Postfix shared-library directory $shlib_directory!
86 cd $meta_directory || {
87 $FATAL no Postfix meta directory $meta_directory!
90 cd $queue_directory || {
91 $FATAL no Postfix queue directory $queue_directory!
94 def_config_directory=`$command_directory/postconf -dh config_directory` || {
95 $FATAL cannot execute $command_directory/postconf!
99 # If this is a secondary instance, don't touch shared files.
101 instances=`test ! -f $def_config_directory/main.cf ||
102 $command_directory/postconf -c $def_config_directory \
103 -h multi_instance_directories | sed 's/,/ /'` || {
104 $FATAL cannot execute $command_directory/postconf!
109 for name in $instances
112 "$def_config_directory") ;;
113 "$config_directory") check_shared_files=; break;;
134 $daemon_directory/master -t 2>/dev/null || {
135 $FATAL the Postfix mail system is already running
138 $daemon_directory/postfix-script quick-check || {
139 $FATAL Postfix integrity check failed!
142 $INFO starting the Postfix mail system
143 $daemon_directory/master &
148 $daemon_directory/master -t 2>/dev/null || {
149 $FATAL the Postfix mail system is already running
152 if [ -f $queue_directory/quick-start ]
154 rm -f $queue_directory/quick-start
156 $daemon_directory/postfix-script check-fatal || {
157 $FATAL Postfix integrity check failed!
160 # Foreground this so it can be stopped. All inodes are cached.
161 $daemon_directory/postfix-script check-warn
163 $INFO starting the Postfix mail system
166 # NOTE: wait in foreground process to get the initialization status.
167 $daemon_directory/master -w || {
168 $FATAL "mail system startup failed"
173 # Foreground start-up is incompatible with multi-instance mode.
174 # We can't use "exec $daemon_directory/master" here: that would
175 # break process group management, and "postfix stop" would kill
176 # too many processes.
178 "") $daemon_directory/master
180 *) $FATAL "start-fg does not support multi_instance_directories"
190 $daemon_directory/master -t 2>/dev/null && {
191 $FATAL the Postfix mail system is not running
194 $INFO stopping the Postfix mail system
195 kill -9 `sed 1q pid/master.pid`
200 $daemon_directory/postfix-script stop
201 touch $queue_directory/quick-start
206 $daemon_directory/master -t 2>/dev/null && {
207 $FATAL the Postfix mail system is not running
210 $INFO stopping the Postfix mail system
211 kill `sed 1q pid/master.pid`
214 $daemon_directory/master -t && exit 0
215 $INFO waiting for the Postfix mail system to terminate
218 $WARN stopping the Postfix mail system with force
219 pid=`awk '{ print $1; exit 0 } END { exit 1 }' pid/master.pid` &&
225 $daemon_directory/master -t 2>/dev/null && {
226 $FATAL the Postfix mail system is not running
229 $INFO aborting the Postfix mail system
230 kill `sed 1q pid/master.pid`
235 $daemon_directory/master -t 2>/dev/null && {
236 $FATAL the Postfix mail system is not running
239 $INFO refreshing the Postfix mail system
240 $command_directory/postsuper active || exit 1
241 kill -HUP `sed 1q pid/master.pid`
242 $command_directory/postsuper &
247 cd $queue_directory || {
248 $FATAL no Postfix queue directory $queue_directory!
251 $command_directory/postqueue -f
256 $daemon_directory/postfix-script check-fatal || exit 1
257 $daemon_directory/postfix-script check-warn
263 $daemon_directory/master -t 2>/dev/null && {
264 $INFO the Postfix mail system is not running
267 $INFO the Postfix mail system is running: PID: `sed 1q pid/master.pid`
272 # This command is NOT part of the public interface.
274 $SHELL $daemon_directory/post-install create-missing || {
275 $WARN unable to create missing queue directories
279 # Look for incomplete installations.
281 test -f $config_directory/master.cf || {
282 $FATAL no $config_directory/master.cf file found
289 # This command is NOT part of the public interface.
291 $daemon_directory/postfix-script quick-check
293 # See if all queue files are in the right place. This is slow.
294 # We must scan all queues for mis-named queue files before the
295 # mail system can run.
297 $command_directory/postsuper || exit 1
302 # This command is NOT part of the public interface.
304 # Check Postfix root-owned directory owner/permissions.
306 find $queue_directory/. $queue_directory/pid \
307 -prune ! -user root \
308 -exec $WARN not owned by root: {} \;
310 find $queue_directory/. $queue_directory/pid \
311 -prune \( -perm -020 -o -perm -002 \) \
312 -exec $WARN group or other writable: {} \;
314 # Check Postfix root-owned directory tree owner/permissions.
316 todo="$config_directory/."
317 test -n "$check_shared_files" && {
318 todo="$daemon_directory/. $meta_directory/. $todo"
319 test "$shlib_directory" = "no" ||
320 todo="$shlib_directory/. $todo"
322 todo=`echo "$todo" | tr ' ' '\12' | sort -u`
324 find $todo ! -user root \
325 -exec $WARN not owned by root: {} \;
327 # Handle symlinks separately
328 find -L $todo \( -perm -020 -o -perm -002 \) \
329 -exec $WARN group or other writable: {} \;
331 find $todo -type l | while read f; do \
332 readlink "$f" | grep -q / && $WARN symlink leaves directory: "$f"; \
335 # Check Postfix mail_owner-owned directory tree owner/permissions.
337 find $data_directory/. ! -user $mail_owner \
338 -exec $WARN not owned by $mail_owner: {} \;
340 find $data_directory/. \( -perm -020 -o -perm -002 \) \
341 -exec $WARN group or other writable: {} \;
343 # Check Postfix mail_owner-owned directory tree owner.
345 find `ls -d $queue_directory/* | \
346 egrep '/(saved|incoming|active|defer|deferred|bounce|hold|trace|corrupt|public|private|flush)$'` \
347 ! \( -type p -o -type s \) ! -user $mail_owner \
348 -exec $WARN not owned by $mail_owner: {} \;
350 # WARNING: this should not descend into the maildrop directory.
351 # maildrop is the least trusted Postfix directory.
353 find $queue_directory/maildrop -prune ! -user $mail_owner \
354 -exec $WARN not owned by $mail_owner: $queue_directory/maildrop \;
356 # Check Postfix setgid_group-owned directory and file group/permissions.
358 todo="$queue_directory/public $queue_directory/maildrop"
359 test -n "$check_shared_files" &&
360 todo="$command_directory/postqueue $command_directory/postdrop $todo"
363 -prune ! -group $setgid_group \
364 -exec $WARN not owned by group $setgid_group: {} \;
366 test -n "$check_shared_files" &&
367 find $command_directory/postqueue $command_directory/postdrop \
368 -prune ! -perm -02111 \
369 -exec $WARN not set-gid or not owner+group+world executable: {} \;
371 # Check non-Postfix root-owned directory tree owner/content.
373 for dir in bin etc lib sbin usr
376 find $dir ! -user root \
377 -exec $WARN not owned by root: $queue_directory/{} \;
379 find $dir -type f -print | while read path
382 cmp -s $path /$path ||
383 $WARN $queue_directory/$path and /$path differ
389 find corrupt -type f -exec $WARN damaged message: {} \;
391 # Check for non-Postfix MTA remnants.
393 test -n "$check_shared_files" -a -f /usr/sbin/sendmail -a \
394 -f /usr/lib/sendmail && {
395 cmp -s /usr/sbin/sendmail /usr/lib/sendmail || {
396 $WARN /usr/lib/sendmail and /usr/sbin/sendmail differ
397 $WARN Replace one by a symbolic link to the other
403 set-permissions|upgrade-configuration)
404 $daemon_directory/post-install create-missing "$@"
408 # Currently not part of the public interface.
410 $daemon_directory/post-install "$@"
415 $daemon_directory/postfix-tls-script "$@"
419 # Currently not part of the public interface.
424 $FATAL "unknown command: '$1'. Usage: postfix start (or stop, reload, abort, flush, check, status, set-permissions, upgrade-configuration)"