ETCD_DOWNLOAD_URL is set to github url, in our CI, we can point
ETCD_DOWNLOAD_URL to a url in tarballs.openstack.org possibly
in devstack-gate
Download the etcd binaries and drop them into /opt/stack/bin and
use it from there. Cache the tgz for subsequent use (local workflow)
daemon-reload is called twice once from inside the write_user_unit_file
and then when we adjust the entries with additional things recommended
by the etcd team. We need a better way to do this in the future.
Added a TODO to verify the downloaded artifact later. The etcd team
posts gpg signature, we could verify that or run sha256sum and hard
code that in lib/etcd3 file. We would have to update it whenever we
bump the etcd3 version.
We use the public key "CoreOS Application Signing Key <security@coreos.com>"
with ID FC8A365E to verify the integrity of the downloaded file
Any jobs that need to be run on architectures where v3.1.7 is not available
should rey the v3.2.0-rcX release candidates. We can switch to v3.2.0
when it gets released.
Initial version of this code was borrowed from the dragonflow
repo:
http://git.openstack.org/cgit/openstack/dragonflow/tree/devstack
Change-Id: Ibbb430fb1dbf66942168e0cb52d990ab6a2eb8d7
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,126 @@ |
0 |
+#!/bin/bash |
|
1 |
+# |
|
2 |
+# lib/etcd3 |
|
3 |
+# |
|
4 |
+# Functions to control the installation and configuration of etcd 3.x |
|
5 |
+# that provides a key-value store (and possibly other functions). |
|
6 |
+ |
|
7 |
+# Dependencies: |
|
8 |
+# |
|
9 |
+# - ``functions`` file |
|
10 |
+ |
|
11 |
+# ``stack.sh`` calls the entry points in this order: |
|
12 |
+# |
|
13 |
+# - start_etcd3 |
|
14 |
+# - stop_etcd3 |
|
15 |
+# - cleanup_etcd3 |
|
16 |
+ |
|
17 |
+# Save trace setting |
|
18 |
+_XTRACE_ETCD3=$(set +o | grep xtrace) |
|
19 |
+set +o xtrace |
|
20 |
+ |
|
21 |
+ |
|
22 |
+# Defaults |
|
23 |
+# -------- |
|
24 |
+ |
|
25 |
+# Set up default values for etcd |
|
26 |
+ETCD_DOWNLOAD_URL=${ETCD_DOWNLOAD_URL:-https://github.com/coreos/etcd/releases/download} |
|
27 |
+ETCD_VERSION=${ETCD_VERSION:-v3.1.7} |
|
28 |
+ETCD_DATA_DIR="$DEST/data/etcd" |
|
29 |
+ETCD_SYSTEMD_SERVICE="devstack@etcd.service" |
|
30 |
+ETCD_BIN_DIR="$DEST/bin" |
|
31 |
+ |
|
32 |
+if is_ubuntu ; then |
|
33 |
+ UBUNTU_RELEASE_BASE_NUM=`lsb_release -r | awk '{print $2}' | cut -d '.' -f 1` |
|
34 |
+fi |
|
35 |
+ |
|
36 |
+# start_etcd3() - Starts to run the etcd process |
|
37 |
+function start_etcd3 { |
|
38 |
+ _install_etcd |
|
39 |
+ |
|
40 |
+ local cmd="$ETCD_BIN_DIR/etcd" |
|
41 |
+ cmd+=" --name $HOSTNAME --data-dir $ETCD_DATA_DIR" |
|
42 |
+ cmd+=" --initial-cluster-state new --initial-cluster-token etcd-cluster-01" |
|
43 |
+ cmd+=" --initial-cluster $HOSTNAME=http://$SERVICE_HOST:2380" |
|
44 |
+ cmd+=" --initial-advertise-peer-urls http://$SERVICE_HOST:2380" |
|
45 |
+ cmd+=" --advertise-client-urls http://$SERVICE_HOST:2379" |
|
46 |
+ cmd+=" --listen-peer-urls http://0.0.0.0:2380 " |
|
47 |
+ cmd+=" --listen-client-urls http://$SERVICE_HOST:2379" |
|
48 |
+ |
|
49 |
+ local unitfile="$SYSTEMD_DIR/$ETCD_SYSTEMD_SERVICE" |
|
50 |
+ write_user_unit_file $ETCD_SYSTEMD_SERVICE "$cmd" "" "root" |
|
51 |
+ |
|
52 |
+ iniset -sudo $unitfile "Unit" "After" "network.target" |
|
53 |
+ iniset -sudo $unitfile "Service" "Type" "notify" |
|
54 |
+ iniset -sudo $unitfile "Service" "Restart" "on-failure" |
|
55 |
+ iniset -sudo $unitfile "Service" "LimitNOFILE" "65536" |
|
56 |
+ |
|
57 |
+ $SYSTEMCTL daemon-reload |
|
58 |
+ $SYSTEMCTL enable $ETCD_SYSTEMD_SERVICE |
|
59 |
+ $SYSTEMCTL start $ETCD_SYSTEMD_SERVICE |
|
60 |
+} |
|
61 |
+ |
|
62 |
+# stop_etcd3() stops the etcd3 process |
|
63 |
+function stop_etcd3 { |
|
64 |
+ $SYSTEMCTL stop $ETCD_SYSTEMD_SERVICE |
|
65 |
+} |
|
66 |
+ |
|
67 |
+function cleanup_etcd { |
|
68 |
+ $SYSTEMCTL disable $ETCD_SYSTEMD_SERVICE |
|
69 |
+ |
|
70 |
+ local unitfile="$SYSTEMD_DIR/$ETCD_SYSTEMD_SERVICE" |
|
71 |
+ sudo rm -f $unitfile |
|
72 |
+ |
|
73 |
+ $SYSTEMCTL daemon-reload |
|
74 |
+ |
|
75 |
+ sudo rm -rf $ETCD_DATA_DIR |
|
76 |
+} |
|
77 |
+ |
|
78 |
+function _install_etcd { |
|
79 |
+ echo "Installing etcd" |
|
80 |
+ |
|
81 |
+ # Make sure etcd3 downloads the correct architecture |
|
82 |
+ if is_arch "x86_64"; then |
|
83 |
+ ETCD_ARCH="amd64" |
|
84 |
+ elif is_arch "aarch64"; then |
|
85 |
+ ETCD_ARCH="arm64" |
|
86 |
+ elif is_arch "ppc64le"; then |
|
87 |
+ ETCD_ARCH="ppc64le" |
|
88 |
+ else |
|
89 |
+ exit_distro_not_supported "invalid hardware type - $ETCD_ARCH" |
|
90 |
+ fi |
|
91 |
+ |
|
92 |
+ # Install the libraries needed. Note: tooz for example does not have a hard dependency on these libraries |
|
93 |
+ pip_install etcd3 |
|
94 |
+ pip_install etcd3gw |
|
95 |
+ |
|
96 |
+ # Create the necessary directories |
|
97 |
+ sudo mkdir -p $ETCD_BIN_DIR |
|
98 |
+ sudo mkdir -p $ETCD_DATA_DIR |
|
99 |
+ |
|
100 |
+ # Download and cache the etcd tgz for subsequent use |
|
101 |
+ if [ ! -f "$DEST/etcd/etcd-$ETCD_VERSION-linux-$ETCD_ARCH/etcd" ]; then |
|
102 |
+ mkdir -p $DEST/etcd |
|
103 |
+ ETCD_DOWNLOAD_FILE=etcd-$ETCD_VERSION-linux-$ETCD_ARCH.tar.gz |
|
104 |
+ wget $ETCD_DOWNLOAD_URL/$ETCD_VERSION/$ETCD_DOWNLOAD_FILE -O $DEST/etcd/$ETCD_DOWNLOAD_FILE |
|
105 |
+ wget $ETCD_DOWNLOAD_URL/$ETCD_VERSION/$ETCD_DOWNLOAD_FILE.asc -O $DEST/etcd/$ETCD_DOWNLOAD_FILE.asc |
|
106 |
+ |
|
107 |
+ # use gpg to verify the artifact, use a backup key server in case the first one is down for some reason |
|
108 |
+ gpg --keyserver hkps.pool.sks-keyservers.net --recv-key FC8A365E || gpg --keyserver pgpkeys.mit.edu --recv-key FC8A365E |
|
109 |
+ gpg --verify $DEST/etcd/$ETCD_DOWNLOAD_FILE.asc $DEST/etcd/$ETCD_DOWNLOAD_FILE |
|
110 |
+ |
|
111 |
+ tar xzvf $DEST/etcd/$ETCD_DOWNLOAD_FILE -C $DEST/etcd |
|
112 |
+ sudo cp $DEST/etcd/etcd-$ETCD_VERSION-linux-$ETCD_ARCH/etcd $ETCD_BIN_DIR/etcd |
|
113 |
+ fi |
|
114 |
+ if [ ! -f "$ETCD_BIN_DIR/etcd" ]; then |
|
115 |
+ sudo cp $DEST/etcd/etcd-$ETCD_VERSION-linux-$ETCD_ARCH/etcd $ETCD_BIN_DIR/etcd |
|
116 |
+ fi |
|
117 |
+} |
|
118 |
+ |
|
119 |
+# Restore xtrace |
|
120 |
+$_XTRACE_ETCD3 |
|
121 |
+ |
|
122 |
+# Tell emacs to use shell-script-mode |
|
123 |
+## Local variables: |
|
124 |
+## mode: shell-script |
|
125 |
+## End: |
... | ... |
@@ -574,6 +574,7 @@ source $TOP_DIR/lib/neutron |
574 | 574 |
source $TOP_DIR/lib/ldap |
575 | 575 |
source $TOP_DIR/lib/dstat |
576 | 576 |
source $TOP_DIR/lib/dlm |
577 |
+source $TOP_DIR/lib/etcd3 |
|
577 | 578 |
source $TOP_DIR/lib/os_brick |
578 | 579 |
|
579 | 580 |
# Extras Source |
... | ... |
@@ -1043,6 +1044,11 @@ fi |
1043 | 1043 |
# A better kind of sysstat, with the top process per time slice |
1044 | 1044 |
start_dstat |
1045 | 1045 |
|
1046 |
+# Etcd |
|
1047 |
+# ----- |
|
1048 |
+ |
|
1049 |
+# etcd is a distributed key value store that provides a reliable way to store data across a cluster of machines |
|
1050 |
+start_etcd3 |
|
1046 | 1051 |
|
1047 | 1052 |
# Keystone |
1048 | 1053 |
# -------- |
... | ... |
@@ -65,7 +65,7 @@ if ! isset ENABLED_SERVICES ; then |
65 | 65 |
# Dashboard |
66 | 66 |
ENABLED_SERVICES+=,horizon |
67 | 67 |
# Additional services |
68 |
- ENABLED_SERVICES+=,rabbit,tempest,mysql,dstat |
|
68 |
+ ENABLED_SERVICES+=,rabbit,tempest,mysql,etcd3,dstat |
|
69 | 69 |
fi |
70 | 70 |
|
71 | 71 |
# Global toggle for enabling services under mod_wsgi. If this is set to |
... | ... |
@@ -69,6 +69,7 @@ source $TOP_DIR/lib/swift |
69 | 69 |
source $TOP_DIR/lib/neutron |
70 | 70 |
source $TOP_DIR/lib/ldap |
71 | 71 |
source $TOP_DIR/lib/dstat |
72 |
+source $TOP_DIR/lib/etcd3 |
|
72 | 73 |
source $TOP_DIR/lib/dlm |
73 | 74 |
|
74 | 75 |
# Extras Source |
... | ... |
@@ -162,6 +163,11 @@ if is_service_enabled neutron; then |
162 | 162 |
cleanup_neutron |
163 | 163 |
fi |
164 | 164 |
|
165 |
+if is_service_enabled etcd3; then |
|
166 |
+ stop_etcd3 |
|
167 |
+ cleanup_etcd3 |
|
168 |
+fi |
|
169 |
+ |
|
165 | 170 |
if is_service_enabled dstat; then |
166 | 171 |
stop_dstat |
167 | 172 |
fi |