# @(#) $Id: fetchmail2.SuSE.txt,v 1.2 2005/11/21 21:13:11 web2 Exp $ #! /bin/sh # Copyright (c) 2004 Christian Barmala # License GNU Public License http://opensource.org/licenses/gpl-license.php # ### BEGIN INIT INFO # Provides: fetchmail2 # Required-Start: $syslog $network # X-UnitedLinux-Should-Start: # Required-Stop: $syslog $network # X-UnitedLinux-Should-Stop: # Default-Start: 3 5 # Default-Stop: 0 1 2 6 # Short-Description: Fetch mails for configured users # Description: Start fetchmail as configured users. # You must create configuration files $HOME/.fetchmailrc first. ### END INIT INFO # # Required-Start: $remote_fs cyrus postfix $syslog ??? # Check for missing binaries (stale symlinks should not happen) FETCHMAIL_BIN=/usr/bin/fetchmail test -x $FETCHMAIL_BIN || exit 5 # Check for configured users test -f /etc/sysconfig/fetchmail2 || exit 6 test -n $FETCHMAIL_USERS || exit 6 # Configure users to use fetchmail2 service # FETCHMAIL_USERS='User1 User2 User3' . /etc/sysconfig/fetchmail2 # Return values acc. to LSB for all commands but status: # 0 - success # 1 - generic or unspecified error # 2 - invalid or excess argument(s) # 3 - unimplemented feature (e.g. "reload") # 4 - user had insufficient privileges # 5 - program is not installed # 6 - program is not configured # 7 - program is not running # 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl) # # Note that starting an already running service, stopping # or restarting a not-running service as well as the restart # with force-reload (in case signaling is not supported) are # considered a success. startfetch() { for USER in $FETCHMAIL_USERS; do USER_HOME=`grep $USER /etc/passwd | cut -d : -f 6` FETCHMAIL_PIDFILE=$USER_HOME/.fetchmail.pid if [ -f ${FETCHMAIL_PIDFILE} ]; then FETCHMAIL_PID=`cut -d " " -f 1 $FETCHMAIL_PIDFILE` echo fetchmail already running for user $USER: $FETCHMAIL_PID exit 1 fi FETCHMAIL_CONFIG=$USER_HOME/.fetchmailrc if [ -f ${FETCHMAIL_CONFIG} ]; then echo "Starting fetchmail-daemon for $USER" /usr/bin/sudo -u $USER -H $FETCHMAIL_BIN -d 500 echo "." else echo ".fetchmailrc for user $USER missing" fi done } stopfetch() { for USER in $FETCHMAIL_USERS; do echo "Shutting down fetchmail-daemon for $USER" /usr/bin/sudo -u $USER -H $FETCHMAIL_BIN --quit echo "." done } statusfetch() { # Return value is slightly different for the status command: # 0 - service up and running # 1 - service dead, but /var/run/ pid file exists # 2 - service dead, but /var/lock/ lock file exists # 3 - service not running (unused) # 4 - service status unknown :-( # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.) echo "Checking for service fetchmail2" for USER in $FETCHMAIL_USERS; do USER_HOME=`grep $USER /etc/passwd | cut -d : -f 6` FETCHMAIL_PIDFILE=$USER_HOME/.fetchmail.pid if [ -f ${FETCHMAIL_PIDFILE} ]; then FETCHMAIL_PID=`cut -d " " -f 1 $FETCHMAIL_PIDFILE` echo fetchmail running for user $USER: $FETCHMAIL_PID # ps -p $FETCHMAIL_PID fi done exit 4 } case "$1" in start) echo "Starting fetchmail2" startfetch ;; stop) echo "Shutting down fetchmail2" stopfetch ;; restart) ## Stop the service and regardless of whether it was ## running or not, start it again. stopfetch startfetch ;; status) statusfetch ;; *) echo "Usage: $0 {start|stop|status|restart}" exit 1 ;; esac exit 0