#!/bin/sh
#
# mcstransd        This starts and stops mcstransd
#
# chkconfig: - 08 87
# description: This starts the SELinux Context Translation System Daemon
#
# processname: /sbin/mcstransd
# pidfile: /var/run/mcstransd.pid
#
# Return values according to LSB for all commands but status:
# 0 - success
# 1 - generic or unspecified error
# 2 - invalid or excess argument(s)
# 3 - unimplemented feature (e.g. "reload")
# 4 - insufficient privilege
# 5 - program is not installed
# 6 - program is not configured
# 7 - program is not running

PATH=/sbin:/bin:/usr/bin:/usr/sbin
prog="mcstransd"
lockfile=/var/lock/subsys/$prog

# Source function library.
. /etc/rc.d/init.d/functions

[ -f /etc/sysconfig/mcstrans ] && . /etc/sysconfig/mcstrans

# Allow anyone to run status
if [ "$1" = "status" ] ; then
	status $prog
	RETVAL=$?
	exit $RETVAL
fi

# Check that we are root ... so non-root users stop here
test $EUID = 0  || exit 4

# If selinux is not enabled, return success
test -x /usr/sbin/selinuxenabled && /usr/sbin/selinuxenabled || exit 0

RETVAL=0

start(){
	if [ -f $lockfile ]; then
		msg_already_running "mcstrans"
		return
	fi
	msg_starting "mcstrans"
	unset HOME MAIL USER USERNAME
	daemon $prog "$EXTRAOPTIONS"
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch $lockfile
}

stop(){
	if [ ! -f $lockfile ]; then
		msg_not_running "mcstrans"
		return
	fi

	msg_stopping "mcstrans"
	killproc $prog
	rm -f $lockfile
}

restart(){
	stop
	start
}

condrestart(){
	if [ ! -f $lockfile ]; then
		msg_not_running "mcstrans"
		RETVAL=$1
		return
	fi

	restart
}


# See how we were called.
case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    restart)
	restart
	;;
    force-reload)
	condrestart 7
	;;
    try-restart|condrestart)
	condrestart 0
	;;
    *)
	msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
	RETVAL=3
esac

exit $RETVAL
