#!/bin/sh

##############################################################################
#                                                                            #
# Copyright (c) 2015 by R1Soft All rights reserved                           #
#                                                                            #
##############################################################################
#
# chkconfig: 2345 99 99
# description: R1Soft Document Storage Service
# processname: docstore

### BEGIN INIT INFO
# Provides:          docstore
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts R1Soft Document Service
# Description:       Starts R1Soft Document Service
# Options:           start), stop), restart), status)
### END INIT INFO
#!/bin/sh

ERROR=0
case "$@" in
  start|stop|status|restart)
	OPTION=$@
	;;
  *)
	OPTION="help"
	;;
esac

INITSYSTEM=$(ps -p 1 -o comm=)
if [ "$INITSYSTEM" = "systemd" ] && [ -f /etc/systemd/system/docstore.service ]; then
	systemctl $OPTION docstore.service && ERROR=0 || ERROR=1
else
	/opt/r1soft/docstore/service-scripts/docstore-service $OPTION && ERROR=0 || ERROR=1
fi
exit $ERROR
