#! /bin/sh

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/omniNames
NAME=omniNames
DESC="omniorb name server"

test -f $DAEMON || exit 0

set -e

case "$1" in
  start)
	echo -n "Starting $DESC: "
	if [ -f /var/log/omninames-`uname -n`.log ] ; then
		start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
			--make-pidfile --background --exec $DAEMON
	else
		start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
			--make-pidfile --background --exec $DAEMON -- -start
	fi
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	start-stop-daemon --oknodo --stop --quiet --pidfile /var/run/$NAME.pid \
		--exec $DAEMON
	echo "$NAME."
	;;
  restart|force-reload)
	echo -n "Restarting $DESC: "
	start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
		--exec $DAEMON
	sleep 1
	if [ -f /var/log/omninames-`uname -n`.log ] ; then
		start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
			--make-pidfile --background --exec $DAEMON
	else
		start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
			--make-pidfile --background --exec $DAEMON -- -start
	fi
        echo "$NAME."
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0

