Bulk update to deployment
[dcaegen2/deployments.git] / archive / cloud_init / instconsulagentub16.sh
1 #!/bin/bash
2 # ============LICENSE_START====================================================
3 # org.onap.dcae
4 # =============================================================================
5 # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
6 # =============================================================================
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #      http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 # ============LICENSE_END======================================================
19
20 CONSULVER=0.8.3
21 CONSULNAME=consul_${CONSULVER}_linux_amd64
22 CB=/opt/consul/bin
23 CD=/opt/consul/data
24 CF=/opt/consul/config
25 mkdir -p $CB $CD $CF
26 cat >$CF/consul.json
27 cd $CB
28 wget https://releases.hashicorp.com/consul/${CONSULVER}/${CONSULNAME}.zip
29 unzip ${CONSULNAME}.zip
30 rm ${CONSULNAME}.zip
31 mv consul ${CONSULNAME}
32 ln -s ${CONSULNAME} consul
33 cat <<EOF > /lib/systemd/system/consul.service
34 [Unit]
35 Description=Consul
36 Requires=network-online.target
37 After=network.target
38 [Service]
39 Type=simple
40 ExecStart=/opt/consul/bin/consul agent -config-dir=/opt/consul/config
41 ExecReload=/bin/kill -HUP \$MAINPID
42 [Install]
43 WantedBy=multi-user.target
44 EOF
45 systemctl enable consul
46 systemctl start consul
47 until /opt/consul/bin/consul join "dcae-cnsl"
48 do
49   echo Waiting to join Consul cluster
50   sleep 60
51 done