ffmpeg-6: fix COMPONENT_REVISION
[oi-userland.git] / components / mail / sendmail / files / smtp-sendmail
blob950efd98995d269950c7e1697a146b94037c4036
1 #!/sbin/sh
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
22 # Copyright (c) 1991, 2013, Oracle and/or its affiliates. All rights reserved.
24 . /lib/svc/share/smf_include.sh
25 . /lib/svc/share/sendmail_include.sh
27 ERRMSG1='WARNING: /var/mail is NFS-mounted without setting actimeo=0,'
28 ERRMSG2='this can cause mailbox locking and access problems.'
29 SERVER_PID_FILE="/var/run/sendmail.pid"
30 ALIASES_FILE="/etc/mail/aliases"
31 SENDMAIL_CF="/etc/mail/sendmail.cf"
32 MAKEMAP="/usr/sbin/makemap"
34 case "$1" in
35 'refresh')
36 [ -f $SERVER_PID_FILE ] && kill -1 `head -1 $SERVER_PID_FILE`
39 'start')
40 exist_or_exit $SENDMAIL
41 if [ ! -d /var/spool/mqueue ]; then
42 /usr/bin/mkdir -m 0750 /var/spool/mqueue
43 /usr/bin/chown root:bin /var/spool/mqueue
45 if [ ! -d /var/mail/:saved ]; then
46 /usr/bin/mkdir -m 0775 /var/mail/:saved
47 /usr/bin/chown root:mail /var/mail/:saved
49 dbvers=`/usr/bin/svcprop -c -p config/db_version $SMF_FMRI 2>/dev/null`
50 if [ $? -ne 0 -o "$dbvers" != "5" ]; then
51 # Need to upgrade Berkeley DB version
52 # Part 1: blow away aliases DB files; we will recreate them
53 # just below.
54 # Part 2: keyed maps are handled further below.
55 /usr/bin/rm -f $ALIASES_FILE.db $ALIASES_FILE.dir \
56 $ALIASES_FILE.pag
57 db_version_upgrade_needed=true
59 if [ ! -f $ALIASES_FILE.db ] && [ ! -f $ALIASES_FILE.dir ] \
60 && [ ! -f $ALIASES_FILE.pag ]; then
61 /usr/sbin/newaliases
63 MODE="-bd"
64 [ -f $DEFAULT_FILE ] && . $DEFAULT_FILE
66 # * MODE should be "-bd" or null (MODE= or MODE="") or
67 # left alone. Anything else and you're on your own.
68 # * QUEUEOPTION should be "p" or null (as above).
69 # * QUEUEINTERVAL should be set to some legal value;
70 # sanity checks are done below.
71 # * OPTIONS are catch-alls; set with care.
73 if [ -n "$QUEUEOPTION" -a "$QUEUEOPTION" != "p" ]; then
74 QUEUEOPTION=""
76 if [ -z "$QUEUEOPTION" -o -n "$QUEUEINTERVAL" ]; then
77 check_queue_interval_syntax $QUEUEINTERVAL
78 QUEUEINTERVAL=$answer
81 local=`/usr/bin/svcprop -p config/local_only $SMF_FMRI 2>/dev/null`
82 if [ $? -eq 0 -a "$local" = "true" ]; then
83 MODE="-bl"
85 sendmail_path=`svcprop -p config/path_to_sendmail_mc $SMF_FMRI \
86 2>/dev/null`
87 if [ $? -eq 0 -a -n "$sendmail_path" ]; then
88 turn_m4_crank "$SENDMAIL_CF" "$sendmail_path"
90 exist_or_exit "$SENDMAIL_CF"
91 if [ -n "$db_version_upgrade_needed" ]; then
92 # Find the Keyed map lines, extract the arguments, run
93 # makemap to create the maps with the upgraded DB version.
94 /usr/bin/nawk '
95 $1 ~ /^K/ && $2 ~ /^(hash|btree|dbm)$/ {
96 print $2, $NF
97 } ' "$SENDMAIL_CF" |
98 while read dbtyp file; do
99 if [ "$dbtyp" == "dbm" ]; then
100 /usr/bin/rm -f $file.dir $file.pag
101 else
102 /usr/bin/rm -f $file.db
104 echo "Executing \"$MAKEMAP $dbtyp $file < $file\"."
105 $MAKEMAP $dbtyp $file < $file
106 result=$?
107 if [ $result -ne 0 ]; then
108 echo "Failed to update keyed map files."
109 echo "$MAKEMAP failed with error $result."
110 echo "Run makemap manually."
111 exit $SMF_EXIT_ERR_CONFIG
113 done
115 # Finally, update the service property.
116 /usr/sbin/svccfg -s $SMF_FMRI setprop config/db_version=5
118 # We refresh the service to get the above property setting
119 # into the running snapshot. This will result in SMF
120 # invoking this script with $1 set to "refresh" immediately
121 # upon completion of this "start" invocation. But since
122 # sendmail sets up its SIGHUP handler before it writes
123 # its PID file, this should be OK: either the PID file
124 # will not yet exist, in which case, the "refresh" will
125 # do nothing (beyond getting the property setting into the
126 # running snapshot), or the PID file will exist, in which
127 # case the SIGHUP handler will have already been set up,
128 # and sendmail will catch the SIGHUP and re-exec itself.
129 /usr/sbin/svcadm refresh $SMF_FMRI
132 $SENDMAIL $MODE -q$QUEUEOPTION$QUEUEINTERVAL $OPTIONS &
135 # ETRN_HOSTS should be of the form
136 # "s1:c1.1,c1.2 s2:c2.1 s3:c3.1,c3.2,c3.3"
137 # i.e., white-space separated groups of server:client where
138 # client can be one or more comma-separated names; N.B. that
139 # the :client part is optional; see etrn(1M) for details.
140 # server is the name of the server to prod; a mail queue run
141 # is requested for each client name. This is comparable to
142 # running "/usr/lib/sendmail -qRclient" on the host server.
144 # See RFC 1985 for more information.
146 for i in $ETRN_HOSTS; do
147 SERVER=`echo $i | /usr/bin/sed -e 's/:.*$//'`
148 CLIENTS=`echo $i | /usr/bin/sed -n -e 's/,/ /g' \
149 -e '/:/s/^.*://p'`
150 /usr/sbin/etrn -b $SERVER $CLIENTS >/dev/null 2>&1 &
151 done
153 if /usr/bin/nawk 'BEGIN{s = 1}
154 $2 == "/var/mail" && $3 == "nfs" && $4 !~ /actimeo=0/ &&
155 $4 !~ /noac/{s = 0} END{exit s}' /etc/mnttab; then
157 /usr/bin/logger -p mail.crit "$ERRMSG1"
158 /usr/bin/logger -p mail.crit "$ERRMSG2"
162 'stop')
163 [ -f $SERVER_PID_FILE ] && check_and_kill $SERVER_PID_FILE
164 # Need to kill the entire service contract to kill all sendmail related
165 # processes
166 smf_kill_contract $2 TERM 1 30
167 ret=$?
168 [ $ret -eq 1 ] && exit 1
170 # Since sendmail spawns user processes out of .forward files, it is
171 # possible that some of these are not responding to TERM. If the
172 # contract did not empty after TERM, move on to KILL.
173 if [ $ret -eq 2 ] ; then
174 smf_kill_contract $2 KILL 1
179 echo "Usage: $0 { start | stop | refresh }"
180 exit 1
182 esac
183 exit 0