-
Notifications
You must be signed in to change notification settings - Fork 292
Expand file tree
/
Copy pathstart-api.sh
More file actions
executable file
·72 lines (57 loc) · 2.35 KB
/
start-api.sh
File metadata and controls
executable file
·72 lines (57 loc) · 2.35 KB
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
#!/usr/bin/env bash
# This script is meant to be run in the User Data of each EC2 Instance while it's booting. The script uses the
# run-nomad and run-consul scripts to configure and start Nomad and Consul in client mode. Note that this script
# assumes it's running in an AMI built from the Packer template in examples/nomad-consul-ami/nomad-consul.json.
set -euo pipefail
# Set timestamp format
PS4='[\D{%Y-%m-%d %H:%M:%S}] '
# Enable command tracing
set -x
# Send the log output from this script to user-data.log, syslog, and the console
# Inspired by https://alestic.com/2010/12/ec2-user-data-output/
exec > >(tee /var/log/user-data.log | logger -t user-data -s 2>/dev/console) 2>&1
ulimit -n 1048576
export GOMAXPROCS=$(nproc)
sudo tee -a /etc/sysctl.conf <<EOF
# Increase the maximum number of socket connections
net.core.somaxconn = 65535
# Increase the maximum number of backlogged connections
net.core.netdev_max_backlog = 65535
# Increase maximum number of TCP sockets
net.ipv4.tcp_max_syn_backlog = 65535
EOF
sudo sysctl -p
# These variables are passed in via Terraform template interpolation
gsutil cp "gs://${SCRIPTS_BUCKET}/run-consul-${RUN_CONSUL_FILE_HASH}.sh" /opt/consul/bin/run-consul.sh
gsutil cp "gs://${SCRIPTS_BUCKET}/run-nomad-${RUN_NOMAD_FILE_HASH}.sh" /opt/nomad/bin/run-nomad.sh
chmod +x /opt/consul/bin/run-consul.sh /opt/nomad/bin/run-nomad.sh
mkdir -p /root/docker
touch /root/docker/config.json
cat <<EOF >/root/docker/config.json
{
"auths": {
"${GCP_REGION}-docker.pkg.dev": {
"username": "_json_key_base64",
"password": "${GOOGLE_SERVICE_ACCOUNT_KEY}",
"server_address": "https://${GCP_REGION}-docker.pkg.dev"
}
}
}
EOF
mkdir -p /etc/systemd/resolved.conf.d/
touch /etc/systemd/resolved.conf.d/consul.conf
cat <<EOF >/etc/systemd/resolved.conf.d/consul.conf
[Resolve]
DNS=127.0.0.1:8600
DNSSEC=false
Domains=~consul
EOF
systemctl restart systemd-resolved
# These variables are passed in via Terraform template interpolation
/opt/consul/bin/run-consul.sh --client \
--consul-token "${CONSUL_TOKEN}" \
--cluster-tag-name "${CLUSTER_TAG_NAME}" \
--enable-gossip-encryption \
--gossip-encryption-key "${CONSUL_GOSSIP_ENCRYPTION_KEY}" \
--dns-request-token "${CONSUL_DNS_REQUEST_TOKEN}" &
/opt/nomad/bin/run-nomad.sh --client --consul-token "${CONSUL_TOKEN}" --node-pool "${NODE_POOL}" &