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.

102 lines
2.2 KiB

  1. #!/bin/sh /etc/rc.common
  2. USE_PROCD=1
  3. START=25
  4. DOCKERD_CONF="/tmp/dockerd/daemon.json"
  5. json_add_array_string() {
  6. json_add_string "" "$1"
  7. }
  8. process_config() {
  9. local alt_config_file data_root log_level
  10. rm -f "$DOCKERD_CONF"
  11. [ -f /etc/config/dockerd ] || {
  12. # Use the daemon default configuration
  13. DOCKERD_CONF=""
  14. return 0
  15. }
  16. config_load 'dockerd'
  17. config_get alt_config_file globals alt_config_file
  18. [ -n "$alt_config_file" ] && [ -f "$alt_config_file" ] && {
  19. ln -s "$alt_config_file" "$DOCKERD_CONF"
  20. return 0
  21. }
  22. config_get data_root globals data_root "/opt/docker/"
  23. config_get log_level globals log_level "warn"
  24. . /usr/share/libubox/jshn.sh
  25. json_init
  26. json_add_string "data-root" "$data_root"
  27. json_add_string "log-level" "$log_level"
  28. json_add_array "registry-mirrors"
  29. config_list_foreach globals registry_mirror json_add_array_string
  30. json_close_array
  31. mkdir -p /tmp/dockerd
  32. json_dump > "$DOCKERD_CONF"
  33. }
  34. start_service() {
  35. local nofile=$(cat /proc/sys/fs/nr_open)
  36. process_config
  37. procd_open_instance
  38. procd_set_param stderr 1
  39. if [ -z "$DOCKERD_CONF" ]; then
  40. procd_set_param command /usr/bin/dockerd
  41. else
  42. procd_set_param command /usr/bin/dockerd --config-file="$DOCKERD_CONF"
  43. fi
  44. procd_set_param limits nofile="${nofile} ${nofile}"
  45. procd_close_instance
  46. }
  47. reload_service() {
  48. process_config
  49. procd_send_signal dockerd
  50. }
  51. service_triggers() {
  52. procd_add_reload_trigger 'dockerd'
  53. }
  54. ip4tables_remove_nat() {
  55. iptables -t nat -D OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
  56. iptables -t nat -D PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
  57. iptables -t nat -F DOCKER
  58. iptables -t nat -X DOCKER
  59. }
  60. ip4tables_remove_filter() {
  61. iptables -t filter -D FORWARD -j DOCKER-USER
  62. iptables -t filter -D FORWARD -j DOCKER-ISOLATION-STAGE-1
  63. iptables -t filter -D FORWARD -o docker0 -j DOCKER
  64. iptables -t filter -F DOCKER
  65. iptables -t filter -F DOCKER-ISOLATION-STAGE-1
  66. iptables -t filter -F DOCKER-ISOLATION-STAGE-2
  67. iptables -t filter -F DOCKER-USER
  68. iptables -t filter -X DOCKER
  69. iptables -t filter -X DOCKER-ISOLATION-STAGE-1
  70. iptables -t filter -X DOCKER-ISOLATION-STAGE-2
  71. iptables -t filter -X DOCKER-USER
  72. }
  73. ip4tables_remove() {
  74. ip4tables_remove_nat
  75. ip4tables_remove_filter
  76. }
  77. stop_service() {
  78. ip4tables_remove
  79. }