#!/bin/sh

# This script is used to start and stop a package, detect running status, and generate the log file.
# Parameters used by the script are listed in below: start, stop, status

PRIVATE_LOCATION="/var/packages/${SYNOPKG_PKGNAME}/target"
START_FILE="${PRIVATE_LOCATION}/${SYNOPKG_PKGNAME}/start.sh"
STOP_FILE="${PRIVATE_LOCATION}/${SYNOPKG_PKGNAME}/stop.sh"

case $1 in
    start)
        /bin/sh ${START_FILE}
        exit 0
    ;;
    stop)
        /bin/sh ${STOP_FILE}
        exit 0
    ;;
    status)
        ret=$(ps -ef | grep ${SYNOPKG_PKGNAME} | grep -v 'grep')
        if [ -n "${ret}" ]; then
            exit 0
        else
            exit 1
        fi
    ;;
esac

exit 0
