#! /bin/sh ### BEGIN INIT INFO # Provides: ngcp-rtpengine-daemon # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Should-Start: sshd # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Ngcp Rtpengine # Description: Proxy for RTP and other media streams ### END INIT INFO PATH=/sbin:/bin:/usr/sbin:/usr/bin NAME=ngcp-rtpengine-daemon DESC="RTP/media proxy" TABLE=0 case $(dirname $0) in /*) FULLPATH=$(dirname $0);; *) FULLPATH=$(pwd)/$(dirname $0);; esac DAEMON=`which rtpengine` DEFAULTS=/etc/default/${NAME} test -f $DAEMON || exit 0 # Load startup options if available if [ -f $DEFAULTS ]; then . $DEFAULTS || true fi if [ "$RUN_RTPENGINE" != "yes" -a "$RUN_MEDIAPROXY" != "yes" ]; then echo "rtpengine not yet configured. Edit $DEFAULTS first." exit 0 fi [ -z "$PIDFILE" ] && PIDFILE="/var/run/rtpengine.pid" set -e . /lib/lsb/init-functions OPTIONS="" if [ ! -z "$INTERFACES" ]; then for interface in $INTERFACES; do OPTIONS="$OPTIONS --interface=$interface" done fi if [ ! -z "$SUBSCRIBE_KEYSPACES" ]; then for ks in $SUBSCRIBE_KEYSPACES; do OPTIONS="$OPTIONS --subscribe-keyspace=$ks" done fi [ -z "$ADDRESS" ] || OPTIONS="$OPTIONS --interface=$ADDRESS" [ -z "$ADV_ADDRESS" ] || OPTIONS="$OPTIONS!$ADV_ADDRESS" [ -z "$ADDRESS_IPV6" ] || OPTIONS="$OPTIONS --interface=$ADDRESS_IPV6" [ -z "$ADV_ADDRESS_IPV6" ] || OPTIONS="$OPTIONS!$ADV_ADDRESS_IPV6" [ -z "$LISTEN_TCP" ] || OPTIONS="$OPTIONS --listen-tcp=$LISTEN_TCP" [ -z "$LISTEN_UDP" ] || OPTIONS="$OPTIONS --listen-udp=$LISTEN_UDP" [ -z "$LISTEN_NG" ] || OPTIONS="$OPTIONS --listen-ng=$LISTEN_NG" [ -z "$LISTEN_CLI" ] || OPTIONS="$OPTIONS --listen-cli=$LISTEN_CLI" [ -z "$TIMEOUT" ] || OPTIONS="$OPTIONS --timeout=$TIMEOUT" [ -z "$SILENT_TIMEOUT" ] || OPTIONS="$OPTIONS --silent-timeout=$SILENT_TIMEOUT" [ -z "$FINAL_TIMEOUT" ] || OPTIONS="$OPTIONS --final-timeout=$FINAL_TIMEOUT" [ -z "$PIDFILE" ] || OPTIONS="$OPTIONS --pidfile=$PIDFILE" [ -z "$TOS" ] || OPTIONS="$OPTIONS --tos=$TOS" [ -z "$PORT_MIN" ] || OPTIONS="$OPTIONS --port-min=$PORT_MIN" [ -z "$PORT_MAX" ] || OPTIONS="$OPTIONS --port-max=$PORT_MAX" [ -z "$REDIS" -o -z "$REDIS_DB" ] || OPTIONS="$OPTIONS --redis=$REDIS/$REDIS_DB" [ -z "$REDIS_AUTH_PW" ] || export RTPENGINE_REDIS_AUTH_PW="$REDIS_AUTH_PW" [ -z "$REDIS_WRITE" -o -z "$REDIS_WRITE_DB" ] || OPTIONS="$OPTIONS --redis-write=$REDIS_WRITE/$REDIS_WRITE_DB" [ -z "$REDIS_WRITE_AUTH_PW" ] || export RTPENGINE_REDIS_WRITE_AUTH_PW="$REDIS_WRITE_AUTH_PW" [ -z "$REDIS_NUM_THREADS" ] || OPTIONS="$OPTIONS --redis-num-threads=$REDIS_NUM_THREADS" [ -z "$REDIS_EXPIRES" ] || OPTIONS="$OPTIONS --redis-expires=$REDIS_EXPIRES" [ -z "$NO_REDIS_REQUIRED" -o \( "$NO_REDIS_REQUIRED" != "1" -a "$NO_REDIS_REQUIRED" != "yes" \) ] || OPTIONS="$OPTIONS --no-redis-required" [ -z "$B2B_URL" ] || OPTIONS="$OPTIONS --b2b-url=$B2B_URL" [ -z "$NO_FALLBACK" -o \( "$NO_FALLBACK" != "1" -a "$NO_FALLBACK" != "yes" \) ] || OPTIONS="$OPTIONS --no-fallback" OPTIONS="$OPTIONS --table=$TABLE" [ -z "$LOG_LEVEL" ] || OPTIONS="$OPTIONS --log-level=$LOG_LEVEL" [ -z "$LOG_FACILITY" ] || OPTIONS="$OPTIONS --log-facility=$LOG_FACILITY" [ -z "$LOG_FACILITY_CDR" ] || OPTIONS="$OPTIONS --log-facility-cdr=$LOG_FACILITY_CDR" [ -z "$LOG_FACILITY_RTCP" ] || OPTIONS="$OPTIONS --log-facility-rtcp=$LOG_FACILITY_RTCP" [ -z "$NUM_THREADS" ] || OPTIONS="$OPTIONS --num-threads=$NUM_THREADS" [ -z "$DELETE_DELAY" ] || OPTIONS="$OPTIONS --delete-delay=$DELETE_DELAY" [ -z "$GRAPHITE" ] || OPTIONS="$OPTIONS --graphite=$GRAPHITE" [ -z "$GRAPHITE_INTERVAL" ] || OPTIONS="$OPTIONS --graphite-interval=$GRAPHITE_INTERVAL" [ -z "$GRAPHITE_PREFIX" ] || OPTIONS="$OPTIONS --graphite-prefix=$GRAPHITE_PREFIX" [ -z "$MAX_SESSIONS" ] || OPTIONS="$OPTIONS --max-sessions=$MAX_SESSIONS" [ -z "$HOMER" ] || OPTIONS="$OPTIONS --homer=$HOMER" [ -z "$HOMER_PROTOCOL" ] || OPTIONS="$OPTIONS --homer-protocol=$HOMER_PROTOCOL" [ -z "$HOMER_ID" ] || OPTIONS="$OPTIONS --homer-id=$HOMER_ID" [ -z "$RECORDING_DIR" ] || OPTIONS="$OPTIONS --recording-dir=$RECORDING_DIR" [ -z "$DTLS_PASSIVE" -o \( "$DTLS_PASSIVE" != "yes" -a "$DTLS_PASSIVE" != "1" \) ] || OPTIONS="$OPTIONS --dtls-passive" if test "$FORK" = "no" ; then OPTIONS="$OPTIONS --foreground" fi if test "$LOG_STDERR" = "yes" ; then OPTIONS="$OPTIONS --log-stderr" fi if [ -x /usr/sbin/ngcp-virt-identify ]; then if /usr/sbin/ngcp-virt-identify --type container; then VIRT="yes" fi fi case "$1" in start) set +e if [ -x "/usr/sbin/ngcp-check_active" ]; then /usr/sbin/ngcp-check_active -q status=$? case "${status}" in 0|3) echo "Active node or transition." ;; *) echo "Ignored start action in inactive node ($status)" exit 0 ;; esac fi echo -n "Starting $DESC: $NAME" if [ "$TABLE" -ge 0 ] && [ "$VIRT" != "yes" ]; then set +e modprobe xt_RTPENGINE if [ -e /proc/mediaproxy/control ]; then echo "del $TABLE" > /proc/mediaproxy/control 2>/dev/null fi if [ -e /proc/rtpengine/control ]; then echo "del $TABLE" > /proc/rtpengine/control 2>/dev/null fi iptables -D INPUT -j mediaproxy 2> /dev/null iptables -F mediaproxy 2> /dev/null iptables -X mediaproxy 2> /dev/null ip6tables -D INPUT -j mediaproxy 2> /dev/null ip6tables -F mediaproxy 2> /dev/null ip6tables -X mediaproxy 2> /dev/null rmmod xt_MEDIAPROXY 2>/dev/null if [ "$CREATE_IPTABLES_CHAIN" != "no" ]; then iptables -N rtpengine 2> /dev/null iptables -D INPUT -j rtpengine 2> /dev/null iptables -I INPUT -j rtpengine ip6tables -N rtpengine 2> /dev/null ip6tables -D INPUT -j rtpengine 2> /dev/null ip6tables -I INPUT -j rtpengine fi if iptables -C INPUT -j rtpengine 1> /dev/null 2> /dev/null && iptables -n --list rtpengine 1> /dev/null 2> /dev/null; then iptables -D rtpengine -p udp -j RTPENGINE --id "$TABLE" 2>/dev/null iptables -I rtpengine -p udp -j RTPENGINE --id "$TABLE" ip6tables -D rtpengine -p udp -j RTPENGINE --id "$TABLE" 2>/dev/null ip6tables -I rtpengine -p udp -j RTPENGINE --id "$TABLE" else echo "" echo "Missing rtpengine iptables chain - not starting" exit 0 fi set -e fi start-stop-daemon --start --quiet --pidfile $PIDFILE \ --exec $DAEMON -- $OPTIONS || echo -n " already running" log_end_msg $? ;; stop) echo -n "Stopping $DESC: $NAME" start-stop-daemon --oknodo --stop --quiet --pidfile $PIDFILE \ --exec $DAEMON if [ "$?" -ne 0 ]; then return $? fi if [ "$TABLE" -ge 0 ] && [ "$VIRT" != "yes" ]; then set +e if [ -e /proc/mediaproxy/control ]; then echo "del $TABLE" > /proc/mediaproxy/control 2>/dev/null fi if [ -e /proc/rtpengine/control ]; then echo "del $TABLE" > /proc/rtpengine/control 2>/dev/null fi iptables -D INPUT -j mediaproxy 2> /dev/null iptables -F mediaproxy 2> /dev/null iptables -X mediaproxy 2> /dev/null ip6tables -D INPUT -j mediaproxy 2> /dev/null ip6tables -F mediaproxy 2> /dev/null ip6tables -X mediaproxy 2> /dev/null iptables -D INPUT -j mediaproxy 2> /dev/null iptables -D rtpengine -p udp -j RTPENGINE --id "$TABLE" 2>/dev/null ip6tables -D INPUT -j mediaproxy 2> /dev/null ip6tables -D rtpengine -p udp -j RTPENGINE --id "$TABLE" 2>/dev/null rmmod xt_MEDIAPROXY 2>/dev/null rmmod xt_RTPENGINE 2>/dev/null set -e fi rm -f $PIDFILE log_end_msg $? ;; restart|force-reload) echo -n "Restarting $DESC: $NAME" start-stop-daemon --oknodo --stop --quiet --pidfile \ $PIDFILE --exec $DAEMON if [ "$?" -ne 0 ]; then return $? fi rm -f $PIDFILE if [ -x "/usr/sbin/ngcp-check_active" ]; then /usr/sbin/ngcp-check_active -q status=$? case "${status}" in 0|3) echo "Active node or transition." ;; *) echo "Ignored start action in inactive node ($status)" exit 0 ;; esac fi if [ "$TABLE" -ge 0 ] && [ "$VIRT" != "yes" ]; then sleep 1 set +e if [ -e /proc/mediaproxy/control ]; then echo "del $TABLE" > /proc/mediaproxy/control 2>/dev/null fi if [ -e /proc/rtpengine/control ]; then echo "del $TABLE" > /proc/rtpengine/control 2>/dev/null fi iptables -D INPUT -j mediaproxy 2> /dev/null iptables -F mediaproxy 2> /dev/null iptables -X mediaproxy 2> /dev/null ip6tables -D INPUT -j mediaproxy 2> /dev/null ip6tables -F mediaproxy 2> /dev/null ip6tables -X mediaproxy 2> /dev/null rmmod xt_MEDIAPROXY 2>/dev/null rmmod xt_RTPENGINE 2>/dev/null modprobe xt_RTPENGINE if [ "$CREATE_IPTABLES_CHAIN" != "no" ]; then iptables -D INPUT -j rtpengine 2> /dev/null ip6tables -D INPUT -j rtpengine 2> /dev/null iptables -N rtpengine 2> /dev/null iptables -I INPUT -j rtpengine ip6tables -N rtpengine 2> /dev/null ip6tables -I INPUT -j rtpengine fi if iptables -C INPUT -j rtpengine 1> /dev/null 2> /dev/null && iptables -n --list rtpengine 1> /dev/null 2> /dev/null; then ip6tables -D rtpengine -p udp -j RTPENGINE --id "$TABLE" 2>/dev/null iptables -D rtpengine -p udp -j RTPENGINE --id "$TABLE" 2>/dev/null iptables -I rtpengine -p udp -j RTPENGINE --id "$TABLE" ip6tables -I rtpengine -p udp -j RTPENGINE --id "$TABLE" else echo "" echo "Missing rtpengine iptables chain - not starting" exit 0 fi set -e fi start-stop-daemon --start --quiet --pidfile \ $PIDFILE --exec $DAEMON -- $OPTIONS log_end_msg $? ;; status) status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? ;; *) echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2 exit 1 ;; esac exit 0