#!/bin/sh
### BEGIN INIT INFO
# Provides:          codemeter
# Required-Start:    $network $local_fs $remote_fs
# Required-Stop:     $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: CodeMeter Server
# Description:       CodeMeter Server
### END INIT INFO

# Author: Pierre-Olivier Proulx <poproulx@robotiq.com>

INSTALLATION_DIR=/opt/robotiq/vision_system
DESC="CodeMeter Server"
NAME=codemeter
DAEMON=$INSTALLATION_DIR/codemeter_6.20.2153.501_i386/usr/sbin/CodeMeterLin
SCRIPTNAME=/etc/init.d/$NAME
CONFIGFILE=/etc/wibu/CodeMeter/Server.ini

# Exit if the package is not installed
[ -x $DAEMON ] || exit 1

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

do_start()
{
	start-stop-daemon --start --quiet --exec $DAEMON
}

do_stop()
{
	start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --exec $DAEMON
}

do_reload()
{
	start-stop-daemon --stop --signal USR1 --quiet --exec $DAEMON
}

case "$1" in
  start)
    log_daemon_msg "Starting $DESC " "$NAME"
    do_start
    case "$?" in
		0|1) log_end_msg 0 ;;
		2) log_end_msg 1 ;;
	esac
  ;;
  stop)
	log_daemon_msg "Stopping $DESC" "$NAME"
	do_stop
	case "$?" in
		0|1) log_end_msg 0 ;;
		2) log_end_msg 1 ;;
	esac
	;;
  status)
       status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
       ;;
  reload)
	log_daemon_msg "Reloading $DESC" "$NAME"
	do_reload
	log_end_msg 0
	;;
  *)
	echo "Usage: $SCRIPTNAME {start|stop|status|reload}" >&2
	exit 3
	;;
esac
