forked from mikenomitch/quick-nomad-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nomad.sh.tpl
121 lines (94 loc) · 2.55 KB
/
nomad.sh.tpl
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
PRIVATE_IP=$(curl http://169.254.169.254/latest/meta-data/local-ipv4)
PUBLIC_IP=$(curl http://169.254.169.254/latest/meta-data/public-ipv4)
echo "=== Fetching Nomad ==="
cd /tmp
curl -sLo nomad.zip https://releases.hashicorp.com/nomad/${nomad_version}/nomad_${nomad_version}_linux_amd64.zip
echo "=== Installing Nomad ==="
unzip nomad.zip >/dev/null
sudo chmod +x nomad
sudo mv nomad /usr/local/bin/nomad
sudo mkdir -p /mnt/nomad
sudo mkdir -p /etc/nomad.d
if [ ${is_server} == true ] || [ ${is_server} == 1 ]; then
echo "=== Setting up Nomad as Server ==="
echo "=== Writing Server Config ==="
sudo tee /etc/nomad.d/config.hcl > /dev/null <<EOF
datacenter = "${datacenter}"
region = "${region}"
data_dir = "/mnt/nomad"
bind_addr = "0.0.0.0"
server {
enabled = true,
bootstrap_expect = ${desired_servers}
server_join {
retry_join = [ "provider=aws tag_key=${retry_tag_key} tag_value=${retry_tag_value}" ]
}
default_scheduler_config {
memory_oversubscription_enabled = true
preemption_config {
batch_scheduler_enabled = true
system_scheduler_enabled = true
service_scheduler_enabled = true
}
}
}
acl {
enabled = true
}
advertise {
http = "$PUBLIC_IP"
rpc = "$PUBLIC_IP"
serf = "$PUBLIC_IP"
}
telemetry {
publish_allocation_metrics = true
publish_node_metrics = true
prometheus_metrics = true
}
EOF
else
echo "=== Setting up Nomad as Client ==="
sudo mkdir -p /opt/nomad/plugins
sudo mkdir -p /opt/cni/bin
# sudo mkdir -p /tmp/cni
# curl https://github.com/containernetworking/plugins/releases/download/v1.0.1/cni-plugins-linux-amd64-v1.0.1.tgz --output /tmp/cni/cni-plugins-linux-amd64-v1.0.1.tgz
# tar -xf /tmp/cni/cni-plugins-linux-amd64-v1.0.1.tgz -C /tmp/cni
# mv "/tmp/cni/*" "/opt/cni/bin"
# tar -xf /tmp/cni-plugin
echo "=== Writing Client Config ==="
sudo tee /etc/nomad.d/config.hcl > /dev/null <<EOF
datacenter = "${datacenter}"
region = "${region}"
data_dir = "/mnt/nomad"
plugin_dir = "/opt/nomad/plugins"
bind_addr = "0.0.0.0"
client {
enabled = true
server_join {
retry_join = [ "provider=aws tag_key=${retry_tag_key} tag_value=${retry_tag_value}" ]
}
}
acl {
enabled = true
}
plugin "raw_exec" {
enabled = true
}
plugin "docker" {
config {
allow_privileged = true
volumes {
enabled = true
}
}
}
telemetry {
publish_allocation_metrics = true
publish_node_metrics = true
prometheus_metrics = true
}
EOF
fi
sudo tee /etc/systemd/system/nomad.service > /dev/null <<"EOF"
${nomad_service_config}
EOF