#!/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).
+# description: Starts and stops the fetchmail daemon used to retrive mail \
+# via various protocols (such as POP3 and IMAP4).
#
# config: /etc/fetchmailrc
-export PATH=/bin:/sbin:/usr/bin:/usr/sbin
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
-. /etc/sysconfig/network
+# Get service config - may override defaults
+[ -f /etc/sysconfig/fetchmail ] && . /etc/sysconfig/fetchmail
-# Demon specified configuration.
-. /etc/sysconfig/fetchmail
+# defaults
+[ -z "$POLL_INTERVAL" ] && POLL_INTERVAL=300
+
+# Get network config
+[ -f /etc/sysconfig/network ] && . /etc/sysconfig/network
# Check that networking is up.
-[ "${NETWORKING}" = "no" ] && exit 0
+if is_yes "${NETWORKING}"; then
+ if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
+ msg_network_down "fetchmail"
+ exit 1
+ fi
+else
+ exit 0
+fi
# Check that fetchmailrc exists.
[ -f /etc/fetchmailrc ] || exit 0
+start() {
+ if [ ! -f /var/lock/subsys/fetchmail ]; then
+ msg_starting "fetchmail"
+
+ is_yes $VERBOSE_LOGGING && OPTIONS="-v"
+
+ daemon fetchmail -d "$POLL_INTERVAL" $OPTIONS -f /etc/fetchmailrc
+ RETVAL=$?
+ [ $RETVAL -eq 0 ] && touch /var/lock/subsys/fetchmail
+ else
+ msg_already_running fetchmail
+ fi
+}
+
+stop() {
+ if [ -f /var/lock/subsys/fetchmail ]; then
+ msg_stopping "fetchmail"
+ killproc fetchmail
+ rm -f /var/lock/subsys/fetchmail >/dev/null 2>&1
+ else
+ msg_not_running "fetchmail"
+ fi
+}
+
+RETVAL=0
# See how we were called.
case "$1" in
start)
- show Starting fetchmail
- daemon $NICELEVEL fetchmail -f /etc/fetchmailrc
- touch /var/lock/subsys/fetchmail
+ start
;;
stop)
- show Stopping fetchmail
- killproc fetchmail
- rm -f /var/lock/subsys/fetchmail
+ stop
+ ;;
+ restart)
+ stop
+ start
+ ;;
+ reload|force-reload)
+ if [ -f /var/lock/subsys/fetchmail ]; then
+ msg_reloading "fetchmail"
+ killproc fetchmail -HUP
+ RETVAL=$?
+ else
+ msg_not_running fetchmail
+ exit 7
+ fi
;;
status)
status fetchmail
- ;;
- restart)
- $0 stop
- $0 start
+ exit $?
;;
*)
- echo "Usage: $0 {start|stop|restart|status}"
- exit 1
+ msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
+ exit 3
esac
+exit $RETVAL