Marc Adler wrote:
Ok, just as soon as I sent the above message, I realized I also had a
startup script for fetchmail that might have something to do with it. I
su'ed into root status and sure enough there in root's mutt were all the
lost messages. So now the problem is, what's wrong with the startup
script?
[snip init script]

Since running fetchmail as root is such an unbelievably bad idea that I can't believe anyone suggested it, I'm reposting a script based on one originally posted by Colin Cyr in 1998. Consider using this instead of the init script that you've got.

This init script has two advantages. First, it doesn't run as root, so you're less likely to have problems if someone finds an exploitable problem in fetchmail. Second, it allows users control over their own fetchmail process, so they can change the password in the fetchmailrc and restart the process if they need to.

#!/bin/sh
#
# fetchmail     This shell script takes care of starting and stopping
#               fetchmail.
#
# chkconfig: 345 81 31
# description: Fetchmail is a Mail Transport Agent, which is the program \
#              that moves mail from one machine to another.
# processname: fetchmail
# config: ~/.fetchmailrc
# pidfile: ~/.fetchmail.pid
FETCHMAIL=/usr/bin/fetchmail

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -f ${FETCHMAIL} ] || exit 0

# See how we were called.
case "$1" in
  start)
        # Start daemons.
        echo -n "Starting fetchmail:"
        for userdata in `getent passwd | cut -d: -f1,6`; do
            username=`echo ${userdata} | cut -d: -f1`
            userdir="`echo ${userdata} | cut -d: -f2`/.fetchmailrc"
            if [ -f ${userdir} ]; then
                su - ${username} -c "${FETCHMAIL} -d300 &> /dev/null"
                echo -n " ${username}"
            fi
        done
        echo
        ;;
  stop)
        # Stop daemons.
        echo -n "Shutting down fetchmail:"
        for userdata in `getent passwd | cut -d: -f1,6`; do
            username=`echo ${userdata} | cut -d: -f1`
            userdir="`echo ${userdata} | cut -d: -f2`/.fetchmail.pid"
            if [ -f ${userdir} ]; then
                su - ${username} -c "${FETCHMAIL} -q &> /dev/null"
                echo -n " ${username}"
            fi
        done
        echo
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  *)
        echo "Usage: fetchmail {start|stop|restart}"
        exit 1
esac

exit 0

Reply via email to