#! /bin/sh # $1 contains the path to the configuration file. It is passed in the systemd unit file # When calling the rtpengine command # It should be /etc/default/rtpengine-conf DEFAULTS=$1 # 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 set -e # Gradually fill the options of the command rtpengine which starts the RTPEngine daemon # The variables used are sourced from the configuration file rtpengine-conf OPTIONS="" if [ ! -z "$INTERFACES" ]; then for interface in $INTERFACES; do OPTIONS="$OPTIONS --interface=$interface" done fi if [ ! -z "$TABLE" ]; then echo "TABLE=$TABLE" > /etc/default/rtpengine-table 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" 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 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 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 RTP/media proxy: ngcp-rtpengine-daemon" 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 fi rtpengine $OPTIONS exit 0