#!/bin/bash
#
# Startup script for hudlite-server  $Revision: 1.0 $
#
# chkconfig: 345 95 45
#  
# processname: hudlite-server
# description: Server for Fonality HUDlite
# pidfile: /var/run/hudlite-server.pid
# configs: /usr/local/fonality/hud/conf

# Copyright (C) 2007 Fonality Inc. (fonality.com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program 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 General Public License for more details.

# Make sure relevant files exist
[ -f /usr/local/fonality/hud/hudlite-server ] || exit 0

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

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

prog="hudlite-server"

RETVAL=0

start() {
    # Start daemons.
    if [ -n "`/sbin/pidof hudlite-server`" ]; then
        echo -n $"$prog: already running"
        return 1
    fi
    echo -n $"Starting $prog: "
	cd /usr/local/fonality/hud/
    /usr/local/fonality/hud/hudlite-server >/dev/null 2>/dev/null
    RETVAL=$?
    sleep 1
    if [ -z "`/sbin/pidof hudlite-server`" ]; then
        # The child processes have died after fork()ing, e.g.
        # because of a broken config file
        RETVAL=1
    fi
    [ $RETVAL -ne 0 ] && failure $"$prog startup"
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/hudlite-server && success $"$prog startup"
    echo
    return $RETVAL
}

stop() {
    # Stop daemons.
    echo -n $"Shutting down $prog: "
    killproc hudlite-server
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/hudlite-server
    return $RETVAL
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		stop
		start
		RETVAL=$?
		;;
	status)
		status hudlite-server
		RETVAL=$?
		;;
	*)
		echo $"Usage: hudlite-server  {start|stop|restart|status}"
		RETVAL=1
esac
exit $RETVAL

