#!/bin/sh
#
# 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
#
### BEGIN INIT INFO
# Provides:       mcstrans
# Required-Start: $remote_fs
# Required-Stop:  $remote_fs
# Should-Start:
# Should-Stop:
# Default-Start:  3 5
# Default-Stop:   0 1 2 6
# Short-Description: This starts and stops mcstransd
# Description:       This starts the SELinux Context Translation System Daemon
### END INIT INFO
#

PATH=/sbin:/bin:/usr/bin:/usr/sbin
prog="mcstransd"
lockfile=/var/lock/$prog
SETRANS_DIR=/var/run/setrans


# Source function library.
. /etc/rc.status

# Allow anyone to run status
if [ "$1" = "status" ] ; then
	echo -n $"Checking for $prog: "
	checkproc -p $LOCK_FILE $prog
	rc_status -v
	rc_exit
fi

# Check that we are root ... so non-root users stop here
if [ $EUID -ne 0 ] ; then
	echo $"Access denied. Only root can run this daemon"
	rc_failed 4
	rc_status -v
	rc_exit
fi

# Check whether SELinux is enabled
if  [ ! -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled ; then
	echo $"SELinux should be enabled to run this daemon"
	rc_failed 1
	rc_status -v
	rc_exit
fi


RETVAL=0

start(){
	test -x /sbin/mcstransd  || exit 5
	echo -n $"Starting $prog: "
	startproc -p $lockfile $prog "$EXTRAOPTIONS"
	rc_status -v

}

stop(){
	echo -n $"Stopping $prog: "
	killproc -p $lockfile -TERM $prog
	rc_status -v
}

restart(){
	stop
	start
}

condrestart(){
	[ -e $lockfile ] && restart || :
	return 0
}


# See how we were called.
case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    restart|force-reload)
	restart
	;;
    condrestart)
	condrestart
	;;
    *)
	echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
	rc_failed 3
	rc_status -v
esac

rc_exit
