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
28 # Avoid POSIX death due to SIGHUP when some parent process exits.
32 case $daemon_directory in
33 "") echo This script must be run by the postfix command. 1>&2
34 echo Do not run directly. 1>&2
38 LOGGER="$command_directory/postlog -t $MAIL_LOGTAG/postfix-script"
39 INFO="$LOGGER -p info"
40 WARN="$LOGGER -p warn"
41 ERROR="$LOGGER -p error"
42 FATAL="$LOGGER -p fatal"
43 PANIC="$LOGGER -p panic"
45 if [ "X${1#quiet-}" != "X${1}" ]; then
56 # Can't do much without these in place.
58 cd $command_directory || {
59 $FATAL no Postfix command directory $command_directory!
62 cd $daemon_directory || {
63 $FATAL no Postfix daemon directory $daemon_directory!
67 $FATAL no Postfix master program $daemon_directory/master!
70 cd $config_directory || {
71 $FATAL no Postfix configuration directory $config_directory!
74 case $shlib_directory in
76 *) cd $shlib_directory || {
77 $FATAL no Postfix shared-library directory $shlib_directory!
81 cd $meta_directory || {
82 $FATAL no Postfix meta directory $meta_directory!
85 cd $queue_directory || {
86 $FATAL no Postfix queue directory $queue_directory!
89 def_config_directory=`$command_directory/postconf -dh config_directory` || {
90 $FATAL cannot execute $command_directory/postconf!
94 # If this is a secondary instance, don't touch shared files.
96 instances=`test ! -f $def_config_directory/main.cf ||
97 $command_directory/postconf -c $def_config_directory \
98 -h multi_instance_directories | sed 's/,/ /'` || {
99 $FATAL cannot execute $command_directory/postconf!
104 for name in $instances
107 "$def_config_directory") ;;
108 "$config_directory") check_shared_files=; break;;
129 $daemon_directory/master -t 2>/dev/null || {
130 $FATAL the Postfix mail system is already running
133 $daemon_directory/postfix-script quick-check || {
134 $FATAL Postfix integrity check failed!
137 $INFO starting the Postfix mail system
138 $daemon_directory/master &
143 $daemon_directory/master -t 2>/dev/null || {
144 $FATAL the Postfix mail system is already running
147 if [ -f $queue_directory/quick-start ]
149 rm -f $queue_directory/quick-start
151 $daemon_directory/postfix-script check-fatal || {
152 $FATAL Postfix integrity check failed!
155 # Foreground this so it can be stopped. All inodes are cached.
156 $daemon_directory/postfix-script check-warn
158 $INFO starting the Postfix mail system
159 # NOTE: wait in foreground process to get the initialization status.
160 $daemon_directory/master -w || {
161 $FATAL "mail system startup failed"
168 $daemon_directory/master -t 2>/dev/null && {
169 $FATAL the Postfix mail system is not running
172 $INFO stopping the Postfix mail system
173 kill -9 `sed 1q pid/master.pid`
178 $daemon_directory/postfix-script stop
179 touch $queue_directory/quick-start
184 $daemon_directory/master -t 2>/dev/null && {
185 $FATAL the Postfix mail system is not running
188 $INFO stopping the Postfix mail system
189 kill `sed 1q pid/master.pid`
192 $daemon_directory/master -t && exit 0
193 $INFO waiting for the Postfix mail system to terminate
196 $WARN stopping the Postfix mail system with force
197 pid=`awk '{ print $1; exit 0 } END { exit 1 }' pid/master.pid` &&
203 $daemon_directory/master -t 2>/dev/null && {
204 $FATAL the Postfix mail system is not running
207 $INFO aborting the Postfix mail system
208 kill `sed 1q pid/master.pid`
213 $daemon_directory/master -t 2>/dev/null && {
214 $FATAL the Postfix mail system is not running
217 $INFO refreshing the Postfix mail system
218 $command_directory/postsuper active || exit 1
219 kill -HUP `sed 1q pid/master.pid`
220 $command_directory/postsuper &
225 cd $queue_directory || {
226 $FATAL no Postfix queue directory $queue_directory!
229 $command_directory/postqueue -f
234 $daemon_directory/postfix-script check-fatal || exit 1
235 $daemon_directory/postfix-script check-warn
241 $daemon_directory/master -t 2>/dev/null && {
242 $INFO the Postfix mail system is not running
245 $INFO the Postfix mail system is running: PID: `sed 1q pid/master.pid`
250 # This command is NOT part of the public interface.
252 $SHELL $daemon_directory/post-install create-missing || {
253 $WARN unable to create missing queue directories
257 # Look for incomplete installations.
259 test -f $config_directory/master.cf || {
260 $FATAL no $config_directory/master.cf file found
267 # This command is NOT part of the public interface.
269 $daemon_directory/postfix-script quick-check
271 # See if all queue files are in the right place. This is slow.
272 # We must scan all queues for mis-named queue files before the
273 # mail system can run.
275 $command_directory/postsuper || exit 1
280 # This command is NOT part of the public interface.
282 # Check Postfix root-owned directory owner/permissions.
284 find $queue_directory/. $queue_directory/pid \
285 -prune ! -user root \
286 -exec $WARN not owned by root: {} \;
288 find $queue_directory/. $queue_directory/pid \
289 -prune \( -perm -020 -o -perm -002 \) \
290 -exec $WARN group or other writable: {} \;
292 # Check Postfix root-owned directory tree owner/permissions.
294 todo="$config_directory/."
295 test -n "$check_shared_files" && {
296 todo="$daemon_directory/. $meta_directory/. $todo"
297 test "$shlib_directory" = "no" ||
298 todo="$shlib_directory/. $todo"
300 todo=`echo "$todo" | tr ' ' '\12' | sort -u`
302 find $todo ! -user root \
303 -exec $WARN not owned by root: {} \;
305 find $todo \( -perm -020 -o -perm -002 \) \
306 -exec $WARN group or other writable: {} \;
308 # Check Postfix mail_owner-owned directory tree owner/permissions.
310 find $data_directory/. ! -user $mail_owner \
311 -exec $WARN not owned by $mail_owner: {} \;
313 find $data_directory/. \( -perm -020 -o -perm -002 \) \
314 -exec $WARN group or other writable: {} \;
316 # Check Postfix mail_owner-owned directory tree owner.
318 find `ls -d $queue_directory/* | \
319 egrep '/(saved|incoming|active|defer|deferred|bounce|hold|trace|corrupt|public|private|flush)$'` \
320 ! \( -type p -o -type s \) ! -user $mail_owner \
321 -exec $WARN not owned by $mail_owner: {} \;
323 # WARNING: this should not descend into the maildrop directory.
324 # maildrop is the least trusted Postfix directory.
326 find $queue_directory/maildrop -prune ! -user $mail_owner \
327 -exec $WARN not owned by $mail_owner: $queue_directory/maildrop \;
329 # Check Postfix setgid_group-owned directory and file group/permissions.
331 todo="$queue_directory/public $queue_directory/maildrop"
332 test -n "$check_shared_files" &&
333 todo="$command_directory/postqueue $command_directory/postdrop $todo"
336 -prune ! -group $setgid_group \
337 -exec $WARN not owned by group $setgid_group: {} \;
339 test -n "$check_shared_files" &&
340 find $command_directory/postqueue $command_directory/postdrop \
341 -prune ! -perm -02111 \
342 -exec $WARN not set-gid or not owner+group+world executable: {} \;
344 # Check non-Postfix root-owned directory tree owner/content.
346 for dir in bin etc lib sbin usr
349 find $dir ! -user root \
350 -exec $WARN not owned by root: $queue_directory/{} \;
352 find $dir -type f -print | while read path
355 cmp -s $path /$path ||
356 $WARN $queue_directory/$path and /$path differ
362 find corrupt -type f -exec $WARN damaged message: {} \;
364 # Check for non-Postfix MTA remnants.
366 test -n "$check_shared_files" -a -f /usr/sbin/sendmail -a \
367 -f /usr/lib/sendmail && {
368 cmp -s /usr/sbin/sendmail /usr/lib/sendmail || {
369 $WARN /usr/lib/sendmail and /usr/sbin/sendmail differ
370 $WARN Replace one by a symbolic link to the other
376 set-permissions|upgrade-configuration)
377 $daemon_directory/post-install create-missing "$@"
381 # Currently not part of the public interface.
383 $daemon_directory/post-install "$@"
388 $daemon_directory/postfix-tls-script "$@"
392 # Currently not part of the public interface.
397 $ERROR "unknown command: '$1'"
398 $FATAL "usage: postfix start (or stop, reload, abort, flush, check, status, set-permissions, upgrade-configuration)"