#!/bin/bash
# chkconfig: 35 75 36
# description: Starts and stops the 1C:Enterprise Remote Administration Server
### BEGIN INIT INFO
# Provides:          ras1c
# Required-Start:    $remote_fs $network $syslog $named
# Required-Stop:     $remote_fs $network $syslog $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Description:       1C:Enterprise 8.3 Remote Administration Server
### END INIT INFO

SCRIPTNAME="/etc/init.d/ras1c"
NAME="ras"
DAEMON="/opt/1C/v8.3/x86_64/ras"
DAEMON_ARGS=" cluster"
PIDFILE="/var/run/ras1c.pid"
DESC="1C:Enterprise Remote Administration Server"

case "$1" in
    start)
	echo "Starting $DESC"
	start-stop-daemon --start -b -m --exec $DAEMON $DAEMON_ARGS --pidfile $PIDFILE
	;;
    condstop|stop)
	echo "Shutting down $DESC"
        if [ -f $PIDFILE ] ; then
	    start-stop-daemon --stop --pidfile $PIDFILE
	    rm -f $PIDFILE
        else
	    kill $(pidof $NAME)
        fi
    ;;
    condrestart|restart)
	$0 stop
	$0 start
    ;;
    status)
	if [ -f $PIDFILE ] ; then
	echo running
	else
	echo stopped
        fi
    ;;
    *)
    echo "Usage: $SCRIPTNAME {start|condstop|stop|condrestart|restart|status}"
    exit 1
    ;;
esac

exit 0
