reconfDocker.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. # Copyright 2015 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # reconfigure docker network setting
  16. source "$HOME/kube/${KUBE_CONFIG_FILE##*/}"
  17. if [[ "$(id -u)" != "0" ]]; then
  18. echo >&2 "Please run as root"
  19. exit 1
  20. fi
  21. function config_etcd {
  22. attempt=0
  23. while true; do
  24. /opt/bin/etcdctl get /coreos.com/network/config
  25. if [[ "$?" == 0 ]]; then
  26. break
  27. else
  28. # enough timeout??
  29. if (( attempt > 600 )); then
  30. echo "timeout waiting for /coreos.com/network/config" >> ~/kube/err.log
  31. exit 2
  32. fi
  33. /opt/bin/etcdctl mk /coreos.com/network/config "{\"Network\":\"${FLANNEL_NET}\", \"Backend\": {\"Type\": \"vxlan\"}${FLANNEL_OTHER_NET_CONFIG}}"
  34. attempt=$((attempt+1))
  35. sleep 3
  36. fi
  37. done
  38. }
  39. function restart_docker {
  40. attempt=0
  41. while [[ ! -f /run/flannel/subnet.env ]]; do
  42. if (( attempt > 200 )); then
  43. echo "timeout waiting for /run/flannel/subnet.env" >> ~/kube/err.log
  44. exit 2
  45. fi
  46. attempt=$((attempt+1))
  47. sleep 3
  48. done
  49. sudo ip link set dev docker0 down
  50. sudo brctl delbr docker0
  51. source /run/flannel/subnet.env
  52. source /etc/default/docker
  53. echo DOCKER_OPTS=\"${DOCKER_OPTS} -H tcp://127.0.0.1:4243 -H unix:///var/run/docker.sock \
  54. --bip=${FLANNEL_SUBNET} --mtu=${FLANNEL_MTU}\" > /etc/default/docker
  55. sudo service docker restart
  56. }
  57. if [[ $1 == "i" ]]; then
  58. restart_docker
  59. elif [[ $1 == "ai" ]]; then
  60. config_etcd
  61. restart_docker
  62. elif [[ $1 == "a" ]]; then
  63. config_etcd
  64. else
  65. echo "Another argument is required."
  66. exit 1
  67. fi