Red5服务自启动

来源:互联网 发布:我是皇坐骑进阶数据 编辑:程序博客网 时间:2024/04/28 02:42

       曾经碰到许多人问关于red5的启动问题,其实它的svn上早有这样的一启动脚本:

       http://svn1.cvsdude.com/osflash/red5/redhat/trunk/red5.init

       但它是作为系统服务启动的,只能以root用户运行,个人觉得这样不是太安全。最后,干脆自己重新写这样一个脚本得了:

 

#! /bin/bash

 

# For RedHat and cousins:

# chkconfig: 2345 85 85

# description: Red5 flash streaming server

# processname: red5

 

PROG=red5

RED5_HOME=/opt/osflash/red5-0.6/ #把这里设置为你的red5根目录

DAEMON=$RED5_HOME/$PROG.sh

PIDFILE=$PROG.pid

 

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

 

RETVAL=0

 

# Source function library

. /etc/rc.d/init.d/functions

 

pid=""

getpid () {

       if [ -f $PIDFILE ]; then

           local line p

           read line < $PIDFILE

           for p in $line ; do

               [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"

           done

       fi           

       if [ -z "$pid" ]; then

           pid=`ps -aux|awk '/red5/.jar/{print $2}'`;

       fi

}

 

getprogress () {

       local counter=0

       while [ $counter -lt $1 ]; do

              sleep 1

              echo -n "."

              let counter+=1;

       done

}

 

case "$1" in

       start)

           echo -n $"Starting $PROG "

           cd $RED5_HOME

           getpid

           if [ -n "$pid" ]; then

               RETVAL=1;

               echo -n "red5 is already started"

           else

               $DAEMON >/dev/null 2>/dev/null &

              RETVAL=$?

               if [ $RETVAL -eq 0 ]; then

                   echo $! > $PIDFILE

                   touch /tmp/$PROG     

               fi

           fi

           [ $RETVAL -eq 0 ] && getprogress 10 && success $"$PROG startup" || failure $"$PROG startup"

           echo

           cd -

           ;;

       stop)

           echo -n $"Shutting down $PROG "

           cd $RED5_HOME

           getpid

           if [ -n "$pid" ]; then

               kill -TERM $pid

               RETVAL=$?

               rm -f /tmp/$PROG

              rm -f $PIDFILE

           else

              RETVAL=1

               fi

           [ $RETVAL -eq 0 ] &&  getprogress 5  && success $"$PROG stop" || failure $"$PROG stop"

           echo 

           cd -

           ;;

       restart)

           $0 stop

           $0 start

           ;;

       *)

           echo $"Usage: $0 {start|stop|restart}"

           RETVAL=1

esac

exit $RETVAL

 

把文件保存为red5.init,然后用root执行:

       cp red5.init /etc/rc.d/init.d/red5

       cd /etc/rc.d/init.d/red5

       chkconfig –add red5

 

OK,现在可以启动服务了:

/etc/init.d/red5 start

Starting red5 ..........                                   [  OK  ]

 

原创粉丝点击