updated on Sun Jan 15 08:01:04 UTC 2012
[aur-mirror.git] / red5-dev / red5.redhat.sh
blob4ce558f4f9c1eda345636c5ac4c0ac4ef9aba7e8
1 #!/bin/bash
3 # red5: Red5 Server
5 # chkconfig: 2345 70 30
6 # description: Open-Source Flash Server
7 # config: /etc/sysconfig/red5
9 . /etc/init.d/functions
11 [ -f /etc/sysconfig/red5 ] && . /etc/sysconfig/red5
13 [ -z "$RED5_HOME" ] && RED5_HOME=/opt/red5
14 [ ! -d "$RED5_HOME" ] && exit -1
15 [ ! -d "$RED5_CONF_DIR" ] && RED5_CONF_DIR="$RED5_HOME/conf"
16 [ ! -d "$RED5_WORK_DIR" ] && RED5_WORK_DIR="$RED5_HOME/work"
17 [ ! -d "$RED5_LOG_DIR" ] && RED5_LOG_DIR="$RED5_HOME/log"
18 [ -z "$RED5_OUT" ] && RED5_OUT=/dev/null
19 [ ! -d "$STARTUP_DIR" ] && STARTUP_DIR="$RED5_HOME"
21 RED5_CLASSPATH="$RED5_HOME/boot.jar:$RED5_CONF_DIR"
22 export RED5_HOME
24 case "$1" in
25 run)
26 [ -f "$RED5_PID" ] && $0 stop
27 echo -n 'Starting Red5: '
28 cd "$STARTUP_DIR"
29 RED5_OPTS="$LOGGING_OPTS $SECURITY_OPTS -Dpython.home=lib -Dred5.root=$RED5_HOME -Dred5.config_root=$RED5_CONF_DIR"
30 RED5_MAINCLASS='org.red5.server.Bootstrap'
31 if [ ! -z "$RED5_USER" -a "$USER" != "$RED5_USER" ]; then
32 su $RED5_USER -c "exec $JAVA_HOME/bin/java $JAVA_OPTS \
33 $RED5_OPTS -cp $RED5_CLASSPATH $RED5_MAINCLASS \
34 >> $RED5_OUT 2>&1" &
35 for i in $(seq 5); do
36 pid=$(ps -o ppid,pid -U $RED5_USER | awk "{if(\$1==$!)print\$2}")
37 [ -n "$pid" ] && break
38 sleep $i
39 done
40 else
41 $JAVA_HOME/bin/java $JAVA_OPTS \
42 $RED5_OPTS -cp $RED5_CLASSPATH $RED5_MAINCLASS \
43 >> $RED5_OUT 2>&1 &
44 pid=$!
46 if [ -z "$pid" -o ! -e "/proc/$pid" ]; then
47 failure; echo
48 exit
49 else
50 [ ! -z "$RED5_PID" ] && echo $pid > $RED5_PID
51 touch /var/lock/subsys/red5 && success || failure; echo
53 [ "$!" != "$pid" ] && exec kill -9 $! &> /dev/null
55 start)
56 rm -rf $RED5_WORK_DIR/red5*
57 : > $RED5_OUT
58 rm -f $RED5_LOG_DIR/*
59 $0 run
61 stop)
62 echo -n 'Stopping Red5: '
63 cd "$STARTUP_DIR"
64 RED5_MAINCLASS='org.red5.server.Shutdown'
65 if [ ! -z "$RED5_USER" -a "$USER" != "$RED5_USER" ]; then
66 su $RED5_USER -c "exec $JAVA_HOME/bin/java $JAVA_OPTS $JMX_OPTS \
67 $RED5_OPTS -cp $RED5_CLASSPATH $RED5_MAINCLASS $SHUTDOWN_OPTS \
68 >> $RED5_OUT 2>&1" &
69 else
70 $JAVA_HOME/bin/java $JAVA_OPTS $JMX_OPTS \
71 $RED5_OPTS -cp $RED5_CLASSPATH $RED5_MAINCLASS $SHUTDOWN_OPTS \
72 >> $RED5_OUT 2>&1 &
74 for i in $(seq 5); do
75 [ -e "/proc/$!" ] || break
76 sleep $i
77 done
78 [ -e "/proc/$!" ] && kill $! 2> /dev/null && \
79 sleep 1 && kill -9 $! 2> /dev/null
80 [ -f "$RED5_PID" ] && pid=$(<$RED5_PID) && kill $pid 2> /dev/null && \
81 sleep 1 && kill -9 $pid 2> /dev/null && sleep 1
82 if [ -z "$pid" -o $? -eq 0 -a -e "/proc/$pid" ]; then
83 failure; echo
84 exit
85 else
86 rm -f $RED5_PID
87 rm -f /var/lock/subsys/red5 && success || failure; echo
90 restart)
91 $0 stop && $0 start
93 reload)
94 $0 stop && $0 run
96 status)
99 echo "Usage: $0 {start|stop|restart|reload}" >&2
100 exit 1
101 esac