#!/bin/sh
# Start/stop the oscam daemon
#
### BEGIN INIT INFO
# Provides: oscam
# Required-Start: $syslog $network $pcscd
# Required-Stop: $syslog $network $pcscd
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and Stop oscam
# Description: oscam init script. This script start and stop oscam.
### END INIT INFO
. /lib/lsb/init-functions
CAMSERVER="OScam Server"
BINARY=oscam
DAEMON=/usr/local/bin/$BINARY
CONFIG_DIR=/usr/local/etc
PIDFILE=/var/run/oscam.pid
OSCAM_LOG=/var/log/vdr/oscam/oscam.log
OSCAM_USER_LOG=/var/log/vdr/oscam/oscamuser.log
CW_LOGDIR=/var/log/vdr/oscam/cw
CW_LOGFILES=$CW_LOGDIR/*.cwl
START="$DAEMON -- -b -c $CONFIG_DIR"
#test -f $DAEMON || exit 0
[ -x $DAEMON ] || exit 0
[ -d $CONFIG_DIR ] || exit 0
echo $BINARY
clear_file() {
# Clear log and pid file if exists
if [ -e $PIDFILE ]; then
rm -f $PIDFILE
fi
if [ -e $OSCAM_LOG ]; then
rm -f $OSCAM_LOG
fi
if [ -e $OSCAM_USER_LOG ]; then
rm -f $OSCAM_USER_LOG
fi
if [ -d $CW_LOGDIR ]; then
rm -f $CW_LOGFILES
fi
}
case "$1" in
start)
clear_file
log_daemon_msg "Starting $CAMSERVER"
start-stop-daemon --start --quiet --exe $DAEMON --startas $START
log_end_msg $?
;;
stop)
log_daemon_msg "Stopping $CAMSERVER"
start-stop-daemon --stop --quiet --exe $DAEMON
log_end_msg $?
;;
restart)
log_daemon_msg "Restarting $CAMSERVER"
start-stop-daemon --stop --retry 5 --quiet --exe $DAEMON
clear_file
start-stop-daemon --start --quiet --exe $DAEMON --startas $START
log_end_msg $?
;;
status)
status_of_proc -p $PIDFILE $DAEMON $BINARY && exit 0 || exit $?
;;
*)
log_action_msg "Usage: /etc/init.d/oscam {start|stop|restart|status}"
exit 2
;;
esac
exit 0