#!/bin/sh
# Begin /etc/init.d/gpm

### BEGIN INIT INFO
# Provides:            gpm
# Required-Start:      $network
# Should-Start:        $remote_fs
# Required-Stop:       $network
# Should-Stop:         $remote_fs
# Default-Start:       3 4 5
# Default-Stop:        0 1 2 6
# Short-Description:   General Purpose Mouse (service)
# Description:         The gpm service is used to provide mouse services
#                      to console applications.
# X-LFS-Provided-By:   BLFS
### END INIT INFO

. /lib/lsb/init-functions

MESSAGE="GPM Console Mouse Service..."
BIN_FILE=/usr/sbin/gpm
CONFIG_FILE=/etc/sysconfig/mouse

# Make certain that the binary exists, and that the config file exists
chk_stat

# Source the config file 
. "${CONFIG_FILE}"

case "$1" in

    start)
        start_daemon "${BIN_FILE}" -m "$MDEVICE" -t "$PROTOCOL" "$GPMOPTS"
        evaluate_retval start
    ;;

    stop)
        killproc "${BIN_FILE}"
        evaluate_retval stop
    ;;

    restart)
        # Restart service (if running) or start service
        killproc "${BIN_FILE}"
        sleep 1
        start_daemon "${BIN_FILE}" -m "$MDEVICE" -t "$PROTOCOL" "$GPMOPTS"
        evaluate_retval restart
    ;;

    force-reload)
        # Forcefully Reload the configuartion. Usually a SIGHUP is used for 
        # this, however, GPM doesn't support this signal as there is no 
        # configuration to reload, so restart it (only if already running)
        kill -0 `pidofproc "${BIN_FILE}"` 2> /dev/null
        retval="${?}"
        if [ "${retval}" = "0" ]
        then
            # restart it...
            killproc "${BIN_FILE}"
            sleep 1
            "${BIN_FILE}" -m "$MDEVICE" -t "$PROTOCOL" "$GPMOPTS"
            evaluate_retval force-reload
        else
            log_warning_msg "Force reloading ${MESSAGE}: Not running"
            exit "${retval}"
        fi
    ;;

    status)
        statusproc
    ;;

    *)
        echo "    Usage:  ${0}{start|stop|restart|force-reload|status}"
        if [ "${1}" = "reload" -o "${1}" = "try-restart" ]
        then
            echo "    Error:  Unimplemented function '${1}'"
            exit 3
        else
            exit 2
        fi
    ;;

esac

# End /etc/init.d/gpm

