a70c56a
#!/bin/bash
a70c56a
#
a70c56a
# setroubleshoot       This starts and stops setroubleshoot daemon
a70c56a
#
997fb2b
# chkconfig: 345 13 87
a70c56a
# description: This starts the SELinux Troubleshooting Daemon
a70c56a
#
a70c56a
# processname: /usr/sbin/setroubleshootd
a70c56a
# config: /etc/setroubleshoot/setroubleshoot.cfg
a70c56a
# pidfile: /var/run/setroubleshoot.pid
a70c56a
#
b512ba9
b512ba9
### BEGIN INIT INFO
b512ba9
# Provides: lsb-setroubleshootd
63272c6
# Required-Start: $local_fs $syslog $network $named $messagebus
63272c6
# Required-Stop: $local_fs $syslog $network $named $messagebus
b512ba9
# Default-Start:  3 4 5
b512ba9
# Default-Stop: 0 1 6
b512ba9
# Short-Description: start and stop SELinux Troubleshooting Daemon
b512ba9
# Description: controls operation of the SELinux Troubleshooting Daemon
b512ba9
#	(setroubleshootd) which listens for SELinux AVC denial messages
b512ba9
#	analyzes it and provides a friendly interpretation.
b512ba9
### END INIT INFO
b512ba9
a70c56a
# Return values according to LSB for all commands but status:
b512ba9
# 0	success
b512ba9
# 1	generic or unspecified error (current practice)
b512ba9
# 2	invalid or excess argument(s)
b512ba9
# 3	unimplemented feature (for example, "reload")
b512ba9
# 4	user had insufficient privilege
b512ba9
# 5	program is not installed
b512ba9
# 6	program is not configured
b512ba9
# 7	program is not running
b512ba9
b512ba9
# Command argument
b512ba9
# start		start the service
b512ba9
# stop		stop the service
b512ba9
# restart	stop and restart the service if the service is already running, otherwise start the service
b512ba9
# try-restart	restart the service if the service is already running
b512ba9
# reload	cause the configuration of the service to be reloaded without actually stopping and restarting the service
b512ba9
# force-reload	cause the configuration to be reloaded if the service supports this, otherwise restart the service if it is running
b512ba9
# status	print the current status of the service
b512ba9
b512ba9
# start, stop, restart, force-reload, and status actions must be supported
b512ba9
# reload and the try-restart actions are optional.
b512ba9
# the init script.
b512ba9
a70c56a
PATH=/sbin:/bin:/usr/bin:/usr/sbin
a70c56a
a70c56a
# Source function library.
a70c56a
. /etc/init.d/functions
a70c56a
096a7f2
RETVAL=0
096a7f2
prog="setroubleshootd"
096a7f2
abe1879
usage(){
abe1879
    echo $"Usage: $0 {start|stop|status|restart|try-restart|condrestart|reload|force-reload|cleardb [test][verbose]}"
abe1879
}
abe1879
abe1879
command=$1
abe1879
shift
abe1879
abe1879
[ $command ] || (usage; exit 3)
abe1879
abe1879
# look for extra options
abe1879
while [ $# -gt 0 ]; do
abe1879
    arg=$1
abe1879
    case "$arg" in
abe1879
	test)
abe1879
	    EXTRAOPTIONS="$EXTRAOPTIONS -c audit.text_protocol_socket_path=/tmp/audispd_events"
abe1879
	    ;;
abe1879
	verbose)
abe1879
	    EXTRAOPTIONS="$EXTRAOPTIONS -V"
abe1879
	    ;;
abe1879
	*)
abe1879
	    echo "unknown arg $arg"
abe1879
    esac
abe1879
    shift
abe1879
done
abe1879
096a7f2
rhstatus(){
096a7f2
    status $prog
096a7f2
    RETVAL=$?
096a7f2
    return $RETVAL
096a7f2
}
096a7f2
096a7f2
# Allow status as non-root and also if SELinux is disabled
abe1879
if [ "$command" = status ]; then
096a7f2
	rhstatus
096a7f2
	RETVAL=$?
096a7f2
	exit $RETVAL
096a7f2
fi
096a7f2
5d9bdca
# Silently exit is SELinux is not enabled
db2425c
[ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled || exit 1
5d9bdca
a70c56a
# Check that we are root ... so non-root users stop here
096a7f2
if test `id -u` != 0; then
096a7f2
	echo "You must be root"
096a7f2
	exit 4
096a7f2
fi
a70c56a
a70c56a
start(){
a70c56a
    echo -n $"Starting $prog: "
a70c56a
    unset HOME MAIL USER USERNAME
db2425c
    daemon $prog "$EXTRAOPTIONS"
a70c56a
    RETVAL=$?
a70c56a
    echo
a70c56a
    if test $RETVAL = 0 ; then
e514218
        touch /var/lock/subsys/$prog
a70c56a
    fi
2670b62
    if test $RETVAL = 3 ; then
2670b62
	echo -n $"Cannot start $prog: SELinux not enabled"
2670b62
    fi
a70c56a
    return $RETVAL
a70c56a
}
a70c56a
a70c56a
stop(){
a70c56a
    echo -n $"Stopping $prog: "
db2425c
    killproc $prog
a70c56a
    RETVAL=$?
a70c56a
    echo
e514218
    rm -f /var/lock/subsys/$prog
a70c56a
    return $RETVAL
a70c56a
}
a70c56a
a70c56a
reload(){
a70c56a
    echo -n $"Reloading configuration: "	
db2425c
    killproc $prog -HUP
a70c56a
    RETVAL=$?
a70c56a
    echo
a70c56a
    return $RETVAL
a70c56a
}
a70c56a
a70c56a
restart(){
a70c56a
    stop
a70c56a
    start
096a7f2
    RETVAL=$?
096a7f2
    return $RETVAL
a70c56a
}
a70c56a
a70c56a
condrestart(){
e514218
    [ -e /var/lock/subsys/$prog ] && restart
096a7f2
    RETVAL=0
096a7f2
    return $RETVAL
a70c56a
}
a70c56a
2bf0835
cleardb(){
2bf0835
    running=0
e514218
    [ -e /var/lock/subsys/$prog ] && running=1
2bf0835
    [ $running == 1 ] && stop
2bf0835
    echo $"Clearing database"
2bf0835
    rm -f /var/lib/setroubleshoot/database.xml
6f3757a
    rm -f /var/lib/setroubleshoot/audit_listener_database.xml
2bf0835
    [ $running == 1 ] && start
096a7f2
    RETVAL=0
096a7f2
    return $RETVAL
2bf0835
}
2bf0835
a70c56a
# See how we were called.
abe1879
case "$command" in
a70c56a
    start)
a70c56a
	start
096a7f2
	RETVAL=$?
a70c56a
	;;
a70c56a
    stop)
a70c56a
	stop
096a7f2
	RETVAL=$?
a70c56a
	;;
a70c56a
    status)
096a7f2
	rhstatus
096a7f2
	RETVAL=$?
a70c56a
	;;
a70c56a
    restart)
a70c56a
	restart
096a7f2
	RETVAL=$?
a70c56a
	;;
b512ba9
    force-reload|reload)
a70c56a
	reload
096a7f2
	RETVAL=$?
a70c56a
	;;
b512ba9
    try-restart|condrestart)
a70c56a
	condrestart
096a7f2
	RETVAL=$?
a70c56a
	;;
2bf0835
    cleardb)
2bf0835
	cleardb
096a7f2
	RETVAL=$?
2bf0835
	;;
a70c56a
    *)
abe1879
	usage
a70c56a
	RETVAL=3
a70c56a
esac
a70c56a
a70c56a
exit $RETVAL