Fetchmail init script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a fetchmail init script. It doesn't look very redhat-like but it follows the redhat conventions and I have tested it on my FC2-test1 system. Ideas were taken from the Debian and Gentoo init scripts which were available while I was coding this.

Please critique.

--
Martin Jackson: mhjacks@xxxxxxxxxx
===========================================

#!/bin/bash
#
# fetchmail       This shell script takes care of starting and stopping
#                 fetchmail (remote POP/IMAP mail retrieval utility)
#
# chkconfig: - 55 45
# description: fetchmail is used to retrieve mail from remote servers.  This
# script provides support for running it as a system service.
# probe: true

# Derived from the Fedora Core 2 test 1 named script, as well as the Debian
# and Gentoo fetchmail init scripts.

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

# Source networking configuration.
[ -r /etc/sysconfig/network ] && . /etc/sysconfig/network

RETVAL=0
prog="fetchmail"

FETCHMAIL=/usr/bin/fetchmail
CONFFILE=/etc/fetchmailrc
OPTIONS="-f $CONFFILE --syslog"
LOCK=/var/lock/subsys/fetchmail

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

# [ -r /etc/sysconfig/fetchmail ] && . /etc/sysconfig/fetchmail

[ -x $FETCHMAIL ] || exit 0 

[ -r $CONFFILE ] || exit 0 

# Check for some things in the config file, to determine whether we need
# to set options on the command line or not.  The UIDL cache helps determine
# the identity of POP messages.  Defaults to /var/mail if not specified in
# the config file.
#
# The poll rate determines how often fetchmail polls the listed servers.  This
# can also be specified in the config file.
[ -f "$CONFFILE" ] && {
    if ! grep -qs idfile "$CONFFILE" ; then
        [ -d /var/mail ] && UIDL=/var/mail/.fetchmail-UIDL-cache
        [ "${UIDL}" != "" ] && OPTIONS="${OPTIONS} -i ${UIDL}"
    fi

    if ! grep -qs "set daemon" "$CONFFILE" ; then
        OPTIONS="${OPTIONS} -d 900"
    fi
}


start() {
        # Start fetchmail
	if [ -n "`/sbin/pidof $prog`" ]; then
		echo -n $"$prog: already running"
		return 1
	fi
        echo -n $"Starting $prog: "
	daemon $FETCHMAIL $OPTIONS
	RETVAL=$?
 	[ $RETVAL -eq 0 ] && touch $LOCK
        echo
	return $RETVAL
}
stop() {
        # Stop daemons.
        echo -n $"Stopping $prog: "
       	killproc $prog
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f $LOCK
	echo
	return $RETVAL 
	success
}
restart() {
	stop
# wait a couple of seconds for the named to finish closing down
	sleep 2
	start
}	

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	status)
		status $prog
		;;
	restart)
		restart
		;;
	condrestart)
		if [ -e $LOCK ]; then 
			restart; 
		fi
		;;
	checkmail)
		if [ -e $LOCK ]; then 
			echo -n "Forcing mailcheck:"
			killproc $prog -USR1; 
			echo
		fi
		;;
	*)
        	echo $"Usage: $0 {start|stop|status|restart|condrestart|checkmail}"
		exit 1
esac

exit $?


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux