forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovision-vagrant.sh
executable file
·206 lines (167 loc) · 4.55 KB
/
provision-vagrant.sh
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
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# We add environment variables to these files.
readonly PROFILES=("$HOME/.bash_profile" "$HOME/.bashrc")
# Directory containing the lila source code.
readonly LILA_DIR='/vagrant'
# The HTTP port to listen on.
readonly PORT=9663
# List of packages to install with apt.
readonly DEPENDENCIES=(
git
sbt
npm
zsh
mongodb
nginx
gcc
make
closure-compiler
openjdk-8-jdk
)
error() {
echo >>/dev/stderr "ERROR: $*"
}
info() {
echo "INFO: $*"
}
setup_application_config() {
cat >"$LILA_DIR/conf/application.conf" <<'CONF'
include "base"
net {
domain = "l.org"
asset.domain = "en.l.org"
extra_ports = []
}
ai {
hash_size = 128
threads = 1
instances = 4
debug = false
play {
movetime = 500 ms
}
analyse {
movetime = 2000 ms
}
}
geoip {
file = "data/GeoLite2-City.mmdb"
}
CONF
}
# Set compilation options so that we don't run out of memory.
setup_environment_variables() {
for i in "${PROFILES[@]}"; do
echo >>"$i" "export JAVA_OPTS='-Xms64M -Xmx3072M -Xss4M -XX:ReservedCodeCacheSize=64m -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC'"
done
. -- "${PROFILES[0]}"
}
# For sbt: http://www.scala-sbt.org/release/tutorial/Installing-sbt-on-Linux.html
update_apt() {
echo "deb https://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 642AC823
sudo apt-get update
}
install_dependencies() {
sudo apt-get install -y -- "${DEPENDENCIES[@]}"
# `npm` relies on a `node` executable, but we have `nodejs`.
# https://github.com/joyent/node/issues/3911
sudo ln -sf '/usr/bin/nodejs' '/usr/bin/node'
# Installed `npm` is too old, upgrade it.
sudo npm update -g
sudo npm install -g npm
sudo npm install -g gulp
}
setup_nginx() {
local nginx_conf
nginx_conf=$(mktemp)
sed "s#LILA_DIR#$LILA_DIR#g" >"$nginx_conf" <<'CONF'
server {
server_name l.org ~^\w\w\.l\.org$;
listen 80;
error_log /var/log/nginx/lila.error.log;
access_log /var/log/nginx/lila.access.log;
charset utf-8;
location /assets {
add_header "Access-Control-Allow-Origin" "*";
alias LILA_DIR/public;
}
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_read_timeout 90s;
proxy_pass http://127.0.0.1:9663/;
}
error_page 500 501 502 503 /oops/servererror.html;
error_page 504 /oops/timeout.html;
error_page 429 /oops/toomanyrequests.html;
location /oops/ {
root LILA_DIR/public/;
}
location = /robots.txt {
root LILA_DIR/public/;
}
}
server {
server_name socket.l.org;
listen 80;
charset utf-8;
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://127.0.0.1:9663/;
}
}
CONF
sudo mv -- "$nginx_conf" '/etc/nginx/sites-available/default'
sudo nginx -s reload
}
setup_mongodb() {
# Default MongoDB database path. `mongod` will fail to launch if this
# doesn't exist.
sudo mkdir -p /data/db
sudo service mongodb start
}
build_lila() {
cd -- "$LILA_DIR"
git submodule update --init --recursive
./ui/build
./bin/gen/geoip
./bin/build-deps.sh
sbt compile
}
main() {
setup_application_config
setup_environment_variables
update_apt
install_dependencies
setup_nginx
setup_mongodb
build_lila
info 'Lila is all set up! Add this entry to your hosts file on your'
info 'host machine (not the virtual machine, or else I would have done it'
info 'for you):'
info
info " 192.168.34.34 l.org socket.l.org en.l.org de.l.org le.l.org fr.l.org es.l.org l1.org ru.l.org el.l.org hu.l.org"
info
info 'Then run "vagrant ssh" and carry out these steps inside your SSH'
info 'connection:'
info
info ' 1. cd /vagrant'
info " 2. sbt run -Dhttp.port=$PORT"
info " 3. Leave 'sbt run' running inside your virtual machine and visit"
info " http://en.l.org on your host machine. It won't load. This is"
info ' expected.'
info ' 4. Wait until sbt run has finished launching. (After it has'
info ' finished, relevant output will be printed. If the most recent'
info ' message is'
info
info ' (Server started, use Ctrl+D to stop and go back to the console...)'
info
info ' then you have not waited long enough.)'
info ' 5. Visit http://en.l.org again. It should load now.'
}
main