Demon fetchmail

Pàgina inicial

Reply to this message
Autor: Olivier Allard-Jacquin
Data:  
A: Guilde Mailing list
Assumpte: Demon fetchmail
    Bonsoir,

    suite aux mails de la semaine dernière à propos de fetchmail, j'ai 
patché le script d'init de Fetchmail de la Mandrake 9.2 
(/etc/init.d/fetchmail), afin de le faire tourner
sous un compte autre que celui du root.


         Le /etc/init.d/fetchmail permet de centraliser la récupération 
des mails de plusieurs utilisateurs, en un seul fichier de configuration
(/etc/fetchmailrc). Mais dans la configuration actuelle, le demon est 
lancé en temps que root, ce qui n'est pas spécialement judicieux en 
terme de sécurité.


    Bien entendu, vous pouvez ne pas utiliser ce démon fetchmail, et 
laisser un autre utilisateur lancer fetchmail "a la main".


- Pour lancer le demon fetchmail : "service fetchmail start"
- Pour arréter le demon fetchmail : "service fetchmail stop"
- Pour forcer fetchmail a récupérer immediatement les mails : "service
fetchmail reload"

    A titre d'exemple, je fourni aussi un fichier de configuration 
/etc/fetchmailrc . Le parametre "set daemon 900" lance la récupération 
de mails toutes les 15 minutes (900 secondes).


                Olivier


-- 
~~~~~~~  _____/\_____  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Phoenix /   _ \/ _   \    Olivier Allard-Jacquin
       /   / \  / \   \   Web:  http://olivieraj.free.fr/
      /___/  /  \  \___\  Mail: olivieraj@???
~~~~ /////  ///\\\  \\\\\ ~~~~~~~~~~~~~~~~~~~~~~~ Linux Powered !!

# Put here each user config

defaults proto pop3 fetchall no keep no rewrite
set daemon 900

poll pop.free.fr        user olivierxxxxxx              password xxxxxxxxxxxx   is mail-a   here
poll pop.xxxx.xxx       user olivierxxxxxx              password xxxxxxxxxxxx   is mail-b   here

#!/bin/sh
#
# chkconfig: 345 91 35
# description:    Starts and stops the fetchmail daemon used to retrive mail \
#        via various protocols (such as POP3 and IMAP4).
#
# config:    /etc/fetchmailrc


# Source function library.
. /etc/rc.d/init.d/functions

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

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

# Check that fetchmailrc exists.
[ -s /etc/fetchmailrc ] || exit 0

# (2004/04/08) Ajout par Olivier
# Fait tourner le programme fetchmail sous le compte "fetchmail"
PROGRAM_USER=fetchmail
LOG_FILE=/var/log/fetchmail.log
CONFIGURATION_FILE=/etc/fetchmailrc

RETVAL=0

# See how we were called.
case "$1" in
  start)
    if [ ! -f /var/lock/subsys/fetchmail ]; then
        gprintf "Starting Fetchmail services: "


# (2004/04/08) Ajout par Olivier : Lance fetchmail sous le compte de "$PROGRAM_USER"
#        daemon fetchmail -f /etc/fetchmailrc
        chown $PROGRAM_USER:$PROGRAM_USER $CONFIGURATION_FILE $LOG_FILE && \
        chmod 600 $CONFIGURATION_FILE && \
        daemon --user $PROGRAM_USER fetchmail -f $CONFIGURATION_FILE -L $LOG_FILE


        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/fetchmail
    else
        RETVAL=1
    fi
        ;;
  stop)
    if [ -f /var/lock/subsys/fetchmail ]; then
#        killproc fetchmail


# (2004/04/08) Ajout par Olivier : Arrête fetchmail lorsqu'il tourne sous le compte de "$PROGRAM_USER"
#        action "Shutting Fetchmail services: " /usr/bin/fetchmail --quit
        action "Shutting Fetchmail services: " su -s /bin/bash - $PROGRAM_USER -c \"/usr/bin/fetchmail --quit\"


        rm -f /var/lock/subsys/fetchmail >/dev/null 2>&1
        RETVAL=$?
    else
        RETVAL=1
    fi    
        ;;
  restart)
    $0 stop
    $0 start
    RETVAL=$?
    ;;
  reload)
    if [ -f /var/lock/subsys/fetchmail ]; then
           gprintf "Reloading fetchmailrc file: "
        killproc fetchmail -HUP
        RETVAL=$?
        echo
    else
        RETVAL=1
    fi
    ;;
  status)
    status fetchmail
    RETVAL=$?
    ;;
  *)
    gprintf "Usage: %s {start|stop|restart|reload|status|force}\n" "$0"
    exit 1
esac


exit $RETVAL