3649N/A#!/usr/sbin/sh
3649N/A#
3649N/A# CDDL HEADER START
3649N/A#
3649N/A# The contents of this file are subject to the terms of the
3649N/A# Common Development and Distribution License (the "License").
3649N/A# You may not use this file except in compliance with the License.
3649N/A#
3649N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
3649N/A# or http://www.opensolaris.org/os/licensing.
3649N/A# See the License for the specific language governing permissions
3649N/A# and limitations under the License.
3649N/A#
3649N/A# When distributing Covered Code, include this CDDL HEADER in each
3649N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
3649N/A# If applicable, add the following below this CDDL HEADER, with the
3649N/A# fields enclosed by brackets "[]" replaced with your own identifying
3649N/A# information: Portions Copyright [yyyy] [name of copyright owner]
3649N/A#
3649N/A# CDDL HEADER END
3649N/A#
3649N/A# Copyright (c) 1991, 2013, Oracle and/or its affiliates. All rights reserved.
3649N/A
3649N/A. /lib/svc/share/smf_include.sh
3649N/A. /lib/svc/share/sendmail_include.sh
3649N/A
3649N/AERRMSG1='WARNING: /var/mail is NFS-mounted without setting actimeo=0,'
3649N/AERRMSG2='this can cause mailbox locking and access problems.'
3649N/ASERVER_PID_FILE="$SMF_SYSVOL_FS/sendmail.pid"
3649N/AALIASES_FILE="/etc/mail/aliases"
3649N/ASENDMAIL_CF="/etc/mail/sendmail.cf"
3649N/AMAKEMAP="/usr/sbin/makemap"
3649N/A
3649N/Acase "$1" in
3649N/A'refresh')
3649N/A [ -f $SERVER_PID_FILE ] && kill -1 `head -1 $SERVER_PID_FILE`
3649N/A ;;
3649N/A
3649N/A'start')
3649N/A exist_or_exit $SENDMAIL
3649N/A if [ ! -d /var/spool/mqueue ]; then
3649N/A /usr/bin/mkdir -m 0750 /var/spool/mqueue
3649N/A /usr/bin/chown root:bin /var/spool/mqueue
3649N/A fi
3649N/A if [ ! -d /var/mail/:saved ]; then
3649N/A /usr/bin/mkdir -m 0775 /var/mail/:saved
3649N/A /usr/bin/chown root:mail /var/mail/:saved
3649N/A fi
3649N/A dbvers=`/usr/bin/svcprop -c -p config/db_version $SMF_FMRI 2>/dev/null`
3649N/A if [ $? -ne 0 -o "$dbvers" != "5" ]; then
3649N/A # Need to upgrade Berkeley DB version
3649N/A # Part 1: blow away aliases DB files; we will recreate them
3649N/A # just below.
3649N/A # Part 2: keyed maps are handled further below.
3649N/A /usr/bin/rm -f $ALIASES_FILE.db $ALIASES_FILE.dir \
3649N/A $ALIASES_FILE.pag
3649N/A db_version_upgrade_needed=true
3649N/A fi
3649N/A if [ ! -f $ALIASES_FILE.db ] && [ ! -f $ALIASES_FILE.dir ] \
3649N/A && [ ! -f $ALIASES_FILE.pag ]; then
3649N/A /usr/sbin/newaliases
3649N/A fi
3649N/A MODE="-bd"
3649N/A [ -f $DEFAULT_FILE ] && . $DEFAULT_FILE
3649N/A #
3649N/A # * MODE should be "-bd" or null (MODE= or MODE="") or
3649N/A # left alone. Anything else and you're on your own.
3649N/A # * QUEUEOPTION should be "p" or null (as above).
3649N/A # * QUEUEINTERVAL should be set to some legal value;
3649N/A # sanity checks are done below.
3649N/A # * OPTIONS are catch-alls; set with care.
3649N/A #
3649N/A if [ -n "$QUEUEOPTION" -a "$QUEUEOPTION" != "p" ]; then
3649N/A QUEUEOPTION=""
3649N/A fi
3649N/A if [ -z "$QUEUEOPTION" -o -n "$QUEUEINTERVAL" ]; then
3649N/A check_queue_interval_syntax $QUEUEINTERVAL
3649N/A QUEUEINTERVAL=$answer
3649N/A fi
3649N/A
3649N/A local=`/usr/bin/svcprop -p config/local_only $SMF_FMRI 2>/dev/null`
3649N/A if [ $? -eq 0 -a "$local" = "true" ]; then
3649N/A MODE="-bl"
3649N/A fi
3649N/A sendmail_path=`svcprop -p config/path_to_sendmail_mc $SMF_FMRI \
3649N/A 2>/dev/null`
3649N/A if [ $? -eq 0 -a -n "$sendmail_path" ]; then
3649N/A turn_m4_crank "$SENDMAIL_CF" "$sendmail_path"
3649N/A fi
3649N/A exist_or_exit "$SENDMAIL_CF"
3649N/A if [ -n "$db_version_upgrade_needed" ]; then
3649N/A # Find the Keyed map lines, extract the arguments, run
3649N/A # makemap to create the maps with the upgraded DB version.
3649N/A /usr/bin/nawk '
3649N/A $1 ~ /^K/ && $2 ~ /^(hash|btree|dbm)$/ {
3649N/A print $2, $NF
3649N/A } ' "$SENDMAIL_CF" |
3649N/A while read dbtyp file; do
3649N/A if [ "$dbtyp" == "dbm" ]; then
3649N/A /usr/bin/rm -f $file.dir $file.pag
3649N/A else
3649N/A /usr/bin/rm -f $file.db
3649N/A fi
3649N/A echo "Executing \"$MAKEMAP $dbtyp $file < $file\"."
3649N/A $MAKEMAP $dbtyp $file < $file
3649N/A result=$?
3649N/A if [ $result -ne 0 ]; then
3649N/A echo "Failed to update keyed map files."
3649N/A echo "$MAKEMAP failed with error $result."
3649N/A echo "Run makemap manually."
3649N/A exit $SMF_EXIT_ERR_CONFIG
3649N/A fi
3649N/A done
3649N/A
3649N/A # Finally, update the service property.
3649N/A /usr/sbin/svccfg -s $SMF_FMRI setprop config/db_version=5
3649N/A
3649N/A # We refresh the service to get the above property setting
3649N/A # into the running snapshot. This will result in SMF
3649N/A # invoking this script with $1 set to "refresh" immediately
3649N/A # upon completion of this "start" invocation. But since
3649N/A # sendmail sets up its SIGHUP handler before it writes
3649N/A # its PID file, this should be OK: either the PID file
3649N/A # will not yet exist, in which case, the "refresh" will
3649N/A # do nothing (beyond getting the property setting into the
3649N/A # running snapshot), or the PID file will exist, in which
3649N/A # case the SIGHUP handler will have already been set up,
3649N/A # and sendmail will catch the SIGHUP and re-exec itself.
3649N/A /usr/sbin/svcadm refresh $SMF_FMRI
3649N/A fi
3649N/A
3649N/A $SENDMAIL $MODE -q$QUEUEOPTION$QUEUEINTERVAL $OPTIONS &
3649N/A
3649N/A #
3649N/A # ETRN_HOSTS should be of the form
3649N/A # "s1:c1.1,c1.2 s2:c2.1 s3:c3.1,c3.2,c3.3"
3649N/A # i.e., white-space separated groups of server:client where
3649N/A # client can be one or more comma-separated names; N.B. that
3649N/A # the :client part is optional; see etrn(1M) for details.
3649N/A # server is the name of the server to prod; a mail queue run
3649N/A # is requested for each client name. This is comparable to
3649N/A # running "/usr/lib/sendmail -qRclient" on the host server.
3649N/A #
3649N/A # See RFC 1985 for more information.
3649N/A #
3649N/A for i in $ETRN_HOSTS; do
3649N/A SERVER=`echo $i | /usr/bin/sed -e 's/:.*$//'`
3649N/A CLIENTS=`echo $i | /usr/bin/sed -n -e 's/,/ /g' \
3649N/A -e '/:/s/^.*://p'`
3649N/A /usr/sbin/etrn -b $SERVER $CLIENTS >/dev/null 2>&1 &
3649N/A done
3649N/A
3649N/A if /usr/bin/nawk 'BEGIN{s = 1}
3649N/A $2 == "/var/mail" && $3 == "nfs" && $4 !~ /actimeo=0/ &&
3649N/A $4 !~ /noac/{s = 0} END{exit s}' /etc/mnttab; then
3649N/A
3649N/A /usr/bin/logger -p mail.crit "$ERRMSG1"
3649N/A /usr/bin/logger -p mail.crit "$ERRMSG2"
3649N/A fi
3649N/A ;;
3649N/A
3649N/A'stop')
3649N/A [ -f $SERVER_PID_FILE ] && check_and_kill $SERVER_PID_FILE
3649N/A # Need to kill the entire service contract to kill all sendmail related
3649N/A # processes
3649N/A smf_kill_contract $2 TERM 1 30
3649N/A ret=$?
3649N/A [ $ret -eq 1 ] && exit 1
3649N/A
3649N/A # Since sendmail spawns user processes out of .forward files, it is
3649N/A # possible that some of these are not responding to TERM. If the
3649N/A # contract did not empty after TERM, move on to KILL.
3649N/A if [ $ret -eq 2 ] ; then
3649N/A smf_kill_contract $2 KILL 1
3649N/A fi
3649N/A ;;
3649N/A
3649N/A*)
3649N/A echo "Usage: $0 { start | stop | refresh }"
3649N/A exit 1
3649N/A ;;
3649N/Aesac
3649N/Aexit 0