#!/bin/sh
#
# cWnn       This shell script takes care of starting and stopping
#            cserver (Chinese Conversion Engine).
#
# chkconfig: 2345 90 12
# description: cWnn - Chinese(zh_CN) Conversion Engine
# processname: cserver

# 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/cserver ] || exit 1

[ -f /etc/FreeWnn/zh_CN/cserverrc ] || exit 1

# Path to the cserver
cserver=/usr/bin/cserver
RETVAL=0
prog="cWnn"

start () {
    # Start daemons.

    echo -n $"Starting $prog: "
    rm -f /tmp/jd_sockV4
    ( ${cserver} | grep "Finished" > /dev/null ) \
        && echo_success || echo_failure
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/cWnn
    return $RETVAL
}
stop () {
    # Stop daemons.
    echo -n  $"Stopping $prog: "
    killproc cserver
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/cWnn
    [ $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 cserver
        ;;
    restart|reload)
        restart
        ;;
    *)
	echo $"Usage: $0 {start|stop|status|restart|reload}"
        exit 1
esac
 

exit 0
