1
0

chronyd.init 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2006-2015 OpenWrt.org
  3. START=15
  4. USE_PROCD=1
  5. PROG=/usr/sbin/chronyd
  6. CONFIGFILE=/var/etc/chrony.conf
  7. INCLUDEFILE=/etc/chrony/chrony.conf
  8. handle_source() {
  9. local cfg=$1 sourcetype=$2 hostname minpoll maxpoll iburst
  10. hostname=$NTP_SOURCE_HOSTNAME
  11. [ -z "$hostname" ] && config_get hostname "$cfg" hostname
  12. [ -z "$hostname" ] && return
  13. config_get minpoll "$cfg" minpoll
  14. config_get maxpoll "$cfg" maxpoll
  15. config_get_bool iburst "$cfg" iburst 0
  16. echo $(
  17. echo $sourcetype $hostname
  18. [ -n "$minpoll" ] && echo minpoll $minpoll
  19. [ -n "$maxpoll" ] && echo maxpoll $maxpoll
  20. [ "$iburst" = "1" ] && echo iburst
  21. )
  22. }
  23. handle_allow() {
  24. local cfg=$1 iface wan_iface wan6_iface subnet subnets subnets6
  25. network_find_wan wan_iface true
  26. network_find_wan6 wan6_iface true
  27. config_get iface "$cfg" interface
  28. if [ "$wan_iface" = "$iface" ]; then
  29. echo allow 0/0
  30. elif [ "$wan6_iface" = "$iface" ]; then
  31. echo allow ::/0
  32. else
  33. network_get_subnets subnets $iface || \
  34. network_get_subnets subnets6 $iface || continue
  35. for subnet in $subnets $subnets6; do
  36. echo allow $subnet
  37. done
  38. fi
  39. }
  40. handle_makestep() {
  41. local cfg=$1 threshold limit
  42. config_get threshold "$cfg" threshold
  43. config_get limit "$cfg" limit
  44. [ -z "$threshold" -o -z "$limit" ] && return
  45. echo makestep $threshold $limit
  46. }
  47. start_service() {
  48. . /lib/functions/network.sh
  49. procd_open_instance
  50. procd_set_param command $PROG -n -f $CONFIGFILE
  51. procd_set_param file $CONFIGFILE
  52. procd_set_param file $INCLUDEFILE
  53. procd_close_instance
  54. config_load chrony
  55. mkdir -p $(dirname $CONFIGFILE)
  56. (
  57. echo include $INCLUDEFILE
  58. config_foreach handle_source server server
  59. config_foreach handle_source pool pool
  60. config_foreach handle_source peer peer
  61. config_foreach handle_allow allow
  62. config_foreach handle_makestep makestep
  63. ) > $CONFIGFILE
  64. }