Greetings one and all!![]()
This script has been broken into several files.
The best way to install it is with the rpm. Check the links below.
I wrote an init script to manage fetchmail on a multi user mail server.
It's useful for me due to the fact that I have many users that have multiple email accounts across the internet. And they only want to have one account setup in evolution.
I use fetchmail in conjunction with hotwayd to pull email from hotmail accounts.
I'm in the process of rebuilding my site, but you can also get this script from
fetchmail-init home
Corrections were made to the chkconfig line, thanks to tberer for catching that.![]()
If you find the following script useful, please let me know.
be sure to have a working ~/.fetchmailrc
you can also get the rpm here:
http://bink.homeip.net/projects/fetchmail/index.shtml
Setup: rpm -ivh http://www.vparsons.org/data/fetchma...1-0.noarch.rpm
rpm may complain about the gpg key, you can get that here:
http://www.vparsons.org/projects/RPM...Y.vparsons.txt
OLD - Copy the text into /etc/init.d/fetchmail
Make it executable.
Code:chmod 755 /etc/init.d/fetchmail chkconfig --add fetchmail chkconfig --level 345 fetchmail on service fetchmail start
Script Text below...
cheersCode:THIS SCRIPT IS OLD, PLEASE INSTALL THE RPM FOR THE LATEST... http://www.vparsons.org/data/fetchmail-init-1.1-0.noarch.rpm #!/bin/bash ## BEGIN chkconfig header # chkconfig: 345 80 30 # processname: /usr/bin/fetchmail # description: sysv init script to manage user fetchmail processes ## END chkconfig header ## ## AUTHOR: ## Vince Parsons ## Description: ## fetchmail-init is a sysv init script that manages fetchmail for local users \ ## by searching through users home directories for .fetchmailrc and \ ## starting daemons on the users behalf. fetchmail-init should work \ ## on any platform based on Red Hat Linux 7 and above. ## LICENSE: ## GNU GPL ## COPYRIGHT: ## none this work is in the public domain. ## VERSION INFO: ## 1.0.12 (2005.02.19) - Development ## REQUIREMENTS: ## bash, fetchmail ## INSTALLATION: ## Make this script executable and place it somewhere in your path. ## USAGE: ## fetchmail {start|stop|restart|cleanup|status} ## Only the superuser can run this script. [ ${UID} -eq 0 ] || exit 1 ## Source function library and network configuration. [ -r /etc/init.d/functions ] && . /etc/init.d/functions [ -r /etc/sysconfig/network ] && . /etc/sysconfig/network ## Set defaults. PATH="/bin:/sbin:/usr/bin:/usr/sbin" export PROGRAM="/usr/bin/fetchmail" export OPTIONS="-d 300 --nobounce" prog="fetchmail" LOCKFILE="/var/lock/subsys/fetchmail" PIDFILE="/var/run/fetchmail.pid" USERS=`ls -1 /home | grep -v lost+found` RETVAL=0 ERRNO=0 ERRNO1=0 ERRNO2=0 ERRNO3=0 ERRNO4=0 ErrorControl="yes" # Extended error control on startup. ## Use /etc/sysconfig/fetchmail to overide any of the defaults set above. [ -r /etc/sysconfig/fetchmail ] && . /etc/sysconfig/fetchmail function depend() { ## Make sure everything is happy before we continue. [ ${NETWORKING} = "no" ] && exit 2 [ -x ${PROGRAM} ] || exit 3 [ -x /bin/su ] || exit 4 [ -x /sbin/pidof ] || exit 5 ## You can disable all of the extended error checking if you wish. ## Set variable ErrorControl to no. Good luck if something breaks... if [ ${ErrorControl} = "yes" ]; then ## For the sake of our sanity, lets do some error checking, make sure all is well. ## FETCHMAILRC is set here to speed up the script, we only need it for start/restart. FETCHMAILRC=`find /home -name ".fetchmailrc"` ## See if ~/.fetchmailrc exists. [[ ${FETCHMAILRC} = "" ]] && ERRNO=9 ## See if /var/lock/subsys/fetchmail.* exists. [ -e ${LOCKFILE}.* ] && ERRNO1=10 ## See if /var/run/fetchmail.pid exists. [ -e ${PIDFILE} ] && ERRNO2=11 ## See if there are any fetchmail daemons running. [ -n "`pidof ${PROGRAM}`" ] && ERRNO3=12 ## BEGIN ERROR CHECKING ERRNO4=`expr ${ERRNO1} + ${ERRNO2} + ${ERRNO3}` if [ ${ERRNO} -eq 9 ]; then echo -n $"User .${prog}rc not found:" failure && echo && exit ${ERRNO} elif [ ${ERRNO4} -eq 10 ]; then echo -n $"${prog} subsys locked:" warning && echo && exit ${ERRNO4} elif [ ${ERRNO4} -eq 11 ]; then echo -n $"${prog} PID not cleared:" warning && echo && exit ${ERRNO4} elif [ ${ERRNO4} -eq 12 ]; then echo -n $"${prog} daemons are running:" warning && echo && exit ${ERRNO4} elif [ ${ERRNO4} -eq 21 ]; then echo -n $"${prog} subsys locked PID not cleared:" warning && echo && exit ${ERRNO4} elif [ ${ERRNO4} -eq 22 ]; then echo -n $"${prog} subsys locked daemons are running:" warning && echo && exit ${ERRNO4} elif [ ${ERRNO4} -eq 23 ]; then echo -n $"${prog} PID not cleared daemons are running:" warning && echo && exit ${ERRNO4} elif [ ${ERRNO4} -eq 33 ]; then echo -n $"${prog} is already running:" failure && echo && exit ${ERRNO4} fi fi } function start() { ## Start the daemons. depend; for u in ${USERS}; do [ -f "/home/$u/.fetchmailrc" ] && { ## ensure permissions are correct for ~/.fetchmailrc chmod 0600 /home/$u/.fetchmailrc 2>/dev/null echo -n $"Starting ${prog} for user $u:" su $u -c '${PROGRAM} ${OPTIONS}' 2>/dev/null 1>&2 && success || failure RETVAL=$? echo } done ## Set PID & Lock files. [ ${RETVAL} -eq 0 ] && { pidof ${prog} > ${PIDFILE} 2>/dev/null touch "${LOCKFILE}.$u" } return ${RETVAL} } function stop() { ## Stop the daemons. [ -n "`pidof ${PROGRAM}`" ] && { for u in ${USERS}; do [ -e "/home/$u/.fetchmail.pid" ] && { echo -n $"Stopping ${prog} for user $u:" su $u -c '${PROGRAM} -q' 2>/dev/null 1>&2 && success || failure RETVAL=$? echo } done ## Cleanup PID & Lock files. [ ${RETVAL} -eq 0 ] && { rm -f ${PIDFILE} 2>/dev/null rm -f "${LOCKFILE}.$u" 2>/dev/null find /home -name ".fetchmail.pid" -exec rm -f {} 2>/dev/null \; RETVAL=0 } } return ${RETVAL} } function restart() { ## Stop the daemons. stop; sleep 1 ## Start fetchmail. echo start; } ## If for some reason fetchmail does not go down gracefully, you \ ## can run kill to kill the daemons and cleanup the lock and pid files. ## ONLY USE CLEANUP IF STOP FAILS TO FUNCTION PROPERLY. function cleanup() { ## Kill the daemons and cleanup. [ -n "`pidof ${prog}`" ] && killall -9 ${PROGRAM} >/dev/null 2>&1 rm -f ${PIDFILE} 2>/dev/null rm -f ${LOCKFILE}.* 2>/dev/null find /home -name ".fetchmail.pid" -exec rm -f {} 2>/dev/null \; RETVAL=0 return ${RETVAL} } ## pid is used with status to show which PIDs belong to which users. function pid() { ## Find individual PIDs for users daemon processes. for u in ${USERS}; do [ -f /home/$u/.fetchmail.pid ] && { echo $" (pid `cat /home/$u/.fetchmail.pid | awk '{print $1}'`) is assigned to user $u" } done RETVAL=0 } ## See how we are called. case "$1" in start) start ;; stop) stop ;; restart|reload) restart ;; cleanup|kill) cleanup ;; status) status ${prog} pid ;; *) echo $"Usage: $0 {start|stop|restart|cleanup|status}" RETVAL=1 esac unset PROGRAM OPTIONS exit ${RETVAL} ## EOF


Reply With Quote
