System for quickly installing an OpenStack cloud from upstream git for testing and development.
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.

etcd3 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/bin/bash
  2. #
  3. # lib/etcd3
  4. #
  5. # Functions to control the installation and configuration of etcd 3.x
  6. # that provides a key-value store (and possibly other functions).
  7. # Dependencies:
  8. #
  9. # - ``functions`` file
  10. # ``stack.sh`` calls the entry points in this order:
  11. #
  12. # - start_etcd3
  13. # - stop_etcd3
  14. # - cleanup_etcd3
  15. # Save trace setting
  16. _XTRACE_ETCD3=$(set +o | grep xtrace)
  17. set +o xtrace
  18. # Defaults
  19. # --------
  20. # Set up default values for etcd
  21. ETCD_DATA_DIR="$DATA_DIR/etcd"
  22. ETCD_SYSTEMD_SERVICE="devstack@etcd.service"
  23. ETCD_BIN_DIR="$DEST/bin"
  24. # Option below will mount ETCD_DATA_DIR as ramdisk, which is useful to run
  25. # etcd-heavy services in the gate VM's, e.g. Kubernetes.
  26. ETCD_USE_RAMDISK=$(trueorfalse True ETCD_USE_RAMDISK)
  27. ETCD_RAMDISK_MB=${ETCD_RAMDISK_MB:-512}
  28. if is_ubuntu ; then
  29. UBUNTU_RELEASE_BASE_NUM=`lsb_release -r | awk '{print $2}' | cut -d '.' -f 1`
  30. fi
  31. # start_etcd3() - Starts to run the etcd process
  32. function start_etcd3 {
  33. local cmd="$ETCD_BIN_DIR/etcd"
  34. cmd+=" --name $HOSTNAME --data-dir $ETCD_DATA_DIR"
  35. cmd+=" --initial-cluster-state new --initial-cluster-token etcd-cluster-01"
  36. cmd+=" --initial-cluster $HOSTNAME=http://$SERVICE_HOST:$ETCD_PEER_PORT"
  37. cmd+=" --initial-advertise-peer-urls http://$SERVICE_HOST:$ETCD_PEER_PORT"
  38. cmd+=" --advertise-client-urls http://$SERVICE_HOST:$ETCD_PORT"
  39. if [ "$SERVICE_LISTEN_ADDRESS" == "::" ]; then
  40. cmd+=" --listen-peer-urls http://[::]:$ETCD_PEER_PORT "
  41. else
  42. cmd+=" --listen-peer-urls http://0.0.0.0:$ETCD_PEER_PORT "
  43. fi
  44. cmd+=" --listen-client-urls http://$SERVICE_HOST:$ETCD_PORT"
  45. if [ "$ENABLE_DEBUG_LOG_LEVEL" == "True" ]; then
  46. cmd+=" --debug"
  47. fi
  48. local unitfile="$SYSTEMD_DIR/$ETCD_SYSTEMD_SERVICE"
  49. write_user_unit_file $ETCD_SYSTEMD_SERVICE "$cmd" "" "root"
  50. iniset -sudo $unitfile "Unit" "After" "network.target"
  51. iniset -sudo $unitfile "Service" "Type" "notify"
  52. iniset -sudo $unitfile "Service" "Restart" "on-failure"
  53. iniset -sudo $unitfile "Service" "LimitNOFILE" "65536"
  54. if is_arch "aarch64"; then
  55. iniset -sudo $unitfile "Service" "Environment" "ETCD_UNSUPPORTED_ARCH=arm64"
  56. fi
  57. $SYSTEMCTL daemon-reload
  58. $SYSTEMCTL enable $ETCD_SYSTEMD_SERVICE
  59. $SYSTEMCTL start $ETCD_SYSTEMD_SERVICE
  60. }
  61. # stop_etcd3() stops the etcd3 process
  62. function stop_etcd3 {
  63. # Don't install in sub nodes (multinode scenario)
  64. if [ "$SERVICE_HOST" != "$HOST_IP" ]; then
  65. return
  66. fi
  67. $SYSTEMCTL stop $ETCD_SYSTEMD_SERVICE
  68. }
  69. function cleanup_etcd3 {
  70. # Don't install in sub nodes (multinode scenario)
  71. if [ "$SERVICE_HOST" != "$HOST_IP" ]; then
  72. return
  73. fi
  74. $SYSTEMCTL disable $ETCD_SYSTEMD_SERVICE
  75. local unitfile="$SYSTEMD_DIR/$ETCD_SYSTEMD_SERVICE"
  76. sudo rm -f $unitfile
  77. $SYSTEMCTL daemon-reload
  78. if [[ "$ETCD_USE_RAMDISK" == "True" ]]; then
  79. sudo umount $ETCD_DATA_DIR
  80. fi
  81. sudo rm -rf $ETCD_DATA_DIR
  82. }
  83. function install_etcd3 {
  84. echo "Installing etcd"
  85. # Create the necessary directories
  86. sudo mkdir -p $ETCD_BIN_DIR
  87. sudo mkdir -p $ETCD_DATA_DIR
  88. if [[ "$ETCD_USE_RAMDISK" == "True" ]]; then
  89. sudo mount -t tmpfs -o nodev,nosuid,size=${ETCD_RAMDISK_MB}M tmpfs $ETCD_DATA_DIR
  90. fi
  91. # Download and cache the etcd tgz for subsequent use
  92. local etcd_file
  93. etcd_file="$(get_extra_file $ETCD_DOWNLOAD_LOCATION)"
  94. if [ ! -f "$FILES/etcd-$ETCD_VERSION-linux-$ETCD_ARCH/etcd" ]; then
  95. echo "${ETCD_SHA256} $etcd_file" > $FILES/etcd.sha256sum
  96. # NOTE(yuanke wei): rm the damaged file when checksum fails
  97. sha256sum -c $FILES/etcd.sha256sum || (sudo rm -f $etcd_file; exit 1)
  98. tar xzvf $etcd_file -C $FILES
  99. sudo cp $FILES/$ETCD_NAME/etcd $ETCD_BIN_DIR/etcd
  100. sudo cp $FILES/$ETCD_NAME/etcdctl $ETCD_BIN_DIR/etcdctl
  101. fi
  102. if [ ! -f "$ETCD_BIN_DIR/etcd" ]; then
  103. sudo cp $FILES/$ETCD_NAME/etcd $ETCD_BIN_DIR/etcd
  104. sudo cp $FILES/$ETCD_NAME/etcdctl $ETCD_BIN_DIR/etcdctl
  105. fi
  106. }
  107. # Restore xtrace
  108. $_XTRACE_ETCD3
  109. # Tell emacs to use shell-script-mode
  110. ## Local variables:
  111. ## mode: shell-script
  112. ## End: