You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
2.9 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2006-2011 OpenWrt.org
  3. . ${IPKG_INSTROOT}/lib/functions.sh
  4. START=50
  5. STOP=10
  6. USE_PROCD=1
  7. PROG="/usr/sbin/xinetd"
  8. PIDFILE="/var/run/xinetd.pid"
  9. CONF_FILE="/etc/config/xinetd"
  10. GENERATED_CONF_FILE="/var/run/xinetd.conf"
  11. OTHER_CONF_DIR="/tmp/xinetd.d"
  12. ServiceEntry="false"
  13. ListName=""
  14. ListValue=""
  15. # redefined callback for sections when calling config_load
  16. config_cb() {
  17. # write out last list option (from last section) if exist and clear
  18. if [ "$ListName" != "" ]; then
  19. echo -e "\t$ListName = $ListVals" >> $GENERATED_CONF_FILE
  20. fi
  21. ListName=""
  22. ListVals=""
  23. # "close" last service entry (from last section) if exist
  24. if [ "$ServiceEntry" = "true" ]; then # at least one service section "opened"
  25. echo "}" >> $GENERATED_CONF_FILE # "close" open service section in config
  26. ServiceEntry="false"
  27. fi
  28. if [ $# -eq 0 ]; then # end of config reached
  29. return
  30. fi
  31. local type="$1"
  32. local name="$2"
  33. if [ "$type" = "service" ]; then
  34. if [ "$ServiceEntry" = "true" ]; then
  35. echo "}" >> $GENERATED_CONF_FILE # "close" previous opened service section in config
  36. fi
  37. ServiceEntry="true"
  38. echo "" >> $GENERATED_CONF_FILE
  39. echo "service $name" >> $GENERATED_CONF_FILE
  40. echo "{" >> $GENERATED_CONF_FILE
  41. # redefined callback for options when calling config_load
  42. option_cb() {
  43. local option="$1"
  44. local value="$2"
  45. [ -n "$value" ] && echo -e "\t$option = $value" >> $GENERATED_CONF_FILE
  46. }
  47. # redefined callback for lists when calling config_load
  48. list_cb() {
  49. local name="$1"
  50. local value="$2"
  51. # write out last list option if new list starts
  52. if [ "$ListName" != "" -a "$ListName" != "$name" ]; then
  53. echo -e "\t$ListName = $ListVals" >> $GENERATED_CONF_FILE
  54. ListName=""
  55. ListVals=""
  56. fi
  57. # new list option
  58. if [ -z "$ListName" ]; then
  59. ListName="$name"
  60. ListVals="$value"
  61. else
  62. ListVals="$ListVals $value"
  63. fi
  64. }
  65. else # ignore non 'service' sections
  66. return 0
  67. fi
  68. }
  69. generate_config() {
  70. echo "# Auto-generated config file from $CONF_FILE" > $GENERATED_CONF_FILE
  71. echo "# Do not edit, changes to this file will be lost on upgrades" >> $GENERATED_CONF_FILE
  72. echo "" >> $GENERATED_CONF_FILE
  73. echo "defaults" >> $GENERATED_CONF_FILE
  74. echo "{" >> $GENERATED_CONF_FILE
  75. echo "" >> $GENERATED_CONF_FILE
  76. echo "}" >> $GENERATED_CONF_FILE
  77. echo "" >> $GENERATED_CONF_FILE
  78. echo "includedir /etc/xinetd.d" >> $GENERATED_CONF_FILE
  79. echo "includedir $OTHER_CONF_DIR" >> $GENERATED_CONF_FILE
  80. config_load xinetd
  81. }
  82. start_service() {
  83. mkdir -p $OTHER_CONF_DIR
  84. generate_config
  85. procd_open_instance
  86. procd_set_param command $PROG -dontfork -f $GENERATED_CONF_FILE -pidfile $PIDFILE
  87. procd_set_param respawn
  88. procd_close_instance
  89. }
  90. reload_service() {
  91. procd_running xinetd "instance1" && {
  92. procd_send_signal xinetd "*" QUIT
  93. start
  94. }
  95. }
  96. service_triggers() {
  97. procd_add_reload_trigger "xinetd"
  98. }