2005-04-15 20:24:15 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# chkconfig: - 65 35
|
|
|
|
# description: The Cyrus IMAPD master serves as a master process for the Cyrus \
|
|
|
|
# IMAP and POP servers.
|
|
|
|
# config: /etc/cyrus.conf
|
|
|
|
# config: /etc/imapd.conf
|
|
|
|
# pidfile: /var/run/cyrus-master.pid
|
|
|
|
|
2006-02-28 20:04:01 +00:00
|
|
|
# author: Simon Matter, Invoca Systems <simon.matter@invoca.ch>
|
|
|
|
# version: 2005111100
|
|
|
|
# changed: add quickstart/stop option to init script to bypass db import/export
|
2005-04-15 20:24:15 +00:00
|
|
|
|
|
|
|
# Source function library
|
|
|
|
if [ -f /etc/init.d/functions ]; then
|
|
|
|
. /etc/init.d/functions
|
|
|
|
elif [ -f /etc/rc.d/init.d/functions ]; then
|
|
|
|
. /etc/rc.d/init.d/functions
|
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Source networking configuration.
|
|
|
|
. /etc/sysconfig/network
|
|
|
|
|
|
|
|
# Check that networking is up.
|
|
|
|
[ ${NETWORKING} = "no" ] && exit 0
|
|
|
|
|
|
|
|
# check if the config files are present
|
|
|
|
[ -f /etc/cyrus.conf ] || exit 0
|
|
|
|
[ -f /etc/imapd.conf ] || exit 0
|
|
|
|
|
|
|
|
# This is our service name
|
|
|
|
BASENAME=$(basename $0)
|
|
|
|
if [ -L $0 ]; then
|
|
|
|
BASENAME=$(find $0 -name $BASENAME -printf %l)
|
|
|
|
BASENAME=$(basename $BASENAME)
|
|
|
|
fi
|
|
|
|
|
2006-02-28 20:04:01 +00:00
|
|
|
# Source service configuration.
|
|
|
|
if [ -f /etc/sysconfig/$BASENAME ]; then
|
|
|
|
. /etc/sysconfig/$BASENAME
|
2005-04-15 20:24:15 +00:00
|
|
|
else
|
2006-02-28 20:04:01 +00:00
|
|
|
echo "$BASENAME: configfile /etc/sysconfig/$BASENAME does NOT exist !"
|
|
|
|
exit 1
|
2005-04-15 20:24:15 +00:00
|
|
|
fi
|
|
|
|
|
2006-02-28 20:04:01 +00:00
|
|
|
# get_config [config default]
|
|
|
|
# extracts config option from config file
|
|
|
|
get_config() {
|
|
|
|
if config=$(grep "^$1" /etc/imapd.conf); then
|
|
|
|
echo $config | cut -d: -f2
|
|
|
|
else
|
|
|
|
echo $2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# where to find files and directories
|
|
|
|
CONFIGDIRECTORY=$(get_config configdirectory /var/lib/imap)
|
2005-04-15 20:24:15 +00:00
|
|
|
CYRUSMASTER=/usr/lib/cyrus-imapd/cyrus-master
|
|
|
|
CYRUS_PROC_NAME=$(basename $CYRUSMASTER)
|
|
|
|
ALWAYS_CONVERT=1
|
|
|
|
|
2006-02-28 20:04:01 +00:00
|
|
|
# fallback to su if runuser not available
|
|
|
|
if [ -x /sbin/runuser ]; then
|
|
|
|
RUNUSER=runuser
|
2005-04-15 20:24:15 +00:00
|
|
|
else
|
2006-02-28 20:04:01 +00:00
|
|
|
RUNUSER=su
|
2005-04-15 20:24:15 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
RETVAL=0
|
2006-02-28 20:04:01 +00:00
|
|
|
RETVAL2=1
|
|
|
|
QUICK=0
|
2005-04-15 20:24:15 +00:00
|
|
|
|
|
|
|
start() {
|
|
|
|
if [ $(/sbin/pidof -s $CYRUSMASTER) ]; then
|
|
|
|
echo -n $"$BASENAME already running."
|
|
|
|
false
|
2006-02-28 20:04:01 +00:00
|
|
|
echo
|
2005-04-15 20:24:15 +00:00
|
|
|
else
|
2006-02-28 20:04:01 +00:00
|
|
|
if [ $QUICK -eq 0 ]; then
|
|
|
|
echo -n $"Importing $BASENAME databases: "
|
|
|
|
cd $CONFIGDIRECTORY
|
|
|
|
$RUNUSER - cyrus -c "umask 166 ; /usr/lib/cyrus-imapd/cvt_cyrusdb_all > ${CONFIGDIRECTORY}/rpm/db_import.log 2>&1" < /dev/null
|
|
|
|
RETVAL=$?
|
|
|
|
if [ $RETVAL -eq 0 ]; then
|
|
|
|
success $"$BASENAME importing databases"
|
|
|
|
else
|
|
|
|
failure $"$BASENAME error importing databases, check ${CONFIGDIRECTORY}/rpm/db_import.log"
|
|
|
|
fi
|
|
|
|
echo
|
|
|
|
fi
|
2005-04-15 20:24:15 +00:00
|
|
|
if [ $RETVAL -eq 0 ]; then
|
2006-02-28 20:04:01 +00:00
|
|
|
echo -n $"Starting $BASENAME: "
|
2005-04-15 20:24:15 +00:00
|
|
|
daemon $CYRUSMASTER -d $CYRUSOPTIONS
|
2006-02-28 20:04:01 +00:00
|
|
|
RETVAL2=$?
|
|
|
|
echo
|
2005-04-15 20:24:15 +00:00
|
|
|
fi
|
|
|
|
fi
|
2006-02-28 20:04:01 +00:00
|
|
|
[ $RETVAL -eq 0 -a $RETVAL2 -eq 0 ] && touch /var/lock/subsys/$BASENAME
|
2005-04-15 20:24:15 +00:00
|
|
|
return $RETVAL
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
echo -n $"Shutting down $BASENAME: "
|
|
|
|
killproc $CYRUSMASTER
|
|
|
|
RETVAL=$?
|
2006-02-28 20:04:01 +00:00
|
|
|
if [ $QUICK -eq 0 ]; then
|
|
|
|
if [ ! $(/sbin/pidof -s $CYRUSMASTER) ]; then
|
|
|
|
echo
|
|
|
|
echo -n $"Exporting $BASENAME databases: "
|
|
|
|
cd $CONFIGDIRECTORY
|
|
|
|
$RUNUSER - cyrus -c "umask 166 ; /usr/lib/cyrus-imapd/cvt_cyrusdb_all export > ${CONFIGDIRECTORY}/rpm/db_export.log 2>&1" < /dev/null
|
|
|
|
RETVAL2=$?
|
|
|
|
if [ $RETVAL2 -eq 0 ]; then
|
|
|
|
success $"$BASENAME exporting databases"
|
|
|
|
else
|
|
|
|
failure $"$BASENAME error exporting databases, check ${CONFIGDIRECTORY}/rpm/db_export.log"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
2005-04-15 20:24:15 +00:00
|
|
|
echo
|
2006-02-28 20:04:01 +00:00
|
|
|
[ $RETVAL -eq 0 -a $RETVAL2 -eq 0 ] && rm -f /var/lock/subsys/$BASENAME
|
2005-04-15 20:24:15 +00:00
|
|
|
return $RETVAL
|
|
|
|
}
|
|
|
|
|
|
|
|
restart() {
|
|
|
|
stop
|
|
|
|
start
|
|
|
|
}
|
|
|
|
|
|
|
|
reload() {
|
|
|
|
echo -n $"Reloading cyrus.conf file: "
|
|
|
|
killproc $CYRUSMASTER -HUP
|
|
|
|
RETVAL=$?
|
|
|
|
echo
|
|
|
|
return $RETVAL
|
|
|
|
}
|
|
|
|
|
|
|
|
condrestart() {
|
|
|
|
[ -e /var/lock/subsys/$BASENAME ] && restart || :
|
|
|
|
}
|
|
|
|
|
|
|
|
rhstatus() {
|
|
|
|
status $CYRUSMASTER
|
|
|
|
RETVAL=$?
|
|
|
|
return $RETVAL
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
restart
|
|
|
|
;;
|
|
|
|
reload)
|
|
|
|
reload
|
|
|
|
;;
|
|
|
|
condrestart)
|
|
|
|
condrestart
|
|
|
|
;;
|
|
|
|
status)
|
|
|
|
rhstatus
|
|
|
|
;;
|
2006-02-28 20:04:01 +00:00
|
|
|
quickstart)
|
|
|
|
QUICK=1
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
quickstop)
|
|
|
|
QUICK=1
|
|
|
|
stop
|
|
|
|
;;
|
2005-04-15 20:24:15 +00:00
|
|
|
*)
|
2006-02-28 20:04:01 +00:00
|
|
|
echo $"Usage: $BASENAME {start|stop|restart|reload|condrestart|status|quickstart|quickstop}"
|
2005-04-15 20:24:15 +00:00
|
|
|
RETVAL=1
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit $RETVAL
|