summaryrefslogtreecommitdiffstats
path: root/azure/aria/aria-extension-cloudify/src/aria/examples/clearwater/scripts/host/configure.sh
blob: 61cb8350e48b74b6991b9f17c5494b2557167ae0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e

HOSTNAME=$(ctx node capabilities host properties hostname)

# Change hostname
OLD_HOSTNAME=$(hostname)
if [ "$OLD_HOSTNAME" != "$HOSTNAME" ]; then
	hostname "$HOSTNAME"
	echo "$HOSTNAME" > /etc/hostname
	sed --in-place --expression "s/127.0.1.1\s\+$OLD_HOSTNAME/127.0.1.1 $HOSTNAME/" /etc/hosts
fi

ZONE=$(ctx service get_policy_by_type [ clearwater.Configuration ] properties zone)
GEOGRAPHICALLY_REDUNDANT=$(ctx service get_policy_by_type [ clearwater.Configuration ] properties geographically_redundant)
SITE_NAME=$(ctx service get_policy_by_type [ clearwater.Configuration ] properties site_name)
SECRET=$(ctx service get_policy_by_type [ clearwater.Configuration ] properties secret)

SMTP_HOSTNAME=$(ctx service get_node_by_type [ clearwater.Ellis ] get_outbound_relationship_by_name [ smtp ] target_node properties address)
SMTP_USERNAME=$(ctx service get_node_by_type [ clearwater.Ellis ] get_outbound_relationship_by_name [ smtp ] target_node capabilities smtp properties username)
SMTP_PASSWORD=$(ctx service get_node_by_type [ clearwater.Ellis ] get_outbound_relationship_by_name [ smtp ] target_node capabilities smtp properties password)

MAX_LOG_DIRECTORY_SIZE=$(ctx node capabilities host properties max_log_directory_size value)
REDUCE_CASSANDRA_MEM_USAGE=$(ctx node capabilities host properties reduce_cassandra_mem_usage)

PRIVATE_IP=$(ctx node attributes private_address)
PUBLIC_IP=$(ctx node attributes public_address)
PUBLIC_HOSTNAME=$(hostname)
# TODO: comma-separated list of all private IP addresses in group
ETCD_CLUSTER=$PRIVATE_IP

REPO_FILE=/etc/apt/sources.list.d/clearwater.list
REPO_LINE='deb http://repo.cw-ngv.com/stable binary/'
KEY_URL=http://repo.cw-ngv.com/repo_key


#
# Repository
#

if [ ! -f "$REPO_FILE" ]; then
	echo "$REPO_LINE" > "$REPO_FILE"
	curl --location "$KEY_URL" | apt-key add -
fi

apt update

if ! type aptdcon > /dev/null; then
	# This will allow us to do concurrent installs
	apt install aptdaemon --yes
fi

yes | aptdcon --hide-terminal --install clearwater-management


#
# DNS
#

S_CSCF_HOST="$PRIVATE_IP scscf.$PUBLIC_HOSTNAME # ARIA"
grep --quiet --fixed-strings "$S_CSCF_HOST" /etc/hosts || echo "$S_CSCF_HOST" >> /etc/hosts


#
# Local configuration
#

mkdir --parents /etc/clearwater
CONFIG_FILE=/etc/clearwater/local_config
echo "# Created by ARIA on $(date -u)" > "$CONFIG_FILE"

echo >> "$CONFIG_FILE"
echo "# Local IP configuration" >> "$CONFIG_FILE"
echo "local_ip=$PRIVATE_IP" >> "$CONFIG_FILE"
echo "public_ip=$PUBLIC_IP" >> "$CONFIG_FILE"
echo "public_hostname=$PUBLIC_HOSTNAME" >> "$CONFIG_FILE"
echo "etcd_cluster=$ETCD_CLUSTER" >> "$CONFIG_FILE"

if [ "$MAX_LOG_DIRECTORY_SIZE" != 0 ]; then
	echo >> "$CONFIG_FILE"
	echo "max_log_directory_size=$MAX_LOG_DIRECTORY_SIZE" >> "$CONFIG_FILE"
fi

if [ "$GEOGRAPHICALLY_REDUNDANT" = True ]; then
	echo >> "$CONFIG_FILE"
	echo "# Geographically redundant" >> "$CONFIG_FILE"
	echo "local_site_name=$SITE_NAME" >> "$CONFIG_FILE"

	# On the first Vellum node in the second site, you should set remote_cassandra_seeds to the
	# IP address of a Vellum node in the first site.
	#echo "remote_cassandra_seeds=" >> "$CONFIG_FILE"
fi


#
# Shared configuration
#

if [ "$GEOGRAPHICALLY_REDUNDANT" = True ]; then
	SPROUT_HOSTNAME=sprout.$SITE_NAME.$ZONE
	SPROUT_REGISTRATION_STORE=vellum.$SITE_NAME.$ZONE
	HS_HOSTNAME=hs.$SITE_NAME.$ZONE:8888
	HS_PROVISIONING_HOSTNAME=hs.$SITE_NAME.$ZONE:8889
	RALF_HOSTNAME=ralf.$SITE_NAME.$ZONE:10888
	RALF_SESSION_STORE=vellum.$ZONE
	XDMS_HOSTNAME=homer.$SITE_NAME.$ZONE:7888
	CHRONOS_HOSTNAME=vellum.$SITE_NAME.$ZONE
	CASSANDRA_HOSTNAME=vellum.$SITE_NAME.$ZONE
else
	VELLUM_IP=$PRIVATE_IP
	HOMESTEAD_IP=$PRIVATE_IP
	HOMER_IP=$PRIVATE_IP

	SPROUT_HOSTNAME=$PUBLIC_HOSTNAME
	SPROUT_REGISTRATION_STORE=$VELLUM_IP
	HS_HOSTNAME=$HOMESTEAD_IP:8888
	HS_PROVISIONING_HOSTNAME=$HOMESTEAD_IP:8889
	RALF_HOSTNAME=
	RALF_SESSION_STORE=
	XDMS_HOSTNAME=$HOMER_IP:7888
	CHRONOS_HOSTNAME=
	CASSANDRA_HOSTNAME=
fi

mkdir --parents /etc/clearwater
CONFIG_FILE=/etc/clearwater/shared_config
echo "# Created by ARIA on $(date -u)" > "$CONFIG_FILE"

echo >> "$CONFIG_FILE"
echo "# Deployment definitions" >> "$CONFIG_FILE"
echo "home_domain=$ZONE" >> "$CONFIG_FILE"
echo "sprout_hostname=$SPROUT_HOSTNAME" >> "$CONFIG_FILE"
echo "sprout_registration_store=$SPROUT_REGISTRATION_STORE" >> "$CONFIG_FILE"
echo "hs_hostname=$HS_HOSTNAME" >> "$CONFIG_FILE"
echo "hs_provisioning_hostname=$HS_PROVISIONING_HOSTNAME" >> "$CONFIG_FILE"
echo "ralf_hostname=$RALF_HOSTNAME" >> "$CONFIG_FILE"
echo "ralf_session_store=$RALF_SESSION_STORE" >> "$CONFIG_FILE"
echo "xdms_hostname=$XDMS_HOSTNAME" >> "$CONFIG_FILE"
echo "chronos_hostname=$CHRONOS_HOSTNAME" >> "$CONFIG_FILE"
echo "cassandra_hostname=$CASSANDRA_HOSTNAME" >> "$CONFIG_FILE"

echo >> "$CONFIG_FILE"
echo "# Email server configuration" >> "$CONFIG_FILE"
echo "smtp_smarthost=$SMTP_HOSTNAME" >> "$CONFIG_FILE"
echo "smtp_username=$SMTP_USERNAME" >> "$CONFIG_FILE"
echo "smtp_password=$SMTP_PASSWORD" >> "$CONFIG_FILE"
echo "email_recovery_sender=clearwater@$ZONE" >> "$CONFIG_FILE"

echo >> "$CONFIG_FILE"
echo "# I-CSCF/S-CSCF configuration (used by Bono to proxy to Sprout)" >> "$CONFIG_FILE"
echo "upstream_hostname=scscf.$HOSTNAME" >> "$CONFIG_FILE"

echo >> "$CONFIG_FILE"
echo "# Keys" >> "$CONFIG_FILE"
echo "signup_key=$SECRET" >> "$CONFIG_FILE"
echo "turn_workaround=$SECRET" >> "$CONFIG_FILE"
echo "ellis_api_key=$SECRET" >> "$CONFIG_FILE"
echo "ellis_cookie_key=$SECRET" >> "$CONFIG_FILE"

if [ "$REDUCE_CASSANDRA_MEM_USAGE" = True ]; then
	echo >> "$CONFIG_FILE"
	echo "# $REDUCE_CASSANDRA_MEM_USAGE" >> "$CONFIG_FILE"
	echo "reduce_cassandra_mem_usage=Y" >> "$CONFIG_FILE"
fi

# Copy to other hosts in etcd group
#yes | aptdcon --hide-terminal --install clearwater-config-manager
#cw-upload_shared_config