#! /bin/sh
# Author: Henne Vogelsang 
#
# /etc/init.d/recordserver
#   and its symbolic link
# /usr/sbin/rcrecordserver
#
#    This program is free software; you can redistribute it and/or modify 
#    it under the terms of the GNU General Public License as published by 
#    the Free Software Foundation; either version 2 of the License, or 
#    (at your option) any later version. 
# 
#    This program is distributed in the hope that it will be useful, 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
#    GNU General Public License for more details. 
# 
#    You should have received a copy of the GNU General Public License 
#    along with this program; if not, write to the Free Software 
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# LSB compatible service control script; see http://www.linuxbase.org/spec/
# 
### BEGIN INIT INFO
# Provides:          recordserver
# Required-Start:    $syslog $remote_fs
# Required-Stop:     $syslog $remote_fs
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: freevo recordserver daemon
# Description:       recordserver
### END INIT INFO
# 
# Check for missing binaries (stale symlinks should not happen)
# Note: Special treatment of stop for LSB conformance
FREEVO_BIN=/usr/bin/freevo
test -x $FREEVO_BIN || { echo "$FREEVO_BIN not installed"; 
	if [ "$1" = "stop" ]; then exit 0;
	else exit 5; fi; }

# Source LSB init functions
. /etc/rc.status

# Source sysconfig file
. /etc/sysconfig/displaymanager
# The freevo user is the same as the autologin user
FREEVO_USER=$DISPLAYMANAGER_AUTOLOGIN
# Reset status of this service
rc_reset

case "$1" in
    start)
	echo -n "Starting freevo recordserver "
	su - $FREEVO_USER -c "$FREEVO_BIN recordserver --daemon"
	rc_status -v
	;;
    stop)
	echo -n "Shutting down freevo recordserver "
	su - $FREEVO_USER -c "$FREEVO_BIN recordserver --stop"
	rc_status -v
	;;
    restart)
	$0 stop
	$0 start
	rc_status
	;;
    *)
	echo "Usage: $0 {start|stop|restart}"
	exit 1
	;;
esac
rc_exit
