-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
223 lines (204 loc) · 7.24 KB
/
Makefile
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
PREFIX = /
BIN_DIR = $(PREFIX)/usr/bin
DOC_DIR = $(PREFIX)/usr/share/doc/highwaytohell
ETC_DIR = $(PREFIX)/etc
LIB_DIR = $(PREFIX)/var/lib/highwaytohell
MAN_DIR = $(PREFIX)/usr/share/man/man8
SHARE_DIR = $(PREFIX)/usr/share/highwaytohell
shrinkpack:
if ! test -d node_modules; then \
npm install; \
fi
if ! test -x /usr/local/bin/shrinkpack -o -x /usr/bin/shrinkpack; then \
npm install -g shrinkpack; \
npm install -g shrinkwrap; \
fi
if npm shrinkwrap --dev; then \
shrinkpack -c || shrinkpack; \
git status || true; \
fi
shrinkwrap: shrinkpack
rewrap:
rm -fr node_modules node_shrinkwrap npm-shrinkwrap.json
make shrinkpack
dbinit:
test -f db/cassandra.init || return 0
test "$$CASSANDRA_HOST" || return 0
if test "$$CQLSH_VERSION"; then \
grep -vE '^(#|$$)' db/cassandra.init | cqlsh --cqlversion=$$CQLSH_VERSION $$CASSANDRA_HOST; \
else \
grep -vE '^(#|$$)' db/cassandra.init | cqlsh $$CASSANDRA_HOST; \
fi
if test -x ./db/updateScript; then \
if ! ./db/updateScript; then \
exit 1; \
fi; \
fi
dbinittest: dbinit
test -f db/cassandra.test || return 0
test "$$CASSANDRA_HOST" || return 0
if test "$$CQLSH_VERSION"; then \
grep -v '^(#|$$)' db/cassandra.test | cqlsh --cqlversion=$$CQLSH_VERSION $$CASSANDRA_HOST; \
else \
grep -v '^(#|$$)' db/cassandra.test | cqlsh $$CASSANDRA_HOST; \
fi
install:
test -d $(DOC_DIR) || mkdir -p $(DOC_DIR)
install -c -m 0644 samples.d/apache.conf $(DOC_DIR)/apache-vhost.conf.sample
install -c -m 0644 samples.d/haproxy/apiGW.cfg $(DOC_DIR)/haproxy.cfg.sample
install -c -m 0644 samples.d/nginx.conf $(DOC_DIR)/nginx-vhost.conf.sample
install -c -m 0644 samples.d/rsyslog.conf $(DOC_DIR)/rsyslog.conf.sample
install -c -m 0644 samples.d/munin/hwth_multi $(DOC_DIR)/munin.hwth_multi
install -c -m 0644 samples.d/munin/hwth_multi.conf $(DOC_DIR)/munin.conf.sample
install -c -m 0644 samples.d/butters.cfg.sample $(DOC_DIR)/butters.cfg.sample
install -c -m 0644 samples.d/nrpe/check_pm2 $(DOC_DIR)/nrpe-pm2-probe
install -c -m 0644 samples.d/nrpe/check_pm2.cfg $(DOC_DIR)/nrpe-pm2-conf
install -c -m 0644 samples.d/nrpe/sudoers-pm2 $(DOC_DIR)/nrpe-pm2-sudoers
install -c -m 0644 samples.d/fail2ban/jail.conf $(DOC_DIR)/fail2ban-jail.conf.sample
install -c -m 0644 samples.d/fail2ban/filters.d/highwaytohell.conf $(DOC_DIR)/fail2ban-filter.conf.sample
install -c -m 0644 samples.d/hwth-watchmark.service $(DOC_DIR)/hwth-watchmark.service
for potentialDoc in API.md README.md QUICKSTART.md; \
do \
test -s $$potentialDoc || continue; \
install -c -m 0644 $$potentialDoc $(DOC_DIR)/$$potentialDoc; \
done
for d in api db lib templates static/fav workers node_shrinkwrap; \
do \
test -d $(SHARE_DIR)/$$d || mkdir -p $(SHARE_DIR)/$$d; \
done
find api lib templates static workers node_shrinkwrap -type f | while read file; \
do \
install -c -m 0644 $$file $(SHARE_DIR)/$$file; \
done
find db -type f | while read file; \
do \
if echo $$file | grep -E '(updateScript|\.migrate|\.sh)$$' >/dev/null; then \
install -c -m 0755 $$file $(SHARE_DIR)/$$file; \
else \
install -c -m 0644 $$file $(SHARE_DIR)/$$file; \
fi; \
done
for file in revision package.json npm-shrinkwrap.json; \
do \
test -f $$file || continue; \
install -c -m 0644 $$file $(SHARE_DIR)/$$file; \
done
test -d $(LIB_DIR) || mkdir -p $(LIB_DIR)
install -c -m 0644 samples.d/hwth-profile $(LIB_DIR)/.profile-sample
test -d $(BIN_DIR) || mkdir -p $(BIN_DIR)
install -c -m 0755 samples.d/butters $(BIN_DIR)/butters
install -c -m 0755 samples.d/hwth-control $(BIN_DIR)/hwth
install -c -m 0755 samples.d/hwth-watchmark $(BIN_DIR)/hwth-watchmark
test -d $(ETC_DIR)/cron.weekly || mkdir -p $(ETC_DIR)/cron.weekly
install -c -m 0755 samples.d/pm2.cron $(ETC_DIR)/cron.weekly/pm2-update
build:
@/bin/echo nothing to be done
favicon:
if ! test -s logo.png; then \
echo "please install initial logo into repository root, as logo.png"; >&2 \
exit 1; \
fi
for size in 16 32 57 60 64 70 72 76 96 114 120 128 144 150 152 160 180 196 256 310; \
do \
convert logo.png -resize "$${size}x$$size" static/fav/icon$$size.png; \
done
for size in 16 32 48 64; \
do \
convert logo.png -resize "$${size}x$$size" static/fav/icon$$size.ico; \
done
for size in 128 256; \
do \
convert logo.png -resize "$${size}x$$size" static/logo$$size.png; \
done
find static/fav -type f
sourceismissing:
for dep in node_shrinkwrap/*; \
do \
if ! grep "source-is-missing $$dep" debian/source.lintian-overrides >/dev/null; then \
echo "highwaytohell source: source-is-missing $$dep" >>debian/source.lintian-overrides; \
fi; \
done
clean:
if test -s .gitignore; then \
grep -vE '^(#|$$)' .gitignore | while read line; \
do \
rm -fr ./$$line; \
done; \
fi
rm -fr *log
reset:
git reset; \
for item in api *.md *.yml *.json .gitignore db debian lib LICENSE Makefile node_shrinkwrap samples.d static templates tests workers; \
do \
rm -fr $$item; \
git checkout -- $$item; \
done
createdebsource:
LANG=C debuild -S -sa
createdebbin:
LANG=C dpkg-buildpackage -us -uc
createinitialarchive: clean sourceismissing
if test -d .git; then \
case "`git branch | awk '/^\*/{print $$2}'`" in \
master|production|oldbear-prod) suffix= ;; \
oldbear-preprod|preprod) suffix=rc ;; \
staging) suffix=beta ;; \
*) suffix=alpha ;; \
esac; \
else \
suffix=; \
fi; \
git rev-parse HEAD >revision 2>/dev/null || echo alpha >revision; \
rm -fr .git .gitignore .gitrelease circle.yml db/*PoC samples.d/diags samples.d/screens debian/highwaytohell debian/highwaytohell.debhelper.log; \
sed -i "s|(\([0-9]*\.[0-9]*\.[0-9]*-\)\([0-9]*\)) unstable;|(\1$${suffix}\2) unstable;|" debian/changelog
version=`awk '/^highwaytohell/{print $$2;exit}' debian/changelog | sed -e 's|^[^0-9]*\([0-9]*\.[0-9]*\.[0-9]*\)-.*|\1|'`; \
( cd .. ; tar -czf highwaytohell_$$version.orig.tar.gz highwaytohell )
processestest:
for proc in refreshZones apiGW outboundNotifier checkHealth; \
do \
if ! pm2 show $$proc 2>&1 | grep online >/dev/null; then \
echo $$proc is dead; \
test "$$CIRCLECI" && pm2 show $$proc; \
exit 1; \
elif ! pm2 show $$proc 2>&1 | grep -E ' restarts .* 0 ' >/dev/null; then \
echo $$proc is restarting; \
test "$$CIRCLECI" && pm2 show $$proc; \
exit 1; \
fi; \
done
echo "all processes healthy"
pingtest:
if ! curl http://127.0.0.1:8080/ping | grep '^OK$$'; then \
echo apiGW ping failed; \
exit 1; \
fi
test: processestest pingtest
./tests/butters.sh
release:
ifeq ($(GITHUB_USER),)
@/bin/echo "CRITICAL: missing GITHUB_USER env var" >&2;
@exit 1;
else
ifeq ($(GITHUB_TOKEN),)
@/bin/echo "CRITICAL: missing GITHUB_TOKEN env var" >&2;
@exit 1;
else
ifeq (, $(shell which debuild))
@/bin/echo "CRITICAL: missing debuild, can not build debian packages" >&2;
@exit 1;
else
branch=`test -d .git && git branch | awk '/^\*/{print $$2}'`; \
test -z "$$branch" && branch=master; \
if ! git pull; then \
echo "CRITICAL: failed pulling from GitHub" >&2; \
exit 1; \
elif ! git push -u origin $$branch; then \
echo "CRITICAL: failed pushing to GitHub" >&2; \
exit 1; \
elif ! ./.gitrelease; then \
exit $$?; \
fi
endif
endif
endif
all: build