#!/bin/bash
### BEGIN INIT INFO
# Provides:          crtmpserver
# Required-Start:    $network $local_fs $remote_fs
# Required-Stop:     $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: C++ RTMP/RTSP streaming server
# Description:       High performance RTMP/RTSP/MPEG-TS streaming server
### END INIT INFO

# Author: Andriy Beregovenko <jet@jet.kiev.ua>

PATH=/sbin:/usr/sbin:/bin:/usr/bin
NAME=crtmpserver
DAEMON=/usr/sbin/crtmpserver
DAEMON_ARGS="--daemon"
DAEMON_CONF="/etc/crtmpserver/crtmpserver.lua"
DAEMON_USER=crtmpserver
PIDFILE=/var/run/$NAME.pid

[ -x $DAEMON ] || exit 0

[ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME

# Source function library.
. /etc/rc.d/init.d/functions

DAEMON_UID=`id -u ${DAEMON_USER}`
DAEMON_GID=`id -g ${DAEMON_USER}`
[ -z ${DAEMON_UID} ] && (echo "User ${DAEMON_USER} not exists"; return 1)
DAEMON_UID_ARG="--uid=${DAEMON_UID} --gid=${DAEMON_GID}"

do_start()
{
	echo -n $"Starting $NAME: "
	daemon $DAEMON --pid=${PIDFILE} $DAEMON_ARGS $DAEMON_UID_ARG $DAEMON_CONF
	RETVAL=$?
	[ "$RETVAL" = "0" ] && success || failure
	echo
	return $RETVAL
}

do_stop()
{
	echo -n $"Stopping $NAME: "
	killproc -p ${PIDFILE} $DAEMON
	RETVAL=$?
	[ "$RETVAL" = "0" ] && success || failure
	echo
	return $RETVAL
}

case "$1" in
  start)
	do_start
	RETVAL=$?
	;;
  stop)
	do_stop
	RETVAL=$?
	;;
  status)
	status $DAEMON
	RETVAL=$?
       ;;
  restart)
	do_stop
	do_start
	RETVAL=$?
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart}"
	RETVAL=2
	;;
esac
exit $RETVAL
:
