Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

/etc/rc.d/coherence

By: a guest on Aug 1st, 2010  |  syntax: Bash  |  size: 1.09 KB  |  hits: 130  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2.  
  3. DESC="Coherence UPnP A/V Media Server"
  4.  
  5. if [ "$(whoami)" != "root" ];then
  6.  echo "You must be root to start/restart/stop services."
  7.  exit 1
  8. fi
  9.  
  10. . /etc/rc.conf
  11. . /etc/rc.d/functions
  12.  
  13. [ -r "/etc/conf.d/coherence" ] && . /etc/conf.d/coherence
  14.  
  15. PID=`pidof -o %PPID /usr/bin/coherence`
  16.  
  17. case "$1" in
  18.   start)
  19.     stat_busy "Starting $DESC"
  20.     if [ -z "$PID" ]; then
  21.         su - $USER -c /usr/bin/coherence &>/dev/null || stat_fail
  22.         PID=`pidof -o %PPID /usr/bin/coherence`
  23.         if [ -z "$PID" ]; then exit 1;fi
  24.         echo $PID > /var/run/coherence.pid
  25.         add_daemon coherence
  26.         stat_done
  27.     else
  28.                 echo -n "Already running!"
  29.                 stat_fail
  30.     fi
  31.     ;;
  32.   stop)
  33.     stat_busy "Stopping $DESC"
  34.     [ ! -z "$PID" ] && kill $PID &> /dev/null
  35.     if [ $? -gt 0 ]; then
  36.       echo -n "Not started!"
  37.       stat_fail
  38.     else
  39.       rm /var/run/coherence.pid
  40.       rm_daemon coherence
  41.       stat_done
  42.     fi
  43.     ;;
  44.   restart)
  45.     $0 stop
  46.     sleep 1
  47.     $0 start
  48.     ;;
  49.   *)
  50.     echo "usage: $0 {start|stop|restart}"
  51. esac