#!/bin/sh
#
# drweb-esuite-proxy  --- Dr.Web(R) Enterprise Suite proxy
#
# chkconfig:   345 90 10
# description: Dr.Web(R) Enterprise Suite proxy
# processname: drwcsd-proxy
# config:      /var/opt/drwcs/etc/drwcsd-proxy.xml
#
### BEGIN INIT INFO
# Provides:          drweb-esuite-proxy
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start and stop Dr.Web(R) Enterprise Suite proxy
### END INIT INFO
#

#
# Copyright 1992 - 2012 Doctor Web, Ltd.
#
# Use is subject to license terms.
# The reproduction in any form without written permission of
# Doctor Web, Ltd. and proper attribution is strongly prohibited.
#
# Dr.Web is a registered trademark of Doctor Web, Ltd.
#

os=`uname`

case "$1" in
  start)
    ( LD_LIBRARY_PATH=/usr/local/drwcs/lib:$LD_LIBRARY_PATH
      export LD_LIBRARY_PATH
      /usr/local/drwcs/bin/drwcsd-proxy --daemon || echo "Error: $?"
    )
    exit 0
    ;;
  stop)
    if test SunOS = $os; then
      pid=`ps -e -opid,comm | grep 'drwcsd-proxy'| head -n1 | cut -c 1-6`
    else
      pid=`ps ax | grep 'drwcsd-proxy' | grep -v grep | cut -c 1-5`
    fi

    test -n "${pid}" && kill -2 ${pid} || echo "Error: It seems proxy is not started"
    exit 0
    ;;
  *)
    echo "$0: '$@' -- unknown command"
    echo "Usage: $0 start"
    exit 1
    ;;
esac
