MikeL's FreeBSD howto - sendmail-restart

sendmail-restart is the mechanism I use to restart sendmail. Ensuring that all steps needed are performed when making changes to sendmail is becoming more and more difficult, necessitating this script.

Copy the following into a file named sendmail-restart in your /root/bin dir. Be sure to chmod it executable.

#!/usr/bin/perl

use strict;

# It looks like `sendmail -bi` is now smart enough to do the
# the `newaliases` for you...
# newaliases is only needed if you change the /etc/aliases file.
# newaliases

my @Cmds = (
    "makemap -v hash /etc/mail/access.db</etc/mail/access",

    "makemap -v hash /etc/mail/mailertable.db</etc/mail/mailertable",

    "makemap -v hash /etc/mail/virtusertable.db</etc/mail/virtusertable",

    # I believe that '-bi' is really all that is needed, but I'm leaving
    # the old 'kill -HUP' just in case.
    "sendmail -bi",

    # kill is needed if you change the /etc/sendmail.cf file.
    # It may also be  needed if you change virtusertable, but maybe not.
    "kill -HUP `head -1 /var/run/sendmail.pid`"
);


foreach (@Cmds) {
    print "$_\n";
    my @sysout = `$_`;
    my $err = 0;
    foreach (@sysout) {
        my $err = ($_ =~ /error/i);
        if ($err) {
            print "\"$_\"\n";
        }
    }
    if ($err) {
        exit 1;
    }
}


# Note!  'newaliases' seems to be smart enough to take care of this
#   automatically for you...
# makemap -v hash /usr/local/majordomo/aliases.majordomo</etc/mail/access

Copyright © 1995-2017 Mike Lempriere