PDA

View Full Version : I need help porting the rc script for WozaMediaServer


ghostcorps
February 17th, 2011, 00:58
Hi Guys

I have recently been trying to install WowzaMediaServer from the source because the port in the tree is both old, and unavailable as it requires a binary installer that has been removed.

The server itself works fine, but only when run in standalone mode, and there is no rc script provided that is compatible with FreeBSD.

I have been trying to modify the rc script provided with zero results but that is to be expected as this is the first time I have even looked inside an rc script. Below is the original, and them my work in progress, I am sure it is way off, but at least the paths are now correct, I know that much. :)

I have also tried using this as a template Porters Handbook (http://www.freebsd.org/doc/en/books/porters-handbook/rc-scripts.html), but I just made a mess.

If you have any advice for me that would be great :) Thanks for your time :)



Original rc script provided for CENTOS

#!/bin/bash
#
# Startup script for Wowza Media Server
#
# chkconfig: - 80 20
# description: Wowza Media Server is a media server
#

WMCOMMAND=${1}

FUNCTIONS_EXIST=false
if [ -f /etc/rc.d/init.d/functions ] ; then
. /etc/rc.d/init.d/functions
FUNCTIONS_EXIST=true
fi
if [ -f /etc/init.d/functions ] ; then
. /etc/init.d/functions
FUNCTIONS_EXIST=true
fi

if ! $FUNCTIONS_EXIST ; then
failure() {
return 0
}
success() {
return 0
}
fi

# define vars
RETVAL=0
WMSBASE_NAME=WowzaMediaServer
#WMSCONFIG_SCRIPT="/etc/WowzaMediaServer/$WMSBASE_NAME.conf"
WMSCONFIG_SCRIPT="/usr/local/WowzaMediaServer/bin/setenv.sh"
WMSLICENSE_FILE="/usr/local/WowzaMediaServer/conf/Server.license"
AMAZONEC2_INSTALL_SCRIPT="/usr/local/WowzaMediaServer/bin/AmazonEC2Install.sh"
WMSDAEMON_CMD=/usr/bin/WowzaMediaServerd
WMSPID_FILE="/var/run/$WMSBASE_NAME.pid"
WMSLOCK_FILE="/var/run/$WMSBASE_NAME"
SHUTDOWN_WAIT=20

[ -r "$WMSCONFIG_SCRIPT" ] && . "$WMSCONFIG_SCRIPT"

if ! test -f "${WMSLICENSE_FILE}" ; then
echo ""
echo "ERROR: Missing license file: (${WMSLICENSE_FILE})"
echo "You must first run Wowza Media Server 2 in "
echo "standalone mode to enter serial number. Execute the "
echo "following commands to run in standalone mode:"
echo ""
echo "cd /usr/local/WowzaMediaServer"
echo "./startup.sh"
echo ""
exit 0
fi

testjava=`which ${_EXECJAVA} 2>/dev/null`
if ! test -f "$testjava" ; then
echo ""
echo "ERROR: The Java command (${_EXECJAVA}) could not be found."
echo "Search path: $PATH"
echo "In most cases this problem can be fixed by adding a symbolic "
echo "link to the Java command in the /usr/bin directory. "
echo "To do this first execute the command \"which java\" to identify "
echo "the full path to the Java executable. Next, create a symbolic "
echo "link to this file with the command"
echo "\"ln -sf [path-to-java] /usr/bin/java\" where [path-to-java] is "
echo "the path returned by the \"which\" command."
echo ""
exit 0
fi

#
start() {

if [ -f $WMSPID_FILE ]; then
read kpid < $WMSPID_FILE
kill -9 $kpid
echo $"$WMSBASE_NAME is already running ($kpid): stopping"
rm -f $WMSPID_FILE
fi

echo -n $"$WMSBASE_NAME: starting"
#$AMAZONEC2_INSTALL_SCRIPT
$WMSDAEMON_CMD $WMSCONFIG_SCRIPT $WMSPID_FILE start >/dev/null 2>&1 &
success "$WMSBASE_NAME startup"
echo
touch $WMSLOCK_FILE

return 0
}

stop() {

if [ -f $WMSPID_FILE ]; then

echo -n $"$WMSBASE_NAME: stopping"
read kpid < $WMSPID_FILE


$WMSDAEMON_CMD $WMSCONFIG_SCRIPT $WMSPID_FILE stop >/dev/null 2>&1 &

let kwait=$SHUTDOWN_WAIT
count=0;
until [ `ps -p $kpid | grep -c $kpid` = '0' ] || [ $count -gt $kwait ]
do
echo -n -e "\nwaiting for processes to exit";
sleep 1
let count=$count+1;
done

if [ $count -gt $kwait ]; then
echo -n -e "\nkilling processes which didn't stop after $SHUTDOWN_WAIT seconds"
kill -9 $kpid
fi

rm -f $WMSPID_FILE
success "$WMSBASE_NAME shutdown"
else
echo -n $"$WMSBASE_NAME: not running"
fi
echo
rm -f $WMSLOCK_FILE
return 0
}

localstatus() {
if [ -f $WMSLOCK_FILE ]; then
echo "$WMSBASE_NAME started"
else
echo "$WMSBASE_NAME stopped"
fi
RETVAL=0
}

# See how we were called.
case "$WMCOMMAND" in
start)
start
;;
stop)
stop
;;
status)
localstatus
;;
restart)
stop
start
;;
*)
echo $"Usage: $WMSBASE_NAME {start|stop|restart|status}"
exit 1
esac

exit $RETVAL



My modified script, changes are bold:

#!/bin/sh
#
# Startup script for Wowza Media Server
#
# chkconfig: - 80 20
# description: Wowza Media Server is a media server
#

WMCOMMAND=${1}

FUNCTIONS_EXIST=false
if [ -f /etc/rc.subr ] ; then
. /etc/rc.subr
FUNCTIONS_EXIST=true
fi
#if [ -f /etc/rc.d/functions ] ; then
# . /etc/rc.d/functions
# FUNCTIONS_EXIST=true
#fi

if ! $FUNCTIONS_EXIST ; then
failure() {
return 0
}
success() {
return 0
}
fi

# define vars
RETVAL=0
WMSBASE_NAME=WowzaMediaServer
#WMSCONFIG_SCRIPT="/etc/WowzaMediaServer/$WMSBASE_NAME.conf"
WMSCONFIG_SCRIPT="/usr/local/WowzaMediaServer/bin/setenv.sh"
WMSLICENSE_FILE="/usr/local/WowzaMediaServer/conf/Server.license"
AMAZONEC2_INSTALL_SCRIPT="/usr/local/WowzaMediaServer/bin/AmazonEC2Install.sh"
WMSDAEMON_CMD=/usr/local/WowzaMediaServer/bin/WowzaMediaServerd
WMSPID_FILE="/var/run/$WMSBASE_NAME.pid"
WMSLOCK_FILE="/var/run/$WMSBASE_NAME"
SHUTDOWN_WAIT=20

[ -r "$WMSCONFIG_SCRIPT" ] && . "$WMSCONFIG_SCRIPT"

if ! test -f "${WMSLICENSE_FILE}" ; then
echo ""
echo "ERROR: Missing license file: (${WMSLICENSE_FILE})"
echo "You must first run Wowza Media Server 2 in "
echo "standalone mode to enter serial number. Execute the "
echo "following commands to run in standalone mode:"
echo ""
echo "cd /usr/local/WowzaMediaServer"
echo "./startup.sh"
echo ""
exit 0
fi

testjava=`which ${_EXECJAVA} 2>/dev/null`
if ! test -f "$testjava" ; then
echo ""
echo "ERROR: The Java command (${_EXECJAVA}) could not be found."
echo "Search path: $PATH"
echo "In most cases this problem can be fixed by adding a symbolic "
echo "link to the Java command in the /usr/bin directory. "
echo "To do this first execute the command \"which java\" to identify "
echo "the full path to the Java executable. Next, create a symbolic "
echo "link to this file with the command"
echo "\"ln -sf [path-to-java] /usr/bin/java\" where [path-to-java] is "
echo "the path returned by the \"which\" command."
echo ""
exit 0
fi

#
start() {

if [ -f $WMSPID_FILE ]; then
read kpid < $WMSPID_FILE
kill -9 $kpid
echo $"$WMSBASE_NAME is already running ($kpid): stopping"
rm -f $WMSPID_FILE
fi

echo -n $"$WMSBASE_NAME: starting"
#$AMAZONEC2_INSTALL_SCRIPT
$WMSDAEMON_CMD $WMSCONFIG_SCRIPT $WMSPID_FILE start >/dev/null 2>&1 &
success "$WMSBASE_NAME startup"
echo
touch $WMSLOCK_FILE

return 0
}

stop() {

if [ -f $WMSPID_FILE ]; then

echo -n $"$WMSBASE_NAME: stopping"
read kpid < $WMSPID_FILE


$WMSDAEMON_CMD $WMSCONFIG_SCRIPT $WMSPID_FILE stop >/dev/null 2>&1 &

let kwait=$SHUTDOWN_WAIT
count=0;
until [ `ps -p $kpid | grep -c $kpid` = '0' ] || [ $count -gt $kwait ]
do
echo -n -e "\nwaiting for processes to exit";
sleep 1
let count=$count+1;
done

if [ $count -gt $kwait ]; then
echo -n -e "\nkilling processes which didn't stop after $SHUTDOWN_WAIT seconds"
kill -9 $kpid
fi

rm -f $WMSPID_FILE
success "$WMSBASE_NAME shutdown"
else
echo -n $"$WMSBASE_NAME: not running"
fi
echo
rm -f $WMSLOCK_FILE
return 0
}

localstatus() {
if [ -f $WMSLOCK_FILE ]; then
echo "$WMSBASE_NAME started"
else
echo "$WMSBASE_NAME stopped"
fi
RETVAL=0
}

# See how we were called.
case "$WMCOMMAND" in
start)
start
;;
stop)
stop
;;
status)
localstatus
;;
restart)
stop
start
;;
*)
echo $"Usage: $WMSBASE_NAME {start|stop|restart|status}"
exit 1
esac

exit $RETVAL

AndyUKG
February 21st, 2011, 09:53
Hi,

If your preferred route is to use the CentOS script then you would make your life easier by using Bash as the shell in FreeBSD too. As a quick fix, without looking too hard at the problem ;)

ta Andy.

ghostcorps
February 22nd, 2011, 06:53
Thanks Andy

This is the only script that was provided.


I have decided to use Red5 anyway :)