#!/bin/sh
#
# FreeWnn    This shell script takes care of starting and stopping
#            jserver (Japanese Conversion Engine).
#
# chkconfig: 2345 90 12
# description: FreeWnn - Japanese Conversion Engine \
#              FreeWnn is a network-extensible Kana-to-Kanji conversion system
# processname: jserver

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

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

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

[ -f /usr/bin/jserver ] || exit 1

[ -f /etc/FreeWnn/ja/jserverrc ] || exit 1

# Path to the jserver
jserver=/usr/bin/jserver
prog="FreeWnn"
RETVAL=0

start () {
    # Start daemons.

    echo -n $"Starting $prog: "
    rm -f /tmp/jd_sockV4
    ( ${jserver} | grep "Finished" > /dev/null ) \
        && echo_success || echo_failure
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/FreeWnn
    return $RETVAL
}
stop () {
    # Stop daemons.
    echo -n $"Shutting down $prog: "
    killproc jserver
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/FreeWnn
    [ $RETVAL -eq 0 ] && rm -f /tmp/jd_sockV4
    return $RETVAL
}
restart() {
    stop
    start
}

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status jserver
        ;;
    restart|reload)
        restart
        ;;
    *)
	echo $"Usage: $0 {start|stop|status|restart|reload}"
        exit 1
esac
 

exit $RETVAL