aboutsummaryrefslogtreecommitdiffstats
path: root/www/red5/files/red5.in
blob: 2d2c6209ba90e8d6af5d5119d808f2cb7eae4c8b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/sh
#
# $FreeBSD$
#

# PROVIDE: red5
# REQUIRE: NETWORKING SERVERS
# BEFORE: DAEMON
# KEYWORD: shutdown

#
# Configuration settings for red5 in /etc/rc.conf:
#
# red5_enable (bool):
#   Set to "NO" by default.
#   Set it to "YES" to enable red5
#
# red5_home (str)
#   Set to "%%RED5_HOME%%" by default.
#   Set the directory red5 will be executed
#
# red5_stdout_log (str)
#   Set to %%RED5_HOME%%/log/red5.log" by default.
#   Set the location for the Tomcat process log (standard output)
#
# red5_stderr_log (str)
#   Set to "%%RED5_HOME%%/log/red5.err" by default.
#   Set the location for the Tomcat process log (error output)
#
# red5_java_opts (str):
#   Set to "" by default.
#   Java VM args to use.
#   Eg: red5_java_opts="-Xrs -Xms512M -Xmx1024M -Xss128K -XX:NewSize=256m -XX:SurvivorRatio=16 \
#           -XX:MinHeapFreeRatio=20 -XX:+AggressiveHeap -XX:+ExplicitGCInvokesConcurrent \
#           -XX:+UseConcMarkSweepGC -Dsun.rmi.dgc.client.gcInterval=990000 \
#           -Dsun.rmi.dgc.server.gcInterval=990000 
#           -Djava.net.preferIPv4Stack=true -Xverify:none"
#
# red5_user (str)
#   Set to %%RED5_USER%% by default.
#   Set the user that will execute the server.
#  
# red5_connection_token (str)
#   Set to "" by default.
#   Set the "port username pass" which will be used to shutdown the server
#   Eg: "9999 red5user s3cr3t"
#

. /etc/rc.subr

name="red5"
rcvar=`set_rcvar`
pidfile="/var/run/red5.pid"
java_command="%%LOCALBASE%%/bin/java"

#constant options
red5_logging_opts="-Dlogback.ContextSelector=org.red5.logging.LoggingContextSelector \
            -Dcatalina.useNaming=true"
red5_security_opts="-Djava.security.debug=failure"
red5_mainclass="org.red5.server.Bootstrap"
red5_stop_mainclass="org.red5.server.Shutdown"
red5_jython_opt="-Dpython.home=lib"
red5_debug_opts="-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"

load_rc_config "${name}"

#configurable options
red5_enable="${red5_enable:-"NO"}"
red5_user="${red5_user:-"%%RED5_USER%%"}"
red5_home="${red5_home:-"%%RED5_HOME%%"}"
red5_stdout_log="${red5_stdout_log:-"%%RED5_HOME%%/log/red5.log"}"
red5_stderr_log="${red5_stderr_log:-"%%RED5_HOME%%/log/red5.err"}"
red5_stop_timeout="${red5_stop_timeout:-"10"}"


red5_opts="${red5_logging_opts} ${red5_security_opts} ${red5_java_opts}"
red5_stop_opts="-Djavax.net.ssl.keyStore=${red5_home}/conf/keystore.jmx \
        -Djavax.net.ssl.keyStorePassword=password"
red5_classpath="${red5_home}/boot.jar:${red5_home}/conf:${CLASSPATH}"

red5_start_cmd="${java_command} ${red5_jython_opt} -Dred5.root=${red5_home} \
        ${red5_opts} -cp ${red5_classpath} ${red5_mainclass}"

red5_stop_cmd="${java_command} ${red5_jython_opt} -Dred5.root=${red5_home} \
        ${red5_logging_opts} ${red5_security_opts} ${red5_stop_opts} \
        -cp ${red5_classpath} ${red5_stop_mainclass}"

red5_debug_cmd="${java_command} ${red5_jython_opt} -Dred5.root=${red5_home} \
        ${red5_opts} ${red5_debug_opts} -cp ${red5_classpath} ${red5_mainclass}"

log_args=">> ${red5_stdout_log} \
    2>> ${red5_stderr_log} "


command="/usr/sbin/daemon"
flags="-p ${pidfile} ${red5_start_cmd} ${log_args}"

start_precmd="red5_pre_start"
stop_cmd="red5_stop"
status_cmd="red5_status"
poll_cmd="red5_poll"
extra_commands="debug"
debug_cmd="red5_debug"

red5_pre_start() {
    export RED5_HOME=${red5_home}
    touch $pidfile
    chown $red5_user $pidfile
    cd ${red5_home} || exit 1
}

red5_debug() {
    ${red5_debug_cmd}
}

red5_stop() {
    rc_pid=$(red5_check_pidfile $pidfile)

    if [ -z "$rc_pid" ]; then
        [ -n "$rc_fast" ] && return 0
        echo "${name} not running? (check $pidfile)."
        return 1
    fi
    
    echo "Stopping ${name}."
    if [ ${red5_connection_token} ]; then
        ${red5_stop_cmd}
    fi
    red5_wait_max_for_pid ${red5_stop_timeout} ${rc_pid}
    kill -KILL ${rc_pid} 2> /dev/null && echo "Killed."
    rm -f ${pidfile}
}

red5_status() {
    rc_pid=$(red5_check_pidfile $pidfile)

    if [ -z "$rc_pid" ]; then
        [ -n "$rc_fast" ] && return 0
        echo "${name} not running? (check $pidfile)."
        return 1
    fi
    echo "${name} is running has pid $rc_pid."
}

red5_poll() {
    echo -n "Waiting for pid: $(cat $pidfile)"
    while (true) ; do
        rc_pid=$(red5_check_pidfile $pidfile)
        [ -z "$rc_pid" ] && break
        sleep 2
    done
    echo -e "\tdone\n"
}


red5_check_pidfile() {
    _pidfile=$1
    if [ -z "$_pidfile" ]; then
        err 3 'USAGE: red5_check_pidfile pidfile'
    fi
    if [ ! -f $_pidfile ]; then
        debug "pid file ($_pidfile): not readable."
        return
    fi
    read _pid _junk < $_pidfile
    if [ -z "$_pid" ]; then
        debug "pid file ($_pidfile): no pid in file."
        return
    fi
    if [ -n "`%%LOCALBASE%%/bin/jps -l | grep -e "^$_pid $red5_mainclass\$"`" ]; then
        echo -n $_pid
    fi
}

red5_wait_max_for_pid() {
    _timeout=$1
    shift
    _pid=$1
    _prefix=
    while [ $_timeout -gt 0 ] ; do
        echo -n ${_prefix:-"Waiting (max $_timeout secs) for PIDS: "}$_pid
        _prefix=", "
        sleep 2
        kill -0 $_pid 2> /dev/null || break
        _timeout=$(($_timeout-2))
    done
    if [ -n "$_prefix" ]; then
        echo "."
    fi
}

run_rc_command "$1"