#!/bin/sh
#
# domino	Start/stop the Lotus Domino server
# description:	This script is used to start and stop the domino \
#		server as a background process. It will send \
#		the serverID password from a file to the server.\
#		Communication with the server has to be done through \
#		console, Notes Administrator or webadmin.\
#
# Usage:	/etc/rc.d/init.d/domino start|stop|restart|condrestart
#
# process name: server, ...
#
# Version 1.1, by LB, 2005-01-07, updated by Cyberscooty 2012-02-19


# Change the USER, GROUP, DATA_DIR and BIN_DIR for your server
DOMINO_USER="notes"
DOMINO_GROUP="notes"
DOMINO_DATA_DIR="/home/notes/data"
DOMINO_BIN_DIR="/opt/ibm/lotus/bin"
LOCKFILE="/home/notes/data/lock"


# See if the user that runs this script is root

if [ `id -u` != 0 ]; then 
  echo "Ce script doit être lancer en root"
  exit 1
fi

start() {


# Check we're not already running

    if [ -f $LOCKFILE ] ; then
      echo "Le serveur Domino est déjà en cours d'exécution."
      exit 1
    fi

# Two ways to run the server (comment one of them out)
# 1. With the output of the console redirected to /var/log/domino.log
#	Be sure to change the logrotate daemon.
# 2. With the output of the console redirected to /dev/null

    echo -n "Démarrage du serveur Domino..."

# Version with logfile
#    su - ${DOMINO_USER} -c "cd ${DOMINO_DATA_DIR};\
#      ${DOMINO_BIN_DIR}/server" \
#      >> /var/log/domino 2>&1 &
#    RETVAL=$?
#    if [ "$RETVAL" = "0" ] ; then
#      touch $LOCKFILE > /dev/null 2>&1
#    fi
# Version without logfile
    su - ${DOMINO_USER} -c "cd ${DOMINO_DATA_DIR};\
    ${DOMINO_BIN_DIR}/server -jc" > /dev/null 2>&1 &

    echo "done."
}

stop() {
    echo -n "Arrêt du serveur Domino... "
    su - ${DOMINO_USER} -c "cd ${DOMINO_DATA_DIR}; ${DOMINO_BIN_DIR}/server -q"
    RETVAL=$?
# RETVAL is 38 on normal shutdown - what does *that* mean?
# Users should test this on their own systems . . .
#    if [ $RETVAL -lt 50 ] ; then
#      rm $LOCKFILE
#    fi
}

restart() {
	stop
	start
}

# See how we were called.

case $1 in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  condrestart)
	[ -f $LOCKFILE ] && restart
	;;
  *)
    echo "Usage: domino {start|stop|restart|condrestart}"
    exit 1
    ;;

esac

# End of the domino script
exit 0
