#!/sbin/runscript
#

depend() {
	use logger dns
	need net
}

SEMS_CFG_FILE=${SEMS_CFG_FILE:-/etc/sems/sems.conf}
SEMS_PIDFILE=${SEMS_PIDFILE:-/var/run/sems.pid}
SEMS_CREATE_CORE=${SEMS_CREATE_CORE:-true}
SEMS_COREDIR=${SEMS_COREDIR:-/var/core}
SEMS_BINARY=${SEMS_BINARY:-/usr/sbin/sems}

checkconfig() {
	if [ ! -f "${SEMS_CFG_FILE}" ] ; then
		eerror "You need a "${SEMS_CFG_FILE}" file to run sems"
		return 1;
	fi
}


start() {
    local myopts=""

    [ "${SEMS_USER}" != "" ] && \
	myopts="${myopts} -u ${SEMS_USER}"

    [ "${SEMS_GROUP}" != "" ] && \
	myopts="${myopts} -g ${SEMS_GROUP}"


    checkconfig || return 1

    if test "$SEMS_CREATE_CORE" = "true" ; then
	# directory for the core dump files
	[ -d $SEMS_COREDIR ] || mkdir $SEMS_COREDIR
	chmod 777 $SEMS_COREDIR
	echo "$SEMS_COREDIR/core.%e.sig%s.%p" > /proc/sys/kernel/core_pattern
	ulimit -c unlimited
    fi

    ebegin "Starting ${SVCNAME}"
	start-stop-daemon --start --exec "${SEMS_BINARY}" \
	    --pidfile "${SEMS_PIDFILE}" \
	    -- \
	    -f "${SEMS_CFG_FILE}" \
	    ${myopts} 
    eend $?
}

stop() {
	if [ "${RC_CMD}" = "restart" ] ; then
		checkconfig || return 1
	fi

	ebegin "Stopping ${SVCNAME}"
	start-stop-daemon --stop --exec "${SEMS_BINARY}" \
	    --pidfile "${SEMS_PIDFILE}" --quiet
	eend $?
}
