#!/bin/bash
# Time-stamp: <2008-07-13 09:31:34 kojima>

# This file is derived from  avahi.
# Start/stop/restart the system-tools-daemon daemon:

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DESC="Console kit Daemon"
NAME="console-kit-daemon"
DAEMON="/usr/sbin/$NAME"

start()
{
  echo "Starting $DESC:  $DAEMON "
  $DAEMON 
}

status()
{
  chk=`ps axww | gawk '{print $5}' | grep $NAME`
  if [ "$chk.x" != ".x" ]; then
      return 0
  else
      return 1
  fi
}

stop()
{

  if ( ! status ); then
     echo "$DESC seems already stopped"
  else
     echo "Stopping $DESC: "
     killall $DAEMON  
  fi
}

restart()
{
  stop
  start
}

case "$1" in
'start')
  if ( ! status ); then
    start
  else
    echo "$DESC is already running (will not start it twice)."
  fi
  ;;
'stop')
  stop
  ;;
'restart')
  restart
  ;;
'status')
  if ( status ); then
    echo "$DESC is currently running"
  else
    echo "$DESC is not running."
  fi
  ;;
*)
  echo "usage $0 start|stop|status|restart"
esac
