updated on Thu Jan 12 08:01:00 UTC 2012
[aur-mirror.git] / red5 / red5.sh
blobaaa9647de0aff749121ecbacdf2ef247b2153dfb
1 #!/bin/bash
2 . /etc/rc.conf
3 . /etc/rc.d/functions
5 [ -z "$JAVA_HOME" -a -f /etc/profile.d/jdk.sh ] && . /etc/profile.d/jdk.sh
6 [ -f /etc/conf.d/red5 ] && . /etc/conf.d/red5
8 [ -z "$RED5_HOME" ] && RED5_HOME=/opt/red5
9 [ ! -d "$RED5_HOME" ] && exit -1
10 [ ! -d "$RED5_CONF_DIR" ] && RED5_CONF_DIR="$RED5_HOME/conf"
11 [ ! -d "$RED5_WORK_DIR" ] && RED5_WORK_DIR="$RED5_HOME/work"
12 [ ! -d "$RED5_LOG_DIR" ] && RED5_LOG_DIR="$RED5_HOME/log"
13 [ -z "$RED5_OUT" ] && RED5_OUT=/dev/null
14 [ ! -d "$STARTUP_DIR" ] && STARTUP_DIR="$RED5_HOME"
16 RED5_CLASSPATH="$RED5_HOME/boot.jar:$RED5_CONF_DIR"
17 export RED5_HOME
19 case "$1" in
20 run)
21 [ -f "$RED5_PID" ] && $0 stop
22 stat_busy 'Starting Red5'
23 cd "$STARTUP_DIR"
24 RED5_OPTS="$LOGGING_OPTS $SECURITY_OPTS -Dpython.home=lib -Dred5.root=$RED5_HOME -Dred5.config_root=$RED5_CONF_DIR"
25 RED5_MAINCLASS='org.red5.server.Bootstrap'
26 if [ ! -z "$RED5_USER" -a "$USER" != "$RED5_USER" ]; then
27 su $RED5_USER -c "exec $JAVA_HOME/bin/java $JAVA_OPTS \
28 $RED5_OPTS -cp $RED5_CLASSPATH $RED5_MAINCLASS \
29 >> $RED5_OUT 2>&1" &
30 for i in $(seq 5); do
31 pid=$(ps -o ppid,pid -U $RED5_USER | awk "{if(\$1==$!)print\$2}")
32 [ -n "$pid" ] && break
33 sleep $i
34 done
35 else
36 $JAVA_HOME/bin/java $JAVA_OPTS \
37 $RED5_OPTS -cp $RED5_CLASSPATH $RED5_MAINCLASS \
38 >> $RED5_OUT 2>&1 &
39 pid=$!
41 if [ -z "$pid" -o ! -e "/proc/$pid" ]; then
42 stat_fail
43 exit
44 else
45 [ ! -z "$RED5_PID" ] && echo $pid > $RED5_PID
46 add_daemon ${0##*/}
47 stat_done
49 [ "$!" != "$pid" ] && exec kill -9 $! &> /dev/null
51 start)
52 rm -rf $RED5_WORK_DIR/red5*
53 : > $RED5_OUT
54 rm -f $RED5_LOG_DIR/*
55 $0 run
57 stop)
58 stat_busy 'Stopping Red5'
59 cd "$STARTUP_DIR"
60 RED5_MAINCLASS='org.red5.server.Shutdown'
61 if [ ! -z "$RED5_USER" -a "$USER" != "$RED5_USER" ]; then
62 su $RED5_USER -c "exec $JAVA_HOME/bin/java $JAVA_OPTS $JMX_OPTS \
63 $RED5_OPTS -cp $RED5_CLASSPATH $RED5_MAINCLASS $SHUTDOWN_OPTS \
64 >> $RED5_OUT 2>&1" &
65 else
66 $JAVA_HOME/bin/java $JAVA_OPTS $JMX_OPTS \
67 $RED5_OPTS -cp $RED5_CLASSPATH $RED5_MAINCLASS $SHUTDOWN_OPTS \
68 >> $RED5_OUT 2>&1 &
70 for i in $(seq 5); do
71 [ -e "/proc/$!" ] || break
72 sleep $i
73 done
74 [ -e "/proc/$!" ] && kill $! 2> /dev/null && \
75 sleep 1 && kill -9 $! 2> /dev/null
76 [ -f "$RED5_PID" ] && pid=$(<$RED5_PID) && kill $pid 2> /dev/null && \
77 sleep 1 && kill -9 $pid 2> /dev/null && sleep 1
78 if [ -z "$pid" -o $? -eq 0 -a -e "/proc/$pid" ]; then
79 stat_fail
80 exit
81 else
82 rm -f $RED5_PID
83 rm_daemon ${0##*/}
84 stat_done
87 restart)
88 $0 stop && $0 start
90 reload)
91 $0 stop && $0 run
94 echo "Usage: $0 {start|stop|restart|reload}" >&2
95 exit 1
96 esac