-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsearch-machine.yaml
More file actions
488 lines (411 loc) · 12.6 KB
/
search-machine.yaml
File metadata and controls
488 lines (411 loc) · 12.6 KB
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
#cloud-config
# Updated to match requirements to install RDM
package_update: true
package_upgrade: true
fqdn: search-machine.local
packages:
- sshfs
- docker-compose
- docker.io
- build-essential
- git
- lynx
- tmux
- curl
- rsync
- nginx
- imagemagick
- pkg-config
- libxml2-dev
- libxmlsec1-dev
- makepasswd
- shellcheck
- jq
- tree
- zip
- unzip
groups:
- staff
- www-data
runcmd:
- adduser ubuntu staff
- adduser ubuntu www-data
snap:
commands:
- snap install --classic certbot
write_files:
- content: |
#!/bin/bash
cat <<EOT
Weclome to the Search Machine. You can access if with
multipass shell search-machine
The following scripts are available and installed in
/usr/local/bin.
# Display a list of scripts provided with this build
menu_of_scripts.bash
# These are a sample install scripts available in this VM.
install_deno.bash
install_rustup.bash
install_ghcup.bash
install_solr.bash
install_opensearch.bash
# Example scripts for working with Dockerized containers.
opensearch_indexes_dump.bash
opensearch_indexes_restore.bash
The first one displays this list. The next bunch are run
to setup the environment and install deno and some search engines.
The rest are provided as a convienence.
You can grant yourself SSH access with the following
command when you connect using multipass shell.
ssh-keygen
curl -L -o - https://github.com/${USER}.keys \
>>.ssh/authorized_keys
This is handy so you can setup port forward for local
services like.
EOT
path: /usr/local/bin/menu_of_scripts.bash
owner: "root:root"
permissions: "0775"
- content: |
#!/bin/bash
APP_NAME="$(basename "$0")"
case "$1" in
-h|-help|--help|help)
cat <<EOT
USAGE: $APP_NAME
Configure Docker to run from the Ubuntu user. This is
used by the Solr and OpenSearch installs to simplify
running them.
EOT
exit 1
;;
*)
;;
esac
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
echo "You should see the hello world container run"
if ! docker run hello-world; then
echo 'Hello world failed, aborting'
exit 1
fi
sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "$HOME/.docker" -R
#sudo systemctl enable docker.service
#sudo systemctl enable containerd.service
path: /usr/local/bin/setup_docker.bash
owner: "root:root"
permissions: "0775"
- content: |
#!/bin/bash
APP_NAME="$(basename "$0")"
case "$1" in
-h|-help|--help|help)
cat <<EOT
USAGE: $APP_NAME
Install the latest Deno using the installation
curl/shell method described at <https://deno.com/>
EOT
exit 1
;;
*)
;;
esac
# Install Deno
curl -fsSL https://deno.land/install.sh | sh
# Setup Deno
cat <<EOT >"${HOME}/.deno/env"
#!/bin/bash
export DENO_INSTALL="${HOME}/.deno"
export PATH="${HOME}/.deno/bin:$PATH"
EOT
# Append the deno setup to .bashrc
cat <<EOT | ed "${HOME}/.bashrc"
\$
a
# Import env for Deno
if [ -f "$HOME/.deno/env" ]; then
source "${HOME}/.deno/env"
fi
.
wq
EOT
path: /usr/local/bin/install_deno.bash
owner: "root:root"
permissions: "0775"
- content: |
#!/bin/bash
APP_NAME="$(basename "$0")"
case "$1" in
-h|-help|--help|help)
cat <<EOT
USAGE: $APP_NAME
Install Rust via Rustup for VM. This lets you use
Cargo to install Rust based tools like PageFind.
See <https://rustup.rs>
EOT
exit 1
;;
*)
;;
esac
# Install Rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
path: /usr/local/bin/install_rustup.bash
owner: "root:root"
permissions: "0775"
- content: |
#!/bin/bash
APP_NAME="$(basename "$0")"
case "$1" in
-h|-help|--help|help)
cat <<EOT
USAGE: $APP_NAME
Install a dockerized instance of Solr.
See <https://hub.docker.com/_/solr> for details.
Run with
docker run -d -v "$HOME/solrdata:/var/solr" -p 8983:8983 -t solr --name solr_search solr
EOT
exit 1
;;
*)
;;
esac
mkdir "${HOME}/solrdata"
docker pull solr
path: /usr/local/bin/install_solr.bash
owner: "root:root"
permissions: "0775"
- content: |
#!/bin/bash
APP_NAME="$(basename "$0")"
case "$1" in
-h|-help|--help|help)
cat <<EOT
USAGE: $APP_NAME
Install a dockerized version of OpenSearch
See <https://opensearch.org/downloads.html>
This takes a while, when it is finally running
you can access it via http://localhost:5601/
EOT
exit 1
;;
*)
esac
export OPENSEARCH_INITIAL_ADMIN_PASSWORD=$(makepasswd)
cat <<EOT >docker_opensearch.env
# This is the generates environment for running the OpenSearch container demo.
export OPENSEARCH_INITIAL_ADMIN_PASSWORD="${OPENSEARCH_INITIAL_ADMIN_PASSWORD}"
EOT
chmod 600 docker_opensearch.env
curl -L -O https://opensearch.org/samples/docker-compose.yml
docker-compose up
path: /usr/local/bin/install_opensearch.bash
owner: "root:root"
permissions: "0775"
- content: |
#!/bin/bash
APP_NAME="$(basename "$0")"
case "$1" in
-h|-help|--help|help)
cat <<EOT
USAGE: $APP_NAME
Install Haskell via GHCup for VM. With this
you can install the latest Pandoc, shellcheck and other
Haskell based tools.
See <https://www.haskell.org/ghcup/>
EOT
exit 1
;;
*)
;;
esac
# Install Haskell via GHCup.
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
path: /usr/local/bin/install_ghcup.bash
owner: "root:root"
permissions: "0775"
- content: |
#!/bin/bash
APP_NAME="$(basename "$0")"
#
# This script will dump the Open Search indexes.
#
function usage() {
cat <<EOT
% ${APP_NAME}() ${APP_NAME} user manual
% R. S. Doiel
% August 17, 2022
# NAME
${APP_NAME}
# SYNOPSIS
${APP_NAME} REPO_ID
# DESCRIPTION
Dump the Opensearch stats indexes for an Invenio RDM instance.
This script uses 'elasticdump' which is available from
<https://github.com/elasticsearch-dump/elasticsearch-dump>
and runs via npm/NodeJS.
# EXAMPLES
Backup the Opensearch for caltechdata running on CaltechDATA.
~~~shell
sudo -u ubuntu ${APP_NAME} caltechdata
~~~
EOT
}
function backup_opensearch_to() {
REPO_ID="$1"
CONTAINER="${REPO_ID}_db_1"
BACKUP_DIR="$2"
#FIXME: Need to figure out how to identify the two indexes we want to backup to get the stats.
if [ "${BACKUP_DIR}" = "" ]; then
echo "Missing the backup directory name"
exit 1
fi
if [ ! -d "${BACKUP_DIR}" ]; then
echo "${BACKUP_DIR} does not exist"
exit 1
fi
# We need to operating fetch and backup each index machine the repo name.
curl http://localhost:9200/_settings | jq . \
| grep "${REPO_ID}" | cut -d \" -f 2 | \
grep -v provided_name | sort -u >"${BACKUP_DIR}/opensearch-indexes.txt"
while read -r INDEX_NAME; do
# Save the index mapping first, then save the data
elasticdump \
--input "http://localhost:9200/${INDEX_NAME}" \
--output "${BACKUP_DIR}/${INDEX_NAME}.mapping.json" \
--type mapping
gzip --force "${BACKUP_DIR}/${INDEX_NAME}.mapping.json"
elasticdump \
--input "http://localhost:9200/${INDEX_NAME}" \
--output "${BACKUP_DIR}/${INDEX_NAME}.data.json" \
--type data
gzip --force "${BACKUP_DIR}/${INDEX_NAME}.data.json"
done <"${BACKUP_DIR}/opensearch-indexes.txt"
}
function run_backups() {
#
# Sanity check our requiremented environment
#
SCRIPTNAME="$(readlink -f "$0")"
DNAME="$(dirname "${SCRIPTNAME}")"
cd "${DNAME}" || exit 1
backup_opensearch_to "$1" "$2"
}
#
# Main entry script point.
#
case "$1" in
h | help | -h | --help)
usage
exit 0
;;
*)
if [ "$1" = "" ]; then
usage
exit 1
fi
mkdir -p opensearch-dumps
run_backups "$1" "opensearch-dumps"
;;
esac
path: /usr/local/bin/opensearch_indexes_dump.bash
owner: "root:root"
permissions: "0775"
- content: |
#!/bin/bash
APP_NAME="$(basename "$0")"
#
# This script restores the Open Search indexes previously saved using
# the dump_opensearch_index.bash script.
#
function usage() {
cat <<EOT
% ${APP_NAME}() ${APP_NAME} user manual
% R. S. Doiel
% May 29, 2024
# NAME
${APP_NAME}
# SYNOPSIS
${APP_NAME} [PATH_TO_OPENSEARCH_DUMP_DIR]
# DESCRIPTION
Restore the OpenSearch indexes for an Invenio RDM instance from
a opensearch-dump directory. It uses the "opensearch-indexes.txt" for
the index list. If you want to only restore some of the index you should
edit the "opensearch-indexes.txt" file accordingly.
This script uses 'elasticdump' which is available from
<https://github.com/elasticsearch-dump/elasticsearch-dump>
and runs via npm/NodeJS.
# EXAMPLES
Restore the Opensearch for caltechdata running on CaltechDATA.
~~~shell
sudo -u ubuntu ${APP_NAME} /storage/OpenSearchBackups
~~~
EOT
}
function restore_opensearch_to() {
BACKUP_DIR="$1"
#FIXME: Need to figure out how to identify the two indexes we want to backup to get the stats.
if [ "${BACKUP_DIR}" = "" ]; then
echo "Missing the backup directory name"
exit 1
fi
if [ ! -d "${BACKUP_DIR}" ]; then
echo "${BACKUP_DIR} does not exist"
exit 1
fi
if [ ! -f "${BACKUP_DIR}/opensearch-indexes.txt" ]; then
echo "${BACKUP_DIR}/opensearch-indexes.txt not found, aborting"
exit 2
fi
while read -r INDEX_NAME; do
# Retrieve the index mapping first, then the index data
if [ -f "${BACKUP_DIR}/${INDEX_NAME}.mapping.json.gz" ]; then
gunzip "${BACKUP_DIR}/${INDEX_NAME}.mapping.json.gz"
elasticdump \
--input "${BACKUP_DIR}/${INDEX_NAME}.mapping.json" \
--output "http://localhost:9200/${INDEX_NAME}" \
--type mapping
fi
if [ -f "${BACKUP_DIR}/${INDEX_NAME}.data.json.gz" ]; then
gunzip "${BACKUP_DIR}/${INDEX_NAME}.data.json.gz"
elasticdump \
--intput "${BACKUP_DIR}/${INDEX_NAME}.data.json" \
--output "http://localhost:9200/${INDEX_NAME}" \
--type data
fi
done <"${BACKUP_DIR}/opensearch-indexes.txt"
}
function run_restore() {
#
# Sanity check our requiremented environment
#
SCRIPTNAME="$(readlink -f "$0")"
DNAME="$(dirname "${SCRIPTNAME}")"
cd "${DNAME}" || exit 1
restore_opensearch_to "$1" "$2"
}
#
# Main entry script point.
#
case "$1" in
h | help | -h | --help)
usage
exit 0
;;
*)
if [ "$1" = "" ]; then
usage
exit 1
fi
if [ "$1" != "" ] && [ -d "$1" ]; then
run_restore "$1"
else
run_restore "opensearch-dumps"
fi
;;
esac
path: /usr/local/bin/opensearch_indexes_restore.bash
owner: "root:root"
permissions: "0775"