#!/bin/sh
# Start/stop/restart icecast.

# Start icecast:
icecast_start() {
  if [ -x /usr/local/bin/icecast -a -r /usr/local/etc/icecast.xml ]; then
    echo "Starting Icecast:  /usr/local/bin/icecast -c /usr/local/etc/icecast.xml -b"
    /usr/local/bin/icecast -c /usr/local/etc/icecast.xml -b > /dev/null
  fi
}

# Stop icecast:
icecast_stop() {
  if [ -r /usr/local/share/icecast/icecast.pid ]
    kill `cat /usr/local/share/icecast/icecast.pid`
  else
    echo "No pid file found.  Running killall icecast."
    echo "It is recommended that you enable the pid file in icecast.xml"
    killall icecast
  fi
}

# Restart icecast:
icecast_restart() {
  icecast_stop
  sleep 1
  icecast_start
}

case "$1" in
'start')
  icecast_start
  ;;
'stop')
  icecast_stop
  ;;
'restart')
  icecast_restart
  ;;
*)
  echo "usage $0 start|stop|restart"
esac
