#! /bin/sh
### BEGIN INIT INFO
# Provides:          starts and stops the piMoo cli player
# Required-Start:
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Kurze Beschreibung
# Description:       Längere Bechreibung

# for Debian users:
# copy this script to /etc/init.d/
# so you can easily control piMoo's cli_player.php with the runlevel editor "rcconf"
# e.g. to make it automatically launch at system start

# /opt/lampp/htdocs/piMoo/cli_player.php &
# or
# sudo -u dameon /opt/lampp/htdocs/piMoo/cli_player.php &
# this needs the "dameon" user to contain the group [x]audio


### END INIT INFO
# Author: Name <info@craft4fun.de>

# Aktionen
case "$1" in
    start)
      if [ ! "$(pidof mpg123)" ]
      then
        sudo -u daemon /opt/lampp/htdocs/piMoo/cli_player.php &
        sudo -u daemon /opt/lampp/htdocs/piMoo/cli_common.php &
      fi
    ;;

    next)
      sudo -u daemon pkill -USR1 -x mpg123
    ;;

    stop)
      pkill -x cli_player.php
      pkill -x cli_common.php
      pkill -x mpg123
    ;;

    *)
      echo "Usage: /etc/init.d/piMood {start|next|stop}"
      exit 1
    ;;

esac

exit 0

