File SOGo.init of Package SOGo3

#!/bin/sh
#
# Copyright (c) 2011 Scorpio IT, Deidesheim, Germany
# All rights reserved
#
# Author: Christian Wittmer
# please send feedback to <rpm@scorpio-it.net>
#
#     This library is free software; you can redistribute it and/or modify it
#     under the terms of the GNU Lesser General Public License as published by
#     the Free Software Foundation; either version 2.1 of the License, or (at
#     your option) any later version.
#                             
#     This library is distributed in the hope that it will be useful, but
#     WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#     Lesser General Public License for more details.
#      
#     You should have received a copy of the GNU Lesser General Public
#     License along with this library; if not, write to the Free Software
#     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
#     USA.
#
# /etc/init.d/sogod
#   and its symbolic link
# /(usr/)sbin/rcsogod
#
### BEGIN INIT INFO
# Provides:          sogod
# Required-Start:    $network $remote_fs memcached
# Should-Start:      httpd postgresql smtp mysql
# Required-Stop:     $network $remote_fs memcached
# Should-Stop:       httpd postgresql smtp mysql
# Default-Start:     2 3 5
# Default-Stop:      0 1 6
# Short-Description: SOGo server
# Description:       Scalable OpenGroupware.org Server
### END INIT INFO
#
# Note on runlevels:
# 0 - halt/poweroff                     6 - reboot
# 1 - single user                       2 - multiuser without network exported
# 3 - multiuser w/ network (text mode)  5 - multiuser w/ network and X11 (xdm)
# 

# Check for missing binaries (stale symlinks should not happen)
# Note: Special treatment of stop for LSB conformance
SOGOD_BIN=/usr/sbin/sogod
test -x $SOGOD_BIN || { echo "$SOGOD_BIN not installed";
	if [ "$1" = "stop" ]; then exit 0;
	else exit 5; fi; }

# Check for existence of needed config file and read it
SOGOD_CONFIG=/etc/sysconfig/SOGo
test -r $SOGOD_CONFIG || { echo "$SOGOD_CONFIG not existing";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 6; fi; }

# Read config
. $SOGOD_CONFIG

# Check for existence of needed GNUstep Makefile
SOGOD_GS_MAKEFILE=$(gnustep-config --variable=GNUSTEP_MAKEFILES)/GNUstep.sh
test -r $SOGOD_GS_MAKEFILE || { echo "$SOGOD_GS_MAKEFILE not existing";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 6; fi; }

# Read config
. $SOGOD_GS_MAKEFILE

SOGOD_USER=${SOGO_USER:="sogo"}
SOGOD_PREFORK=${SOGO_PREFORK:="1"}
SOGOD_PIDDIR=${SOGO_PIDDIR:="/var/run/SOGo"}
SOGOD_PIDFILE=${SOGO_PIDFILE:="${SOGOD_PIDDIR}/sogod.pid"}
SOGOD_LOGFILE=${SOGO_LOGFILE:="/var/log/SOGo/sogod.log"}
SOGOD_OPTS="-WOWorkersCount $SOGOD_PREFORK -WOPidFile $SOGOD_PIDFILE -WOLogFile $SOGOD_LOGFILE"

[ ! -d $SOGOD_PIDDIR ] && install -d -m0750 -o ${SOGOD_USER} -g root $SOGOD_PIDDIR ;

SOGOD_DESC="SOGo"

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     be verbose in local rc status and clear it afterwards
#      rc_status -v -r  ditto and clear both the local and overall rc status
#      rc_status -s     display "skipped" and exit with status 3
#      rc_status -u     display "unused" and exit with status 3
#      rc_failed        set local and overall rc status to failed
#      rc_failed <num>  set local and overall rc status to <num>
#      rc_reset         clear both the local and overall rc status
#      rc_exit          exit appropriate to overall rc status
#      rc_active        checks whether a service is activated by symlinks
. /etc/rc.status

# Reset status of this service
rc_reset

# Return values acc. to LSB for all commands but status:
# 0       - success
# 1       - generic or unspecified error
# 2       - invalid or excess argument(s)
# 3       - unimplemented feature (e.g. "reload")
# 4       - user had insufficient privileges
# 5       - program is not installed
# 6       - program is not configured
# 7       - program is not running
# 8--199  - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
# 
# Note that starting an already running service, stopping
# or restarting a not-running service as well as the restart
# with force-reload (in case signaling is not supported) are
# considered a success.

case "$1" in
    # ------------------------------------------------------
    # start
    # ------------------------------------------------------
    start)
	echo "Checking needed Services by $SOGOD_DESC and trying to start ... "

	# --
	# check database
	# --
	if test $SOGO_DB_RUNNING -gt 0; then
	  if $SOGO_USED_DB_RCSCRIPT status > /dev/null 2>&1 ; then
	    echo " Checking $SOGO_USED_DB ... done."
	    rc_status
	  else
	    #echo " Checking $SOGO_USED_DB ... failed."
	    #echo "  --> Please start the database at first! ($SOGO_USED_DB_RCSCRIPT start) <--"
	    #rc_failed
	    #rc_status -v
	    #exit 1;
	    $SOGO_USED_DB_RCSCRIPT start
	  fi
	else
	    echo " Disabled: database check!"
	fi

	# --
	# check imap
	# --
	if test $SOGO_IMAP_RUNNING -gt 0; then
	  if $SOGO_USED_IMAP_RCSCRIPT status > /dev/null 2>&1 ; then
	    echo " Checking $SOGO_USED_IMAP ... done."
	    rc_status
	  else
	    #echo " Checking $SOGO_USED_IMAP ... failed."
	    #echo "  --> Please start the database at first! ($SOGO_USED_IMAP_RCSCRIPT start) <--"
	    #rc_failed
	    #rc_status -v
	    #exit 1;
	    if [ "$(echo "$SOGO_USED_IMAP" | tr 'A-Z' 'a-z')" = "cyrus" ]; then
	      $SOGO_USED_SASL_RCSCRIPT start
	    fi
	    $SOGO_USED_IMAP_RCSCRIPT start
	  fi
	else
	    echo " Disabled: imap check!"
	fi

	# --
	# check memcached
	# --
	if $SOGO_USED_MEMCACHE_RCSCRIPT status > /dev/null 2>&1 ; then
	  echo " Checking $SOGO_USED_MEMCACHE ... done."
	  rc_status
	else
	  #echo " Checking $SOGO_USED_MEMCACHE ... failed."
	  #echo "  --> Please start the database at first! ($SOGO_USED_MEMCACHE_RCSCRIPT start) <--"
	  #rc_failed
	  #rc_status -v
	  #exit 1;
	  $SOGO_USED_MEMCACHE_RCSCRIPT start
	fi

	# --
	# start web server
	# --
	if test $SOGO_HTTP_RUNNING -gt 0; then
	  if $SOGO_USED_HTTP_RCSCRIPT status > /dev/null 2>&1 ; then
	    echo " Checking $SOGO_USED_HTTP ... done."
	    rc_status
	  else
	    #echo " Checking $SOGO_USED_HTTP ... failed!"
	    #echo "  --> Please start the web server first! ($SOGO_USED_HTTP_RCSCRIPT start) <--"
	    #rc_failed
	    #exit 1
	    $SOGO_USED_HTTP_RCSCRIPT start
	  fi
	else
	    echo " Disabled: web server check!"
	fi

	# --
	# start mail server
	# --
	if test $SOGO_SMTP_RUNNING -gt 0; then
	  if $SOGO_USED_SMTP_RCSCRIPT status > /dev/null 2>&1 ; then
	    echo " Checking $SOGO_USED_SMTP ... done."
	    rc_status
	  else
	    #echo " Checking $SOGO_USED_SMTP ... failed!"
	    #echo "  --> Please start the web server first! ($SOGO_USED_SMTP_RCSCRIPT start) <--"
	    #rc_failed
	    #exit 1
	    $SOGO_USED_SMTP_RCSCRIPT start
	  fi
	else
	    echo " Disabled: mail server check!"
	fi


	echo -n "Starting $SOGOD_DESC "
	## Start daemon with startproc(8). If this fails
	## the return value is set appropriately by startproc.
	/sbin/startproc -u $SOGOD_USER $SOGOD_BIN $SOGOD_OPTS

	# Remember status and be verbose
	rc_status -v
	;;
    # ------------------------------------------------------
    # stop
    # ------------------------------------------------------
    stop)
	echo -n "Shutting down $SOGOD_DESC "
	## Stop daemon with killproc(8) and if this fails
	## killproc sets the return value according to LSB.
	/sbin/killproc $SOGOD_BIN

	# Remember status and be verbose
	rc_status -v
	;;
    restart)
	## Stop the service and regardless of whether it was
	## running or not, start it again.
	$0 stop
	$0 start

	# Remember status and be quiet
	rc_status

	# --
	# restart memcached after restart of sogod
	# --
	$SOGO_USED_MEMCACHE_RCSCRIPT restart
	
	;;
    reload)
	echo -n "Reloading $SOGOD_DESC "
        # sogod does not support reload on signal
        rc_failed 3

	# Remember status and be verbose
        rc_status -v
        ;;
    # ------------------------------------------------------
    # status
    # ------------------------------------------------------
    status)
	echo "Checking needed Services by $SOGOD_DESC ... "

	# --
	# database
	# --
	$SOGO_USED_DB_RCSCRIPT status

	# --
	# imap
	# --
	$SOGO_USED_IMAP_RCSCRIPT status

	# --
	# memcache
	# --
	$SOGO_USED_MEMCACHE_RCSCRIPT status

	# --
	# web server
	# --
	$SOGO_USED_HTTP_RCSCRIPT status

	# --
	# mail server
	# --
	$SOGO_USED_SMTP_RCSCRIPT status

	echo -n "Checking for $SOGOD_DESC "
	## Check status with checkproc(8), if process is running
	## checkproc will return with exit status 0.

	# Return value is slightly different for the status command:
	# 0 - service up and running
	# 1 - service dead, but /var/run/  pid  file exists
	# 2 - service dead, but /var/lock/ lock file exists
	# 3 - service not running (unused)
	# 4 - service status unknown :-(
	# 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)

	# NOTE: checkproc returns LSB compliant status values.
	/sbin/checkproc $SOGOD_BIN

	# Remember status and be verbose
	rc_status -v
	;;
    *)
	echo "Usage: $0 {start|stop|status|restart|reload}"
	exit 1
	;;
esac
rc_exit
openSUSE Build Service is sponsored by