No mail at shutdown by initscript - Mandrake

This is a discussion on No mail at shutdown by initscript - Mandrake ; Hi, I have a script that sends status reports by email via postfix from other computers to my computer over the internet. The reports contain login info and psacct info. However the email is not sent at shutdown, it remains ...

+ Reply to Thread
Results 1 to 17 of 17

Thread: No mail at shutdown by initscript

  1. No mail at shutdown by initscript

    Hi, I have a script that sends status reports by email via postfix from
    other computers to my computer over the internet. The reports contain
    login info and psacct info. However the email is not sent at shutdown,
    it remains in the postfix queue. It is only sent at the next boot. Does
    anyone know what could be wrong?

    This is the script:

    #!/bin/bash

    ### BEGIN INIT INFO
    # Provides: mailboothalt
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Required-Start: $network postfix
    # Required-Stop: $network postfix
    # Short-Description: Send mail about startup/shutdown
    # Description: Mail users about computer startup/shutdown.
    ### END INIT INFO

    if [ -f /etc/rc.d/init.d/functions ]; then

    . /etc/rc.d/init.d/functions
    else

    exit 0

    fi

    [ ! -f /etc/sysconfig/mailboothalt ] && exit 1

    .. /etc/sysconfig/mailboothalt

    [ -z "${EMAIL}" ] && exit 1

    HOST="`hostname -s | tr [:lower:] [:upper:]`"

    case "$1" in

    start) gprintf "`hostname` boot: \n"
    echo -e "`hostname` boot at `LC_TIME=nl date`" | \
    /bin/mail -s "${HOST} BOOTED `LC_TIME=nl date "+%A %d %B %Y %H:%M"`"
    "${EMAIL}" && success

    touch /var/lock/subsys/mailboothalt
    ;;

    stop) if [ -x "/usr/local/sbin/security-info" ]; then

    gprintf "`hostname` shutdown: \n"
    (/usr/local/sbin/security-info ; echo -e "\n`hostname` stopped at
    `date`.") |\
    /bin/mail -s "${HOST} SHUTDOWN `LC_TIME=nl date "+%A %d %B %Y
    %H:%M"`" "${EMAIL}" && success

    else

    gprintf "`hostname` shutdown: \n"
    echo -e "\n`hostname` stopped at `LC_TIME=nl date`.\n`uptime | cut
    -d "," -f 1 |\
    sed "s|[ ][0-9][0-9][:][0-9][0-9][:][0-9][0-9][ ]up[ ]|Computer
    heeft gedurende een periode van |"` gedraaid." |\
    /bin/mail -s "${HOST} STOPPED `LC_TIME=nl date "+%A %d %B %Y
    %H:%M"`" "${EMAIL}" && success

    fi

    /sbin/service postfix flush
    #/usr/sbin/postfix flush
    #/usr/sbin/sendmail -q

    rm -f /var/lock/subsys/mailboothalt
    ;;

    *) echo "Usage: /etc/rc.d/init.d/mailboothalt {start|stop}"
    exit 1
    ;;

    esac

    exit 0

  2. Re: No mail at shutdown by initscript

    On Tue, 13 Feb 2007 14:58:15 -0500, Maxim Heijndijk wrote:

    > Hi, I have a script that sends status reports by email via postfix from
    > other computers to my computer over the internet. The reports contain
    > login info and psacct info. However the email is not sent at shutdown,
    > it remains in the postfix queue. It is only sent at the next boot. Does
    > anyone know what could be wrong?
    > /sbin/service postfix flush


    I believe you need the postfix/pickup, cleanup, and qmgr daemons to run
    between the sendmail and the flush. I don't see anything in the man files
    on how to force this to happen. I think running a service postfix reload
    may do it. Worth a try.

    Regards, Dave Hodgins

    --
    Change nomail.afraid.org to ody.ca to reply by email.
    (nomail.afraid.org has been set up specifically for
    use in usenet. Feel free to use it yourself.)

  3. Re: No mail at shutdown by initscript

    On Tue, 13 Feb 2007 20:58:15 +0100, Maxim Heijndijk wrote:
    > Hi, I have a script that sends status reports by email via postfix from
    > other computers to my computer over the internet. The reports contain
    > login info and psacct info. However the email is not sent at shutdown,
    > it remains in the postfix queue. It is only sent at the next boot. Does
    > anyone know what could be wrong?


    My swag, postfix received the message, placed in outbound queue for
    next minute(s) transmission window. But system is going down so
    transmission queue is on hold.

    Or, cannot complete handshake/handoff with smart relay before network
    goes down.


  4. Re: No mail at shutdown by initscript

    David W. Hodgins schreef:

    > On Tue, 13 Feb 2007 14:58:15 -0500, Maxim Heijndijk wrote:
    >
    >> Hi, I have a script that sends status reports by email via postfix from
    >> other computers to my computer over the internet. The reports contain
    >> login info and psacct info. However the email is not sent at shutdown,
    >> it remains in the postfix queue. It is only sent at the next boot. Does
    >> anyone know what could be wrong?
    >> /sbin/service postfix flush

    >
    > I believe you need the postfix/pickup, cleanup, and qmgr daemons to run
    > between the sendmail and the flush. I don't see anything in the man files
    > on how to force this to happen. I think running a service postfix reload
    > may do it. Worth a try.
    >
    > Regards, Dave Hodgins


    Thanx, but service postfix reload does not work.

    Regards, Max Heijndijk.

  5. Re: No mail at shutdown by initscript

    Bit Twister schreef:
    > On Tue, 13 Feb 2007 20:58:15 +0100, Maxim Heijndijk wrote:
    >> Hi, I have a script that sends status reports by email via postfix from
    >> other computers to my computer over the internet. The reports contain
    >> login info and psacct info. However the email is not sent at shutdown,
    >> it remains in the postfix queue. It is only sent at the next boot. Does
    >> anyone know what could be wrong?

    >
    > My swag, postfix received the message, placed in outbound queue for
    > next minute(s) transmission window. But system is going down so
    > transmission queue is on hold.


    So how do I fix that?

    > Or, cannot complete handshake/handoff with smart relay before network
    > goes down.


    What is a smart relay?

    Regards, Max Heijndijk

  6. Re: No mail at shutdown by initscript

    On 2007-02-14, Maxim Heijndijk wrote:
    > David W. Hodgins schreef:
    >
    >> On Tue, 13 Feb 2007 14:58:15 -0500, Maxim Heijndijk wrote:
    >>
    >>> Hi, I have a script that sends status reports by email via postfix from
    >>> other computers to my computer over the internet. The reports contain
    >>> login info and psacct info. However the email is not sent at shutdown,
    >>> it remains in the postfix queue. It is only sent at the next boot. Does
    >>> anyone know what could be wrong?
    >>> /sbin/service postfix flush

    >>
    >> I believe you need the postfix/pickup, cleanup, and qmgr daemons to run
    >> between the sendmail and the flush. I don't see anything in the man files
    >> on how to force this to happen. I think running a service postfix reload
    >> may do it. Worth a try.
    >>
    >> Regards, Dave Hodgins

    >
    > Thanx, but service postfix reload does not work.


    The correct command is most likely

    postfix reload

    HTH

    --
    Robert Riches
    spamtrap42@verizon.net
    (Yes, that is one of my email addresses.)

  7. Re: No mail at shutdown by initscript

    On 2007-02-14, Maxim Heijndijk wrote:
    > Bit Twister schreef:
    >> On Tue, 13 Feb 2007 20:58:15 +0100, Maxim Heijndijk wrote:
    >>> Hi, I have a script that sends status reports by email via postfix from
    >>> other computers to my computer over the internet. The reports contain
    >>> login info and psacct info. However the email is not sent at shutdown,
    >>> it remains in the postfix queue. It is only sent at the next boot. Does
    >>> anyone know what could be wrong?

    >>
    >> My swag, postfix received the message, placed in outbound queue for
    >> next minute(s) transmission window. But system is going down so
    >> transmission queue is on hold.

    >
    > So how do I fix that?


    If you want the email message to get out before the system
    shuts down, you'll need to somehow introduce a delay between
    sending the message and proceeding with shutdown. The
    specifics of how to do that would depend on the specifics of
    your situation.

    >> Or, cannot complete handshake/handoff with smart relay before network
    >> goes down.

    >
    > What is a smart relay?


    The "smart relay" would probably refer your ISP's outbound
    email server, at least if you're sending the message through
    that server.


    It's a reference to the arguably misguided attempt to reduce
    spam by convincing everyone that they can't send email
    directly from one computer to another but must send through
    their ISP's outbound email server to the destination ISP's
    inbound email server. A good friend of mine described that
    situation by saying, "Spam has broken the internet." With a
    bit of work, Postfix can be configured to send directly or
    through a "smart relay" based on the destination domain. If
    you're lucky, the "smart relay" won't delay messages by
    several minutes in the best case and a couple of days in bad
    cases. My mother's ISP's inbound mail servers are too
    snobbish to accept direct email from DSL customers of my
    ISP, so I have to send through my ISP's "smart relay". One
    time, she hadn't received a message I had sent. 44 hours
    after I first sent the message, I received a notice that my
    ISP's "smart relay" was having difficulty communicating with
    Yahoo's mail server. Normal convention is to send delay
    notices at 4 hours, not just shy of _two_ _DAYS_!


    HTH

    --
    Robert Riches
    spamtrap42@verizon.net
    (Yes, that is one of my email addresses.)

  8. Re: No mail at shutdown by initscript

    On Wed, 14 Feb 2007 16:59:51 +0100, Maxim Heijndijk wrote:
    > Bit Twister schreef:
    >>
    >> My swag, postfix received the message, placed in outbound queue for
    >> next minute(s) transmission window. But system is going down so
    >> transmission queue is on hold.

    >
    > So how do I fix that?


    Well, with the old init script setup, I would have attempted to get my script
    to run first on shutdown by naming the script amailboothalt

    Something to play with, create /sbin/ifdown-pre-local

    What would happen is /sbin/ifdown would run /sbin/ifdown-pre-local ${DEVICE}

    Your /sbin/ifdown-pre-local would check arg 1 (eth0, eth1,,,) and
    decide if that is the device to wait/sleep on. If so
    /sbin/ifdown-pre-local could check for a flag file set by mailboothalt
    on stop, delete it, sleep X_seconds.

    Go ahead and create /sbin/ifdown-pre-local with

    date >> /root/pre.env
    echo "arg1 = $1" >> /root/pre.env
    env >> /root/pre.env
    echo "_______________" >> /root/pre.env


    chmod +x /sbin/ifdown-pre-local
    and do a
    service network restart
    and a reboot to see contents of variables available to /sbin/ifdown-pre-local

    >> Or, cannot complete handshake/handoff with smart relay before network
    >> goes down.

    >
    > What is a smart relay?


    Dang, should have looked it up, it's relayhost not smart relay.
    Sorry.

    As part of postfix's setup, you define the next MTA to take your mail
    you are sending from your node.


  9. Re: No mail at shutdown by initscript

    On Wed, 14 Feb 2007 13:19:57 -0500, Robert M. Riches Jr. wrote:

    > The correct command is most likely
    > postfix reload


    Same effect as "service postfix reload".

    I'm thinking It might be better to run "postfix stop"
    followed by a wait for the processes pickup and qmgr
    to stop. Either that, or sleep for 60 seconds, after
    sending the mail.

    Regards, Dave Hodgins

    --
    Change nomail.afraid.org to ody.ca to reply by email.
    (nomail.afraid.org has been set up specifically for
    use in usenet. Feel free to use it yourself.)

  10. Re: No mail at shutdown by initscript

    On 2007-02-14, David W. Hodgins wrote:
    > On Wed, 14 Feb 2007 13:19:57 -0500, Robert M. Riches Jr. wrote:
    >
    >> The correct command is most likely
    >> postfix reload

    >
    > Same effect as "service postfix reload".


    And what was that? Exactly what response did you get?
    Please cut and paste (don't paraphrase) the warnings and/or
    errors you got. Oh, did you try that as root or as a
    non-root user?

    > I'm thinking It might be better to run "postfix stop"
    > followed by a wait for the processes pickup and qmgr
    > to stop. Either that, or sleep for 60 seconds, after
    > sending the mail.


    Once "postfix stop" has finished, I would be surprised to
    see the pickup or qmgr processes still alive. Are you
    saying they survive after finishing the "postfix stop"?

    A sleep of a fixed number of seconds might work or might not
    if the message takes a minute or two to bounce through steps
    in the process. I believe there is a way, either a postfix
    or a postsuper command, to force a queue run immediately.

    HTH

    --
    Robert Riches
    spamtrap42@verizon.net
    (Yes, that is one of my email addresses.)

  11. Re: No mail at shutdown by initscript

    Maxim Heijndijk writes:

    >David W. Hodgins schreef:


    >> On Tue, 13 Feb 2007 14:58:15 -0500, Maxim Heijndijk wrote:
    >>
    >>> Hi, I have a script that sends status reports by email via postfix from
    >>> other computers to my computer over the internet. The reports contain
    >>> login info and psacct info. However the email is not sent at shutdown,
    >>> it remains in the postfix queue. It is only sent at the next boot. Does
    >>> anyone know what could be wrong?
    >>> /sbin/service postfix flush


    No idea what you mean. If that status report is sent on shutdown, then the
    system almost certainly shuts down and kills all the postfix stuff before
    it has a chance to send it. It takes a number of seconds to clean out a
    queue.



    >>
    >> I believe you need the postfix/pickup, cleanup, and qmgr daemons to run
    >> between the sendmail and the flush. I don't see anything in the man files
    >> on how to force this to happen. I think running a service postfix reload
    >> may do it. Worth a try.
    >>
    >> Regards, Dave Hodgins


    >Thanx, but service postfix reload does not work.


    "does not work" means what? The computer crashes?



  12. Re: No mail at shutdown by initscript

    Unruh schreef:
    > Maxim Heijndijk writes:
    >
    >> David W. Hodgins schreef:

    >
    >>> On Tue, 13 Feb 2007 14:58:15 -0500, Maxim Heijndijk wrote:
    >>>
    >>>> Hi, I have a script that sends status reports by email via postfix from
    >>>> other computers to my computer over the internet. The reports contain
    >>>> login info and psacct info. However the email is not sent at shutdown,
    >>>> it remains in the postfix queue. It is only sent at the next boot. Does
    >>>> anyone know what could be wrong?
    >>>> /sbin/service postfix flush

    >
    > No idea what you mean. If that status report is sent on shutdown, then the
    > system almost certainly shuts down and kills all the postfix stuff before
    > it has a chance to send it. It takes a number of seconds to clean out a
    > queue.


    The postfix service is stopped AFTER the mailscript.

    >>> I believe you need the postfix/pickup, cleanup, and qmgr daemons to run
    >>> between the sendmail and the flush. I don't see anything in the man files
    >>> on how to force this to happen. I think running a service postfix reload
    >>> may do it. Worth a try.
    >>>
    >>> Regards, Dave Hodgins

    >
    >> Thanx, but service postfix reload does not work.

    >
    > "does not work" means what? The computer crashes?


    The mail is not sent.

  13. Re: No mail at shutdown by initscript

    Maxim Heijndijk schreef:

    > Hi, I have a script that sends status reports by email via postfix from
    > other computers to my computer over the internet. The reports contain
    > login info and psacct info. However the email is not sent at shutdown,
    > it remains in the postfix queue. It is only sent at the next boot. Does
    > anyone know what could be wrong?


    It turned out I had to add a sleep 15 command at the end of the start
    section. I tried to let the script run as the first script at shutdown,
    but it was always executed right before the shutdown of postfix, no
    matter what put in the chkconfig init info section. Thank you all for
    your help.

    --
    Best regards, Max Heijndijk

    Photography - http://www.maccusfoto.nl
    Soundscapes - http://www.maccusfoto.nl/cchq
    Linux - http://www.maccusfoto.nl/conmen

  14. Re: No mail at shutdown by initscript

    On Fri, 16 Feb 2007 21:27:39 +0100, Maxim Heijndijk wrote:
    > Maxim Heijndijk schreef:
    >
    >> Hi, I have a script that sends status reports by email via postfix from
    >> other computers to my computer over the internet. The reports contain
    >> login info and psacct info. However the email is not sent at shutdown,
    >> it remains in the postfix queue. It is only sent at the next boot. Does
    >> anyone know what could be wrong?

    >
    > It turned out I had to add a sleep 15 command at the end of the
    > start section.


    Should that not be in the stop section.??

  15. Re: No mail at shutdown by initscript

    Maxim Heijndijk wrote:

    > Maxim Heijndijk schreef:
    >
    >> Hi, I have a script that sends status reports by email via postfix from
    >> other computers to my computer over the internet. The reports contain
    >> login info and psacct info. However the email is not sent at shutdown,
    >> it remains in the postfix queue. It is only sent at the next boot. Does
    >> anyone know what could be wrong?

    >
    > It turned out I had to add a sleep 15 command at the end of the start
    > section. I tried to let the script run as the first script at shutdown,
    > but it was always executed right before the shutdown of postfix, no
    > matter what put in the chkconfig init info section. Thank you all for
    > your help.
    >

    Maybe a "postqueue -f" in your script could help as well.
    Btw., why are you so eager to receive these log messages in an instant?
    --
    vista policy violation: Microsoft optical mouse found penguin patterns
    on mousepad. Partition scan in progress to remove offending
    incompatible products. Reactivate MS software.
    Linux 2.6.17-mm1,Xorg7.1/nvidia [LinuxCounter#295241,ICQ#4918962]

  16. Re: No mail at shutdown by initscript

    Maxim Heijndijk writes:

    >Hi, I have a script that sends status reports by email via postfix from
    >other computers to my computer over the internet. The reports contain
    >login info and psacct info. However the email is not sent at shutdown,
    >it remains in the postfix queue. It is only sent at the next boot. Does
    >anyone know what could be wrong?


    A queue is just that-- a place for things to wait. Postfix does not
    instantly do things. It places them into a queue for the next program to
    handle when it is woken up to check on the queue. On shutdown, there is no
    time.

    So you could put in a 5 min sleep to make sure that postfix has time to do
    its thing. But you might get annoyed if your shutdown took 5 min.




    >This is the script:


    >#!/bin/bash


    >### BEGIN INIT INFO
    ># Provides: mailboothalt
    ># Default-Start: 2 3 4 5
    ># Default-Stop: 0 1 6
    ># Required-Start: $network postfix
    ># Required-Stop: $network postfix
    ># Short-Description: Send mail about startup/shutdown
    ># Description: Mail users about computer startup/shutdown.
    >### END INIT INFO


    >if [ -f /etc/rc.d/init.d/functions ]; then


    > . /etc/rc.d/init.d/functions
    >else


    > exit 0


    >fi


    >[ ! -f /etc/sysconfig/mailboothalt ] && exit 1


    >. /etc/sysconfig/mailboothalt


    >[ -z "${EMAIL}" ] && exit 1


    >HOST="`hostname -s | tr [:lower:] [:upper:]`"


    >case "$1" in


    > start) gprintf "`hostname` boot: \n"
    > echo -e "`hostname` boot at `LC_TIME=nl date`" | \
    > /bin/mail -s "${HOST} BOOTED `LC_TIME=nl date "+%A %d %B %Y %H:%M"`"
    >"${EMAIL}" && success


    > touch /var/lock/subsys/mailboothalt
    > ;;


    > stop) if [ -x "/usr/local/sbin/security-info" ]; then


    > gprintf "`hostname` shutdown: \n"
    > (/usr/local/sbin/security-info ; echo -e "\n`hostname` stopped at
    >`date`.") |\
    > /bin/mail -s "${HOST} SHUTDOWN `LC_TIME=nl date "+%A %d %B %Y
    >%H:%M"`" "${EMAIL}" && success


    > else


    > gprintf "`hostname` shutdown: \n"
    > echo -e "\n`hostname` stopped at `LC_TIME=nl date`.\n`uptime | cut
    >-d "," -f 1 |\
    > sed "s|[ ][0-9][0-9][:][0-9][0-9][:][0-9][0-9][ ]up[ ]|Computer
    >heeft gedurende een periode van |"` gedraaid." |\
    > /bin/mail -s "${HOST} STOPPED `LC_TIME=nl date "+%A %d %B %Y
    >%H:%M"`" "${EMAIL}" && success


    > fi


    > /sbin/service postfix flush
    > #/usr/sbin/postfix flush
    > #/usr/sbin/sendmail -q


    > rm -f /var/lock/subsys/mailboothalt
    > ;;


    > *) echo "Usage: /etc/rc.d/init.d/mailboothalt {start|stop}"
    > exit 1
    > ;;


    >esac


    >exit 0


  17. Re: No mail at shutdown by initscript

    Bit Twister schreef:
    > On Fri, 16 Feb 2007 21:27:39 +0100, Maxim Heijndijk wrote:
    >> Maxim Heijndijk schreef:
    >>
    >>> Hi, I have a script that sends status reports by email via postfix from
    >>> other computers to my computer over the internet. The reports contain
    >>> login info and psacct info. However the email is not sent at shutdown,
    >>> it remains in the postfix queue. It is only sent at the next boot. Does
    >>> anyone know what could be wrong?

    >> It turned out I had to add a sleep 15 command at the end of the
    >> start section.

    >
    > Should that not be in the stop section.??


    Yes, indeed, the stop section....

+ Reply to Thread