-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
171 lines (133 loc) · 5.2 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
HOSTNAME := $(shell hostname)
.PHONY: all
all: git ssh commit /home/isucon/.bashrc /files/hosts/$(HOSTNAME)
@echo "\n\n\n\n"
@echo "Open \e[4mhttps://github.com/$$(\
git config --get remote.origin.url | sed -r 's/^.*?:(.*)\.git$$/\1/' \
)/settings/keys/new\e[0m and paste pubkey:\n"
@cat /root/.ssh/id_rsa.pub
@echo
.PHONY: commit
commit:
git add -A
git commit -m "Configure $(HOSTNAME)"
.PHONY: git
git: /.gitignore /usr/local/bin/git-preserve-permissions /root/.vimrc /home/isucon/.vimrc
git config --get remote.origin.url \
| grep '^https://' \
&& git config --get remote.origin.url \
| sed -r 's%^https://github.com/([a-zA-Z0-9_-]*/[a-zA-Z0-9_-]*).*$$%git@github.com:\1.git%' \
| xargs git remote set-url origin \
|| true
.PHONY: ssh
ssh: /root/.ssh/authorized_keys /files/pubkey/$(HOSTNAME) sshd
.PHONY: sshd
sshd: /etc/sudoers /etc/ssh/sshd_config
.PHONY: /etc/sudoers
/etc/sudoers: /etc/sudoers.bak
echo 'Defaults env_keep+="GIT_AUTHOR_NAME"' >> $@
echo 'Defaults env_keep+="GIT_AUTHOR_EMAIL"' >> $@
/etc/sudoers.bak:
cp -p /etc/sudoers $@
.PHONY: /etc/ssh/sshd_config
/etc/ssh/sshd_config: /etc/ssh/sshd_config.bak ssh_host_key
sed -i '/^PermitRootLogin no/d' $@
echo 'PermitUserEnvironment yes' >> $@
echo 'PermitRootLogin without-password' >> $@
sshd -t
systemctl reload sshd
/etc/ssh/sshd_config.bak:
cp -p /etc/ssh/sshd_config $@
.PHONY: clean
clean:
rm -rf /root/.ssh /.gitignore /root/.vimrc /home/isucon/.vimrc /root/.ssh/id_rsa /root/.gitconfig
test -e /etc/sudoers.bak && cp -fp /etc/sudoers.bak /etc/sudoers
test -e /etc/ssh/sshd_config.bak && cp -fp /etc/ssh/sshd_config.bak /etc/ssh/sshd_config
/root/.ssh:
mkdir -p /root/.ssh
chmod 700 /root/.ssh
/root/.ssh/authorized_keys: /root/.ssh
touch $@
chmod 600 $@
git add -f $@
/.gitignore: files/gitignore
cp -n $< $@
/root/.vimrc: files/vimrc
cp -f $< $@
/home/isucon/.vimrc: files/vimrc
cp -f $< $@
/root/.ssh/id_rsa: /root/.ssh
test -f $@ || yes | ssh-keygen -f $@ -t rsa -N "" -b 4096 > /dev/null
/root/.ssh/id_rsa.pub: /root/.ssh/id_rsa
/files/pubkey/$(HOSTNAME): /root/.ssh/id_rsa.pub
mkdir -p /files/pubkey
cp -f $< $@
git add -f $@
/root/.gitconfig:
git config --global user.email "anonymous@example.com"
git config --global user.name "anonymous"
git config --global preserve-permissions.user "true"
git config --global preserve-permissions.group "true"
.PHONY: ssh_host_key
ssh_host_key:
ssh-keygen -A
/usr/local/bin/git-preserve-permissions: /git-preserve-permissions /root/.gitconfig
cp -f $</git-preserve-permissions $@
cp -f $</post-checkout $</post-merge $</pre-commit /.git/hooks/
-git preserve-permissions --save
/git-preserve-permissions:
git clone --depth=1 https://github.com/dr4Ke/git-preserve-permissions.git
/home/isucon:
mkdir -p $@
/home/isucon/.bashrc.backup: /home/isucon
cp -f /home/isucon/.bashrc $@
/files/gitignore.sh $@
/home/isucon/.bashrc: /home/isucon/.bashrc.backup
ifeq ($(shell git status --ignored --short /home/isucon/.bashrc),)
@echo skip $@
else
/files/gitignore.sh $@
echo 'alias git="sudo git"' >> $@
git add -f $@
git commit -m 'Add alias for git'
endif
/files/hosts/$(HOSTNAME):
mkdir -p /files/hosts
echo "$(shell hostname -s) $(shell hostname -i)" > $@
-git add -f $@
-git commit -m 'Add host'
.PHONY: monitoring
monitoring: prometheus node_exporter process-exporter grafana-server
.PHONY: prometheus
prometheus: /usr/local/bin/prometheus
-pkill $@
nohup $@ --config.file=/etc/prometheus/prometheus.yml &
/usr/local/bin/prometheus:
curl -sL https://github.com/prometheus/prometheus/releases/download/v2.21.0-rc.1/prometheus-2.21.0-rc.1.linux-amd64.tar.gz | tar xzv --strip-components 1 -C /usr/local/bin/ prometheus-2.21.0-rc.1.linux-amd64/prometheus
.PHONY: node_exporter
node_exporter: /usr/local/bin/node_exporter
-pkill $@
nohup $@ &
/usr/local/bin/node_exporter:
curl -sL https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz | tar xzv --strip-components 1 -C /usr/local/bin/ node_exporter-1.0.1.linux-amd64/node_exporter
.PHONY: process-exporter
process-exporter: /usr/local/bin/process-exporter /etc/process-exporter/all.yaml
-pkill $@
nohup $@ -config.path /etc/process-exporter/all.yaml &
/usr/local/bin/process-exporter:
curl -sL https://github.com/ncabatoff/process-exporter/releases/download/v0.7.2/process-exporter-0.7.2.linux-amd64.tar.gz | tar xzv --strip-components 1 -C /usr/local/bin/ process-exporter-0.7.2.linux-amd64/process-exporter
/etc/process-exporter/all.yaml: /etc/process-exporter
curl -sL https://raw.githubusercontent.com/ncabatoff/process-exporter/v0.7.2/packaging/conf/all.yaml > $@
/etc/process-exporter:
mkdir -p $@
.PHONY: grafana-server
grafana-server: /usr/local/bin/grafana-server
-pkill $@
GF_SERVER_HTTP_PORT=3999 GF_AUTH_ANONYMOUS_ENABLED=true GF_AUTH_ANONYMOUS_ORG_ROLE=Admin nohup $@ -homepath /opt/grafana &
/usr/local/bin/grafana-server: /opt/grafana
ln -sf $</bin/grafana-server $@
/opt/grafana:
mkdir -p $@
curl -sL https://dl.grafana.com/oss/release/grafana-7.1.5.linux-amd64.tar.gz | tar xzv --strip-components 1 -C $@
cp -f /files/grafana/datasources.yml $@/conf/provisioning/datasources/datasources.yml
cp -f /files/grafana/dashboards.yml $@/conf/provisioning/dashboards/dashboards.yml