Red5 init Script for Ubuntu

If you’ve read our Installing and Integrating Red5 with Kaltura CE5 post, you have probably encountered several errors when starting or stopping the Red5 Server.

./red5: 14: .: Can't open /etc/rc.d/init.d/functions
./red5: line 30: success: command not found
./red5: line 30: failure: command not found

The above error messages occur because the Red5 init Script is written for CentOS and not for Ubuntu.

While CentOS uses /etc/init.d/functions as the init function libraries, Ubuntu uses /lib/lsb/init-functions.
The two init function libraries do not export the same functions, hence using the Red5 script in Ubuntu triggers these errors to appear, because Ubuntu doesn’t have the functions that are being used in the script.

In order to resolve these errors you can use the following Red5 init Script for Ubuntu:
This script uses Ubuntu init function libraries.

#!/bin/bash
# For RedHat and cousins:
# chkconfig: 2345 85 85
# description: Red5 flash streaming server
# processname: red5
# Created By: Sohail Riaz (sohaileo@gmail.com)

PROG=red5
RED5_HOME=/usr/share/red5
DAEMON=$RED5_HOME/$PROG.sh
PIDFILE=/var/run/$PROG.pid

# Source function library
. /lib/lsb/init-functions

[ -r /etc/sysconfig/red5 ] && . /etc/sysconfig/red5

RETVAL=0

case "$1" in
        start)
        log_daemon_msg $"Starting $PROG: "
        cd $RED5_HOME
        $DAEMON >/dev/null 2>/dev/null &
        RETVAL=$?
        if [ $RETVAL -eq 0 ]; then
                echo $! > $PIDFILE
                touch /var/lock/subsys/$PROG
        fi
        sleep 3
        [ $RETVAL -eq 0 ] && $0 status
        echo
        ;;
        stop)
        log_daemon_msg $"Shutting down $PROG: "
        killproc -p $PIDFILE
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$PROG
        ;;
        restart)
        $0 stop
        $0 start
        ;;
        status)
        pidofproc -p $PIDFILE $PROG
        RETVAL=$?
        if [ $RETVAL -eq 0 ]; then
                log_daemon_msg $"$PROG is running"
        else
                log_daemon_msg $"$PROG is not running"
        fi
        RETVAL=$?
        ;;
        *)
        echo $"Usage: $0 {start|stop|restart|status}"
        RETVAL=1
esac

exit $RETVAL

Leave a Reply

Your email address will not be published. Required fields are marked *