LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File noxspellserver.init of Package noxspellserver (Project home:lrupp)

#!/bin/bash
#
#     Template LSB system startup script for example service/daemon FOO
#     Copyright (C) 1995--2005  Kurt Garloff, SUSE / Novell Inc.
#          
#     This library is free software; you can redistribute it and/or modify it
#     under the terms of the GNU Lesser General Public License as published by
#     the Free Software Foundation; either version 2.1 of the License, or (at
#     your option) any later version.
#                             
#     This library 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
#     Lesser General Public License for more details.
#      
#     You should have received a copy of the GNU Lesser General Public
#     License along with this library; if not, write to the Free Software
#     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
#     USA.
#
# /etc/init.d/noxspellserver
#   and its symbolic link
# /usr/sbin/rcnoxspellserver
#
### BEGIN INIT INFO
# Provides:          noxspellserver
# Required-Start:    $syslog $remote_fs
# Should-Start:      $time 
# Required-Stop:     $syslog $remote_fs
# Should-Stop:       $time
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: Nox Spell Server daemon providing GoogieSpell
# Description:       Nox Spell Server is a little Python Aspell 
#	server that is fully compatible with GoogieSpell.
### END INIT INFO
#
NOX_BIN='/usr/bin/nox_server.py'
test -x $NOX_BIN || { echo "$NOX_BIN not installed"; 
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi; }

# Check for existence of needed config file and read it
NOX_CONFIG=/etc/sysconfig/noxspellserver
test -r $NOX_CONFIG || { echo "$NOX_CONFIG not existing";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 6; fi; }

NAME='Nox Spell Server'
PIDFILE='/var/run/noxspellserver.pid'
NOX_TIMEOUT=3

# Read config   
. $NOX_CONFIG

# Shell functions sourced from /etc/rc.status
. /etc/rc.status

# Reset status of this service
rc_reset

case "$1" in
    start)
        echo -n "Starting $NAME: "
        /sbin/startproc -p $PIDFILE $NOX_BIN $NOXPORT 2>/dev/null
        if [ ! -f $PIDFILE ]; then
            PID=$(pidof -x $NOX_BIN | tail -n1)
            echo $PID > $PIDFILE
        fi
        # Remember status and be verbose
        rc_status -v
        ;;
    stop)
        echo -n "Shutting down $NAME "
        if checkproc "$NOX_BIN" ; then
            killproc -t 2 -p "$PIDFILE" -TERM "$NOX_BIN"
            sleep 1
            if [ -e "$PIDFILE" ]; then
                while [ -e "$PIDFILE" ] && [ $NOX_TIMEOUT -gt 0 ] ; do
                    sleep 1
                    NOX_TIMEOUT=$[$NOX_TIMEOUT-1]
                    echo -n '.'
                    [ $NOX_TIMEOUT -eq 41 ] && echo
                done
            fi
            if checkproc "$NOX_BIN" ; then
                PID=$(cat $PIDFILE)
                /bin/kill -KILL "$PID"
                echo -n " $NAME killed"
                rm "$PIDFILE"
            fi
        else
            echo -n "$NAME not running"
            rc_failed 7
        fi
        rc_status -v
        ;;
    try-restart|condrestart)
        if test "$1" = "condrestart"; then
                echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
        fi
        $0 status
        if test $? = 0; then
                $0 restart
        else
                rc_reset        # Not running is not a failure.
        fi
        rc_status
        ;;
    restart)
        $0 stop
        $0 start
        rc_status
        ;;
    force-reload)
        echo -n "Reload service $NAME "
        $0 try-restart
        rc_status
        ;;
    reload)
        echo -n "Reload service $NAME "
        rc_failed 3
        rc_status -v
        ;;
    status)
        echo -n "Checking for service $NAME "
        /sbin/checkproc -p $PIDFILE $NOX_BIN
        rc_status -v
        ;;
    *)
        echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}"
        exit 1
        ;;
esac
rc_exit