tvheadend.init 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/sh /etc/rc.common
  2. START=99
  3. STOP=00
  4. USE_PROCD=1
  5. PROG=/usr/bin/tvheadend
  6. TEMP_CONFIG=/tmp/tvheadend
  7. PERSISTENT_CONFIG=/etc/tvheadend
  8. execute_first_run() {
  9. "$PROG" -c "$1" -B -C -A >/dev/null 2>&1
  10. }
  11. ensure_config_exists() {
  12. local config_path
  13. config_load tvheadend
  14. config_get config_path service config_path
  15. if [ -z "$config_path" ]; then
  16. [ -d "$PERSISTENT_CONFIG" ] || execute_first_run "$PERSISTENT_CONFIG"
  17. else
  18. # if the configuration directory is empty, empty config with grant-all ACL is created
  19. [ -d "$config_path" ] && [ "$(ls -A $config_path)" ] || execute_first_run "$config_path"
  20. fi
  21. # if use_temp_epgdb is enabled (default), most of the config is put to config_path
  22. # (or /etc/config), except for epgdb.v2, which grows quite large and is write-heavy,
  23. # so it's put into volatile tmpfs
  24. # epgdb.v2 is created and symlinked to main config dir upon each start (if it doesn't exist)
  25. config_get_bool use_temp_epgdb service use_temp_epgdb 1
  26. if [ "$use_temp_epgdb" == "1" ]; then
  27. TEMP_EPG="${TEMP_CONFIG}/epgdb.v2"
  28. [ ! -f "$TEMP_EPG" ] && mkdir -p "$TEMP_CONFIG" && touch "$TEMP_EPG" && chmod 700 "$TEMP_EPG"
  29. [ -z "$config_path" ] && config_path="$PERSISTENT_CONFIG"
  30. ln -sf "$TEMP_EPG" "${config_path}/epgdb.v2"
  31. fi
  32. }
  33. load_uci_config() {
  34. config_load tvheadend
  35. config_get config_path service config_path "$PERSISTENT_CONFIG"
  36. [ -n "$config_path" ] && procd_append_param command -c "$config_path"
  37. config_get_bool nosyslog service nosyslog 0
  38. [ "$nosyslog" -eq 1 ] && procd_append_param command --nosyslog
  39. config_get_bool ipv6 server ipv6 0
  40. [ "$ipv6" -eq 1 ] && procd_append_param command --ipv6
  41. config_get bindaddr server bindaddr
  42. [ -n "$bindaddr" ] && procd_append_param command --bindaddr "$bindaddr"
  43. config_get http_port server http_port
  44. [ -n "$http_port" ] && procd_append_param command --http_port "$http_port"
  45. config_get http_root server http_root
  46. [ -n "$http_root" ] && procd_append_param command --http_root "$http_root"
  47. config_get htsp_port server htsp_port
  48. [ -n "$htsp_port" ] && procd_append_param command --htsp_port "$htsp_port"
  49. config_get htsp_port2 server htsp_port2
  50. [ -n "$htsp_port2" ] && procd_append_param command --htsp_port "$htsp_port2"
  51. config_get xspf server xspf 0
  52. [ "$xspf" -eq 1 ] && procd_append_param command --xspf
  53. }
  54. start_service() {
  55. ensure_config_exists
  56. procd_open_instance
  57. procd_set_param file /etc/config/tvheadend
  58. procd_set_param command "$PROG" -B
  59. load_uci_config
  60. procd_close_instance
  61. }