d0d307
#!/bin/sh
d0d307
#
d0d307
# chkconfig: - 65 35
d0d307
# description: The Cyrus IMAPD master serves as a master process for the Cyrus \
d0d307
#              IMAP and POP servers.
d0d307
# config: /etc/cyrus.conf
d0d307
# config: /etc/imapd.conf
d0d307
# pidfile: /var/run/cyrus-master.pid
d0d307
cf58a5
# author:	Simon Matter, Invoca Systems <simon.matter@invoca.ch>
cf58a5
# version:	2005111100
cf58a5
# changed:	add quickstart/stop option to init script to bypass db import/export
d0d307
933756
. /etc/init.d/functions
d0d307
933756
config=/etc/imapd.conf
933756
config2=/etc/cyrus.conf
933756
exec=/usr/lib/cyrus-imapd/cyrus-master
933756
lockfile=/var/lock/subsys/cyrus-imapd
933756
pidfile=/var/run/cyrus-master.pid
933756
prog="cyrus-imapd"
d0d307
5e73cf
if [ -f /etc/sysconfig/$prog ]; then
5e73cf
    . /etc/sysconfig/$prog
933756
fi
d0d307
d0d307
# check if the config files are present
933756
configok=true
933756
[ -f $config -a $config2 ] || configok=false
d0d307
 
cf58a5
# get_config [config default]
cf58a5
# extracts config option from config file
cf58a5
get_config() {
933756
  if conf=$(grep "^$1" /etc/imapd.conf); then
933756
    echo $conf | cut -d: -f2
cf58a5
  else
cf58a5
    echo $2
cf58a5
  fi
cf58a5
}
cf58a5
cf58a5
# where to find files and directories
cf58a5
CONFIGDIRECTORY=$(get_config configdirectory /var/lib/imap)
d0d307
CYRUSMASTER=/usr/lib/cyrus-imapd/cyrus-master
d0d307
CYRUS_PROC_NAME=$(basename $CYRUSMASTER)
d0d307
ALWAYS_CONVERT=1
d0d307
d0d307
RETVAL=0
cf58a5
RETVAL2=1
cf58a5
QUICK=0
d0d307
d0d307
start() {
933756
  [ $UID -eq 0 ] || exit 4
933756
  [ -x $exec ] || exit 5
933756
  $configok || exit 6
d0d307
  if [ $(/sbin/pidof -s $CYRUSMASTER) ]; then
933756
    echo -n $"$prog already running."
933756
    true
cf58a5
    echo
d0d307
  else
cf58a5
    if [ $QUICK -eq 0 ]; then
933756
      echo -n $"Importing $prog databases: "
cf58a5
      cd $CONFIGDIRECTORY
c050dc
      runuser - cyrus -s /bin/sh -c "umask 166 ; /usr/lib/cyrus-imapd/cvt_cyrusdb_all > ${CONFIGDIRECTORY}/rpm/db_import.log 2>&1" < /dev/null
cf58a5
      RETVAL=$?
cf58a5
      if [ $RETVAL -eq 0 ]; then
933756
        success $"$prog importing databases"
cf58a5
      else
933756
        failure $"$prog error importing databases, check ${CONFIGDIRECTORY}/rpm/db_import.log"
cf58a5
      fi
cf58a5
      echo
cf58a5
    fi
d0d307
    if [ $RETVAL -eq 0 ]; then
933756
      echo -n $"Starting $prog: "
d0d307
      daemon $CYRUSMASTER -d $CYRUSOPTIONS
cf58a5
      RETVAL2=$?
cf58a5
      echo
d0d307
    fi
d0d307
  fi
933756
  [ $RETVAL -eq 0 -a $RETVAL2 -eq 0 ] && touch $lockfile
d0d307
  return $RETVAL
d0d307
}
d0d307
d0d307
stop() {
933756
  [ $UID -eq 0 ] || exit 4
933756
  [ -x $exec ] || exit 5
933756
933756
  echo -n $"Shutting down $prog: "
d0d307
  killproc $CYRUSMASTER
d0d307
  RETVAL=$?
cf58a5
  if [ $QUICK -eq 0 ]; then
cf58a5
    if [ ! $(/sbin/pidof -s $CYRUSMASTER) ]; then
cf58a5
      echo
933756
      echo -n $"Exporting $prog databases: "
cf58a5
      cd $CONFIGDIRECTORY
c050dc
      runuser - cyrus -s /bin/sh -c "umask 166 ; /usr/lib/cyrus-imapd/cvt_cyrusdb_all export > ${CONFIGDIRECTORY}/rpm/db_export.log 2>&1" < /dev/null
cf58a5
      RETVAL2=$?
cf58a5
      if [ $RETVAL2 -eq 0 ]; then
933756
        success $"$prog exporting databases"
cf58a5
      else
933756
        failure $"$prog error exporting databases, check ${CONFIGDIRECTORY}/rpm/db_export.log"
cf58a5
      fi
cf58a5
    fi
cf58a5
  fi
d0d307
  echo
933756
  [ $RETVAL -eq 0 -a $RETVAL2 -eq 0 ] && rm -f $lockfile
d0d307
  return $RETVAL
d0d307
}
d0d307
d0d307
restart() {
d0d307
  stop
d0d307
  start
d0d307
}
d0d307
d0d307
reload() {
d0d307
  echo -n $"Reloading cyrus.conf file: "
d0d307
  killproc $CYRUSMASTER -HUP
d0d307
  RETVAL=$?
d0d307
  echo
d0d307
  return $RETVAL
d0d307
}
d0d307
 
d0d307
case "$1" in
d0d307
  start)
d0d307
    start
d0d307
    ;;
d0d307
  stop)
d0d307
    stop
d0d307
    ;;
933756
  force-reload|restart)
d0d307
    restart
d0d307
    ;;
d0d307
  reload)
d0d307
    reload
d0d307
    ;;
933756
  condrestart|try-restart)
933756
    if [ -f $lockfile ]; then
933756
        stop
933756
        start
933756
    fi
d0d307
    ;;
d0d307
  status)
933756
    status -p $pidfile $prog 
933756
    RETVAL=$?
d0d307
    ;;
cf58a5
  quickstart)
cf58a5
    QUICK=1
cf58a5
    start
cf58a5
    ;;
cf58a5
  quickstop)
cf58a5
    QUICK=1
cf58a5
    stop
cf58a5
    ;;
d0d307
  *)
933756
    echo $"Usage: $0 {start|stop|restart|reload|force-reload|condrestart|try-restart|status|quickstart|quickstop}"
933756
    RETVAL=2
933756
    [ "$1" = "usage" ] && RETVAL=0
d0d307
esac
d0d307
d0d307
exit $RETVAL