Skip to content

Instantly share code, notes, and snippets.

@heffergm
Last active March 11, 2022 12:59
Show Gist options
  • Select an option

  • Save heffergm/2908117c90e2cecb7f50 to your computer and use it in GitHub Desktop.

Select an option

Save heffergm/2908117c90e2cecb7f50 to your computer and use it in GitHub Desktop.
Pelias
#!/usr/bin/env bash
basedir="${HOME}/pelias"
es_version="1.3.4"
es_port="9200"
es_url="https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-${es_version}.tar.gz"
export NODE_PATH=${NODE_PATH}:./node_modules
# dependencies
for dep in 'node' 'git' 'wget' 'curl'; do
if [ ! $(which ${dep}) ]; then
echo "${dep} required, please install it and try again";
exit 1
fi
done
getstatus() {
if [ $? != 0 ]; then
echo "Failure! Exiting."
exit 1
fi
}
clone() {
cd ${basedir}
org=$(echo $1 | cut -d"/" -f1)
repo=$(echo $1 | cut -d"/" -f2)
[ -d ${org} ] || mkdir ${org};
cd ${org}
if [ ! -d "${repo}" ]; then
github="https://github.com/${1}.git"
echo "cloning repo: ${github}"
git clone ${github}
fi
cd ${repo}
git pull
git checkout $2
npm install
}
# install elasticsearch
echo -e "Should we install elasticsearch for you? \c"
read resp dummy
case ${resp} in
yes|Yes|YES|y|Y)
cd ${basedir}
if [ -d elasticsearch-${es_version} ]; then
echo "Looks like it might already be installed... skipping."
elif [[ $(pgrep -f elasticsearch-${es_version}) ]]; then
echo "Elasticsearch appears to be running. Skipping..."
else
wget ${es_url} -O elasticsearch-${es_version}.tgz && tar zxf elasticsearch-${es_version}.tgz
cd elasticsearch-${es_version} && ./bin/plugin -url https://github.com/pelias/elasticsearch-plugin/blob/${es_version}/pelias-analysis.zip?raw=true -install pelias-analysis
./bin/elasticsearch -d -Xmx4g -Xms4g -Des.threadpool.bulk.size=4 -Des.threadpool.bulk.queue=500
echo "Sleeping for a bit to allow Elasticsearch to start..."
sleep 30
fi
;;
*)
echo "Ok!"
echo "Note that you should be running with:
* at least 4gb of allocated heap space
* an increased bulk threadpool: -Des.threadpool.bulk.size=4 -Des.threadpool.bulk.queue=500
* the pelias-analysis plugin installed: bin/plugin -url https://github.com/pelias/elasticsearch-plugin/blob/${es_version}/pelias-analysis.zip?raw=true -install pelias-analysis"
;;
esac
# check that elasticsearch is installed and running
if [[ ! $(curl -s localhost:${es_port}) ]]; then
echo "Elasticsearch not running on port ${es_port}. Exiting."
exit 1
fi
if [[ ! $(curl -s localhost:${es_port} | grep number | grep "${es_version}") ]]; then
echo "You are not running elasticsearch version ${es_version}. Exiting."
exit 1
fi
if [[ ! $(curl -s localhost:${es_port}/_cluster/stats | grep pelias-analysis) ]]; then
echo -e "You need to install the pelias analyzer plugin: ./bin/plugin -url https://github.com/pelias/elasticsearch-plugin/blob/${es_version}/pelias-analysis.zip?raw=true -install pelias-analysis. Exiting."
exit 1
fi
# create directory if it doesn't exist
if [ ! -d ${basedir} ]; then
echo "creating dir: ${basedir}"
mkdir ${basedir}
getstatus
fi
# update repositories
clone "pelias/schema" "master"
clone "pelias/api" "master"
clone "mapzen/pelias-geonames" "master"
clone "mapzen/pelias-openstreetmap" "master"
# reset mappings
cd ${basedir}/pelias/schema
node scripts/drop_index.js --force-yes
node scripts/create_index.js
getstatus
# import geonames
cd ${basedir}/mapzen/pelias-geonames
#if [ ! -f data/allCountries.zip ]; then
# ./bin/pelias-geonames -d all # download allCountries.zip
#fi
./bin/pelias-geonames -i all # stream the import of allCountries.zip
getstatus
# import openstreetmap
cd ${basedir}/mapzen/pelias-openstreetmap
node index.js
getstatus
# run the api
cd ${basedir}/pelias/api
npm start
@stefanocudini
Copy link

is this script made to run pelias modules in a single docker container?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment