#!/bin/sh
#
# PolicyKit:   PolicyKit daemon
#
# chkconfig: 345 47 03
# description:  The PolicyKit maintains a list of privileges and \
#               provides interfaces for changing it. \
#               See http://www.freedesktop.org/Software/hal
#
# processname: polkitd
# config: /etc/PolicyKit
# pidfile: /var/run/polkit/pid
#
# Do not load RH compatibility interface. 
WITHOUT_RC_COMPAT=1 
 
# Sanity checks.
[ -x /usr/sbin/polkitd ] || exit 0

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

# so we can rearrange this easily
DAEMON=polkitd
LOCKFILE=/var/lock/subsys/$DAEMON
PIDFILE=/var/run/polkit/pid
USER=polkit
 
RETVAL=0

cleanup_state_dir()
{
    # Clean out all files in 
    rm -f /var/run/polkit-console/*
    mkdir -p /var/run/polkit-console
}

start() {
    msg_starting $"system PolicyKit"
    start_daemon --pidfile "$PIDFILE" \
		--lockfile "$LOCKFILE" \
		--no-announce \
		-- $DAEMON
     RETVAL=$?
     return $RETVAL
}

stop() {
    msg_stopping $"system PolicyKit" 
    stop_daemon --pidfile "$PIDFILE" \
		--lockfile "$LOCKFILE" \
		--no-announce \
		-- $DAEMON
    rm -f "$PIDFILE" ||:
    RETVAL=$?
    return $RETVAL
}

# See how we were called.
case "$1" in
    start)
	cleanup_state_dir
        start
        ;;
    stop)
        stop
        ;;
    status)
        status --pidfile "$PIDFILE" -- $DAEMON
	RETVAL=$?
        ;;
    restart)
        stop
        start
        ;;
    condstop) 
        if [ -f "$LOCKFILE" ]; then 
           stop
	fi 
       ;; 
    condrestart)
	if [ -f "$LOCKFILE" ]; then 
            stop
            start
        fi
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condstop|condrestart}"
        ;;
esac
exit $RETVAL
