#!/bin/sh
#
# omniNames This shell script takes care of loading omniNames
#           for i.e. 3Dwm server
#
# chkconfig: 2345 80 30
#
# description: Lauching omniNames server.
#
# (c) MandrakeSoft, Lenny Cartier <lenny@mandrakesoft.com>
#
# config: /etc/omniORB.cfg
#
### BEGIN INIT INFO
# Provides: omninames
# Required-Start: $network
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 6
# Description: This shell script takes care of loading omniNames for i.e. 3Dwm server
# Short-Description: start and stop omninames
### END INIT INFO

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

RETVAL=0

OMNILOG=/var/log/omniORB/omninames-$HOSTNAME.log
LOCKFILE=/var/lock/subsys/omninames
ERRORLOG=/var/log/omniORB/omninames-error.log
USER=daemon

# Source networking configuration.
# Check that networking is up.
SourceIfNotEmpty /etc/sysconfig/network || exit 1
is_yes "$NETWORKING" || exit 1

SourceIfExists /etc/sysconfig/omninames

# Default server address and port
[ -z $NAMES_ADDR ] && NAMES_ADDR=127.0.0.1
[ -z $NAMES_PORT ] && NAMES_PORT=2810

start()
{
	echo -n "Starting omniNames daemon: "
	if [ -f "$OMNILOG" ]
	then
		start_daemon  --no-announce --user "$USER" -- /usr/bin/omniNames -errlog $ERRORLOG -ORBendPoint giop:tcp:$NAMES_ADDR:$NAMES_PORT "&"
	else
		start_daemon --no-announce --user "$USER" -- /usr/bin/omniNames -start -errlog $ERRORLOG -ORBendPoint giop:tcp:$NAMES_ADDR:$NAMES_PORT "&"
	fi
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch "$LOCKFILE"
	return $RETVAL
}

stop()
{
	echo -n "Stopping omniNames daemon: "
	stop_daemon --no-announce /usr/bin/omniNames 
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f "$LOCKFILE"
	return $RETVAL
}

restart()
{
	stop
	start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	status)
		status omniNames
		RETVAL=$?
		;;
	*)
		echo "Usage: ${0##*/} {start|stop|reload|restart|condstop|condrestart|status}"
		RETVAL=1
esac

exit $RETVAL
