#!/bin/sh
# This script is used to start and stop a package, detect running status, and generate the log file

SYMDESKTOP="/usr/syno/synoman/webman/3rdparty/${SYNOPKG_PKGNAME}"

# DSM Version file
. /etc.defaults/VERSION

if [ "$majorversion" -eq "5"  ]; then
	#pid of Archiware P5 nsd process, to check if archiware is running or not
	NSDPID="$(ps -w | grep /var/packages/ArchiwareP5/target/bin/nsd | grep -v grep | awk '{print $1}')"
elif [ "$majorversion" -eq "6"  ]; then
	NSDPID="$(ps -ax | grep /ArchiwareP5/target/bin/nsd | grep -v grep | awk '{print $1}')"
fi

# Log file location
LOG_PATH="$SYNOPKG_PKGDEST/log/lexxsrv.log"

case "$1" in
        start)
            /var/packages/ArchiwareP5/target/start-server
           ;;

        stop)
            /var/packages/ArchiwareP5/target/stop-server
            exit 0
	    ;;

        status)
            #echo $NSDPID
	    if [ ! "$NSDPID" ]; then
            	# echo "Lexxsrv is not running"
        	exit 3
            fi

            if [ "$NSDPID" ]; then
	    	# echo "Lexxsrv is running"
		exit 0
	    fi
            ;;

	log)
	    echo "$LOG_PATH"
	    exit 0
esac

exit 0
