-
Notifications
You must be signed in to change notification settings - Fork 0
/
user-data
173 lines (162 loc) · 5.23 KB
/
user-data
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
#cloud-config
---
coreos:
etcd:
# generate a new token for each unique cluster from https://discovery.etcd.io/new
# WARNING: replace each time you 'vagrant destroy'
#discovery: https://discovery.etcd.io/<token>
addr: $public_ipv4:4001
peer-addr: $public_ipv4:7001
etcd2:
# generate a new token for each unique cluster from https://discovery.etcd.io/new
# discovery: https://discovery.etcd.io/<token>
# multi-region and multi-cloud deployments need to use $public_ipv4
# advertise-client-urls: http://$public_ipv4:2379
initial-advertise-peer-urls: http://$private_ipv4:2380
# listen on both the official ports and the legacy ports
# legacy ports can be omitted if your application doesn't depend on them
listen-client-urls: http://$private_ipv4:2379,http://$private_ipv4:4001
listen-peer-urls: http://$private_ipv4:2380,http://$private_ipv4:7001
fleet:
public-ip: $public_ipv4
flannel:
interface: $public_ipv4
units:
- name: etcd.service
command: start
# To use etcd2, comment out the above service and uncomment these
# Note: this requires a release that contains etcd2
#- name: etcd2.service
# command: start
- name: fleet.service
command: start
- name: docker-tcp.socket
command: start
enable: true
content: |
[Unit]
Description=Docker Socket for the API
[Socket]
ListenStream=2375
Service=docker.service
BindIPv6Only=both
[Install]
WantedBy=sockets.target
- name: settimezone.service
command: start
content: |
[Unit]
Description=Set the timezone
[Service]
ExecStart=/usr/bin/timedatectl set-timezone UTC
RemainAfterExit=yes
Type=oneshot
write_files:
- path: /etc/ntp.conf
content: |
# Common pool
server 0.pool.ntp.org
server 1.pool.ntp.org
# - Allow only time queries, at a limited rate.
# - Allow all local queries (IPv4, IPv6)
restrict default nomodify nopeer noquery limited kod
restrict 127.0.0.1
restrict [::1]
- path: /home/core/nsqlookupd.service
content: |
[Unit]
Description=Nsqlookupd
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill nsqlookupd
ExecStartPre=-/usr/bin/docker rm nsqlookupd
ExecStartPre=/usr/bin/docker pull nsqio/nsq
ExecStart=/usr/bin/docker run --name=nsqlookupd -p 4160:4160 -p 4161:4161 nsqio/nsq /nsqlookupd
ExecStop=/usr/bin/docker stop nsqlookupd
Restart=always
RestartSec=10s
- path: /home/core/nsqlookupd-sidekick.service
content: |
[Unit]
Description=Nsqlookupd etcd registration
Requires=etcd.service
Requires=nsqlookupd.service
After=etcd.service
After=nsqlookupd.service
BindsTo=nsqlookupd.service
[Service]
EnvironmentFile=/etc/environment
ExecStart=/bin/bash -c '\
while true; do \
HTTP_PORT=4161; \
TCP_PORT=4160; \
curl -f ${COREOS_PRIVATE_IPV4}:$HTTP_PORT/ping; \
if [ $? -eq 0 ]; then \
/usr/bin/etcdctl set /nsqlookupd/${COREOS_PRIVATE_IPV4} ${COREOS_PRIVATE_IPV4}:$TCP_PORT --ttl 30; \
/usr/bin/etcdctl set /nsqlookupd-http/${COREOS_PRIVATE_IPV4} ${COREOS_PRIVATE_IPV4}:$HTTP_PORT --ttl 30; \
else \
/usr/bin/etcdctl rm /nsqlookupd/${COREOS_PRIVATE_IPV4}; \
/usr/bin/etcdctl rm /nsqlookupd-http/${COREOS_PRIVATE_IPV4}; \
fi; \
sleep 15; \
done'
ExecStop=/usr/bin/etcdctl rm /nsqlookupd
Restart=always
RestartSec=10s
[X-Fleet]
MachineOf=nsqlookupd.service
- path: /home/core/nsqd.service
content: |
[Unit]
Description=Nsqd
After=docker.service
After=nsqlookupd.service
Requires=docker.service
[Service]
TimeoutStartSec=0
EnvironmentFile=/etc/environment
ExecStartPre=-/usr/bin/docker kill nsqd
ExecStartPre=-/usr/bin/docker rm nsqd
ExecStartPre=/usr/bin/docker pull nsqio/nsq
ExecStart=/bin/bash -c '\
for lookupd in $(/usr/bin/etcdctl ls /nsqlookupd); do \
LOOKUPDS="$LOOKUPDS --lookupd-tcp-address=$(/usr/bin/etcdctl get $lookupd)"; \
done; \
/usr/bin/docker run --name=nsqd -p 4150:4150 -p 4151:4151 -v /data nsqio/nsq /nsqd $LOOKUPDS --broadcast-address=${COREOS_PRIVATE_IPV4} \
'
ExecStop=/usr/bin/docker stop nsqd
Restart=always
RestartSec=10s
[X-Fleet]
Global=true
- path: /home/core/nsqd-sidekick.service
content: |
[Unit]
Description=Nsqd etcd watcher
Requires=etcd.service
Requires=nsqd.service
After=etcd.service
After=nsqd.service
After=nsqlookupd.service
BindsTo=nsqd.service
[Service]
EnvironmentFile=/etc/environment
ExecStart=/bin/bash -c '\
NSQLS=$(/usr/bin/etcdctl ls /nsqlookupd); \
NSQLS_LEN=${#NSQLS[@]}; \
while true; do \
echo "checking nsqlookupd locations"; \
NSQLS_CHECK=$(/usr/bin/etcdctl ls /nsqlookupd); \
NSQLS_CHECK_LEN=${#NSQLS_CHECK[@]}; \
if [ "$NSQLS_LEN" != "$NSQLS_CHECK_LEN" ]; then \
echo "restarting nsqd"; \
/usr/bin/docker kill nsqd; \
fi; \
sleep 30; \
done'
Restart=always
RestartSec=10s
[X-Fleet]
Global=true