etcd2-join 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash -e
  2. # Copyright 2015 CoreOS, Inc.
  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. if [ $# -lt 3 ];then
  16. echo "USAGE: $0 <master_advertise_peer_urls> <target_name> <target_peer_url>"
  17. exit 1
  18. fi
  19. function convertDropin {
  20. sed -e 's/^Added.*$/[Service]/g' -e 's/="/=/g' -e 's/^ETCD_/Environment="ETCD_/g'
  21. }
  22. masterAdvUrl=$1
  23. targetName=$2
  24. targetUrl=$3
  25. cmd="etcdctl --peers ${masterAdvUrl} member add ${targetName} ${targetUrl}"
  26. ENV_VARS=`$cmd`
  27. echo "${ENV_VARS}" | convertDropin > 40-boostrap-cluster.conf
  28. sudo mv 40-boostrap-cluster.conf /var/run/systemd/system/etcd2.service.d/
  29. sudo systemctl daemon-reload
  30. sudo systemctl cat etcd2.service
  31. echo "You can now start etcd2"