#!/bin/bash
#
# 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

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

prog="mcstransd"
lockfile="/var/lock/subsys/$prog"
PIDFILE="/var/run/$prog.pid"

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

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

RETVAL=0

start(){
	start_daemon --pidfile "$PIDFILE" --lockfile "$lockfile" --expect-user root -- $prog
	RETVAL=$?
	return $RETVAL
}

stop(){
	stop_daemon --pidfile "$PIDFILE" --lockfile "$lockfile" --expect-user root -- $prog
	RETVAL=$?
}

restart(){
	stop
	start
}

reload(){
	restart
}

# See how we were called.
case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    restart)
	restart
	;;
	reload)
	reload
	;;
	condrestart)
	if [ -e "$lockfile" ]; then
		restart
	fi
	;;
	condstop)
	if [ -e "$lockfile" ]; then
		stop
	fi
	;;
	condreload)
	if [ -e "$lockfile" ]; then
		reload
	fi
	;;
	status)
	status --pidfile "$PIDFILE" --expect-user root -- $prog
	RETVAL=$?
	;;
    *)
	msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
	RETVAL=1
esac

exit $RETVAL
