mptsd reads mpegts streams from udp/multicast or http and combines them into one multiple program stream that is suitable for outputting to DVB-C modulator. Tested with Dektec DTE-3114 Quad QAM Modulator and used in production in small DVB-C networks. https://georgi.unixsol.org/programs/mptsd/

rc.mptsd 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #!/bin/sh
  2. # mptsd server control script
  3. # Copyright (C) 2007-2011 Unix Solutions Ltd.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License version 2
  7. # as published by the Free Software Foundation.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  17. #
  18. PATH="/home/iptv:/bin:/sbin:/usr/bin:/usr/local/bin"
  19. export PATH
  20. cd $(dirname $0)
  21. CONFIG="$(basename $0).conf"
  22. if [ ! -r $CONFIG ]
  23. then
  24. echo "[ERROR] $CONFIG is not found."
  25. exit 1
  26. fi
  27. . ./$CONFIG
  28. istart() {
  29. echo "[START] Starting $PRGNAME."
  30. if [ ! -f "$SERVER" -o ! -x "$SERVER" ]
  31. then
  32. echo "[ERROR] $SERVER does not exist or it's not executable."
  33. exit 1
  34. fi
  35. if [ -r "$PIDFILE" ]
  36. then
  37. fpid=$(cat "$PIDFILE" 2>/dev/null)
  38. rpid=$(pidof $PRGNAME 2>/dev/null)
  39. if [ -n "$rpid" -a "0$fpid" -eq "0$rpid" ]
  40. then
  41. echo "[ERROR] $PRGNAME is already running: (pid $rpid)"
  42. exit 1
  43. else
  44. echo "[ERROR] $PIDFILE is stale, $PRGNAME is not running. Deleting it pid file."
  45. rm $PIDFILE
  46. fi
  47. fi
  48. echo "[CMD ] $SERVER $PARAMS"
  49. cd $(dirname $SERVER)
  50. $SERVER $PARAMS
  51. if [ $? -eq 0 ]
  52. then
  53. echo "[OK ] $PRGNAME started."
  54. else
  55. echo "[ERROR] $PRGNAME not started."
  56. fi
  57. }
  58. istop() {
  59. echo "[STOP ] Stopping $PRGNAME."
  60. killall $PRGNAME
  61. if [ $? -eq 0 ]
  62. then
  63. echo -n "[WAIT ] Waiting"
  64. echo -n "." && sleep .3
  65. echo -n "." && sleep .3
  66. echo -n "." && sleep .3
  67. echo -n "." && sleep .2
  68. echo "."
  69. if [ -r "$PIDFILE" ]
  70. then
  71. RPID=$(pidof $PRGNAME 2>/dev/null)
  72. if [ "0$RPID" -ne "0" ]
  73. then
  74. echo "[ERROR] $PRGNAME is still running: (pid $(cat $PIDFILE)). Kill -9ing it."
  75. killall -9 $PRGNAME
  76. fi
  77. fi
  78. echo "[OK ] $PRGNAME is stopped."
  79. fi
  80. }
  81. icheck() {
  82. if [ -r "$PIDFILE" ]
  83. then
  84. fpid=$(cat "$PIDFILE" 2>/dev/null)
  85. rpid=$(pidof $PRGNAME 2>/dev/null)
  86. if [ -n "$rpid" -a "0$fpid" -eq "0$rpid" ]
  87. then
  88. echo "[CHECK] $PRGNAME is already running: (pid $rpid)"
  89. else
  90. istart
  91. fi
  92. else
  93. echo "[CHECK] Stop and start"
  94. istop
  95. istart
  96. fi
  97. }
  98. istatus() {
  99. rpid=$(pidof $PRGNAME 2>/dev/null)
  100. echo "[STATUS] $PRGNAME pidfile pid: $(cat $PIDFILE 2>/dev/null)"
  101. echo "[STATUS] $PRGNAME pidof pid: $rpid"
  102. if [ -z "$rpid" ]
  103. then
  104. echo "[STATUS] $PRGNAME is not running."
  105. else
  106. if [ -n "$rpid" -a "0$(cat $PIDFILE 2>/dev/null)" -eq "0$rpid" ]
  107. then
  108. echo "[STATUS] $PRGNAME is running"
  109. else
  110. echo "[STATUS] $PRGNAME is running but no pid file exist: $PIDFILE"
  111. fi
  112. ps ax | grep "$PRGNAME -i" | grep -v grep
  113. fi
  114. }
  115. ireconnect() {
  116. echo "[RECONN] Sending SIGUSR1 to $PRGNAME causing reconnect"
  117. kill -USR1 $(pidof $PRGNAME)
  118. }
  119. ireload() {
  120. echo "[RECONN] Sending SIGHUP to $PRGNAME causing configuration reload"
  121. kill -HUP $(pidof $PRGNAME)
  122. }
  123. case "$1" in
  124. 'start')
  125. if [ "$2" != "" ]
  126. then
  127. sleep "$2"
  128. fi
  129. istart
  130. ;;
  131. 'stop')
  132. istop
  133. ;;
  134. 'check')
  135. icheck
  136. ;;
  137. 'status')
  138. istatus
  139. ;;
  140. 'restart')
  141. istop
  142. istart
  143. ;;
  144. 'reload')
  145. ireload
  146. ;;
  147. 'reconnect')
  148. ireconnect
  149. ;;
  150. *)
  151. echo "Usage: `basename $0` start|stop|check|restart|reload|reconnect|status"
  152. esac