Created
May 15, 2016 13:04
-
-
Save boyska/7984ac7982a6539d00eb5d37a0915af2 to your computer and use it in GitHub Desktop.
test libreant upgrade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
basedir=$(readlink -f $(dirname $0)) | |
source "$basedir/config" | |
source "$basedir/lib-run.sh" | |
set -e | |
set -u | |
run /bin/bash do-base.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
basedir=$(readlink -f $(dirname $0)) | |
source "$basedir/config" | |
source "$basedir/lib-run.sh" | |
set -e | |
set -u | |
eph_run /bin/bash do-check.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
basedir=$(readlink -f $(dirname $0)) | |
source "$basedir/config" | |
source "$basedir/lib-run.sh" | |
set -e | |
set -u | |
eph_run /bin/bash do-upgrade.sh | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
basedir=$(readlink -f $(dirname $0)) | |
source "$basedir/config" | |
source "$basedir/lib-run.sh" | |
set -e | |
set -u | |
eph_run /bin/bash do-upgradeboth.sh | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
machine_name=libreant-upgrade | |
projdir=/opt/libreant | |
ES_INDEXNAME=laupgrade |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
source config | |
source lib-es.sh | |
if [[ ! -f /elasticsearch.key ]]; then | |
wget -qO /elasticsearch.key http://packages.elasticsearch.org/GPG-KEY-elasticsearch | |
fi | |
apt-key add /elasticsearch.key | |
echo "deb http://packages.elasticsearch.org/elasticsearch/1.7/debian stable main" | tee /etc/apt/sources.list.d/elasticsearch.list | |
/usr/bin/apt-get -q update | |
/usr/bin/apt-get -q install -y git curl python python-nose python-setuptools python-gevent elasticsearch openjdk-7-jre-headless jq | |
trap es_stop EXIT | |
es_start | |
es_ready | |
mkdir -p /opt/ | |
if [[ ! -d "$projdir" ]]; then | |
git clone -b master 'https://github.com/insomnia-lab/libreant.git' "$projdir" | |
fi | |
cd "$projdir" | |
python2.7 setup.py -q install | |
#cleanup | |
libreant-db 'export-all' | jq '.[]|.id' | xargs -L1 -r libreant-db remove | |
libreant-db insert-volume -l en - <<EOF | |
{ | |
"title": "A pair of socks owned by Tiburtello", | |
"actors": ["tiburtello", "carnevale", "pantalone"], | |
"year": 2005 | |
} | |
EOF | |
libreant-db insert-volume -l it - <<EOF | |
{ | |
"title": "Alcuni pan di stelle del Tuo ancora quasi buoni", | |
"actors": ["cuoco del tuo", "tuo", "mamma discount"], | |
"year": 2002 | |
} | |
EOF | |
libreant-db insert-volume -l fr - <<EOF | |
{ | |
"title": "baguette", | |
"actors": ["zinedine zidane", "toto le moco", "obelix"], | |
"year": 1981 | |
} | |
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
source config | |
source lib-es.sh | |
set -e | |
set -u | |
es_start | |
es_ready | |
[[ "$(libreant-db 'export-all' | jq length)" = 3 ]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
source config | |
source lib-es.sh | |
set -e | |
set -u | |
die() { | |
echo "Error: $1" | |
exit 1 | |
} | |
[[ "$(dpkg-query -W elasticsearch | cut -f2)" = 1.* ]] || die "Wrong ES version installed" | |
es_start | |
cd "$projdir" | |
git remote add patched 'https://github.com/ael-code/libreant.git' | |
git fetch -q patched | |
git reset --hard patched/elasticsearch-2-bulk -- | |
python setup.py -q install | |
es_ready | |
servlog=$(mktemp serv.XXXXX) | |
curlout=$(mktemp curl.XXXXXX) | |
db_upgrade_needed || die "DB upgrade should be needed" | |
libreant -d &> $servlog & | |
sleep 1 | |
set -x | |
set +e | |
curl -si localhost:5000/recents 2>&1 | tee $curlout | |
sync | |
if ! grep -q "Couldn't update index properties mapping" "$servlog"; then | |
die "No error about mapping" | |
fi | |
head -n3 "$curlout"|grep -q 500 || die "500 should be given on /recents" | |
grep -q RequestError "$curlout" || die "Reason should be a RequestError" | |
jobs | |
kill %libreant | |
libreant-db upgrade -y | |
db_upgrade_needed && die "DB upgrade still needed?" | |
libreant -d &> $servlog & | |
sleep 1 | |
curl -si localhost:5000/recents 2>&1 | tee $curlout | |
sync | |
if head -n1 $curlout | grep -q 500; then | |
tail "$servlog" | |
die "Error 500 after upgrade" | |
fi | |
if grep -q "Couldn't update index properties mapping" "$servlog"; then | |
die "Still warning after upgrade" | |
fi | |
set +x | |
echo 'Testing upgrade procedure complete! :)' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
source config | |
source lib-es.sh | |
die() { | |
echo "Error: $1" | |
exit 1 | |
} | |
echo "deb http://packages.elasticsearch.org/elasticsearch/2.x/debian stable main" > /etc/apt/sources.list.d/elasticsearch.list | |
/usr/bin/apt-get -q update | |
/usr/bin/apt-get -q install -y elasticsearch | |
[[ "$(dpkg-query -W elasticsearch | cut -f2)" = 2.* ]] || die "Wrong ES version installed" | |
set -x | |
es_start | |
cd "$projdir" | |
git remote add patched 'https://github.com/ael-code/libreant.git' | |
git fetch -q patched | |
git reset --hard patched/elasticsearch-2-bulk -- | |
python setup.py -q install | |
es_ready | |
servlog=$(mktemp serv.XXXXX) | |
curlout=$(mktemp curl.XXXXXX) | |
db_upgrade_needed || die "DB upgrade should be needed" | |
libreant -d &> $servlog & | |
sleep 1 | |
set -x | |
set +e | |
curl -si localhost:5000/recents 2>&1 | tee $curlout | |
sync | |
if ! grep -q "Couldn't update index properties mapping" "$servlog"; then | |
die "No error about mapping" | |
fi | |
head -n3 "$curlout"|grep -q 500 || echo "500 should be given on /recents" | |
grep -q RequestError "$curlout" || echo "Reason should be a RequestError" | |
jobs | |
kill %libreant | |
libreant-db -d upgrade -y | |
#es_stop | |
#es_start | |
#es_ready | |
db_upgrade_needed && die "DB upgrade still needed?" | |
libreant -d &> $servlog & | |
sleep 1 | |
curl -si localhost:5000/recents 2>&1 | tee $curlout | |
sync | |
if head -n1 $curlout | grep -q 500; then | |
tail "$servlog" | |
die "Error 500 after upgrade" | |
fi | |
if grep -q "Couldn't update index properties mapping" "$servlog"; then | |
die "Still warning after upgrade" | |
fi | |
set +x | |
echo 'Testing upgrade procedure complete! :)' | |
read -p 'Press enter to exit' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export ES_HOME=/usr/share/elasticsearch | |
export ES_CONF_DIR=/etc/elasticsearch | |
export ES_CONF_FILE=/etc/elasticsearch/elasticsearch.yml | |
export ES_DATA_DIR=/var/lib/elasticsearch | |
export ES_LOG_DIR=/var/log/elasticsearch | |
export ES_PID_DIR=/var/run/elasticsearch | |
es_start() { | |
if [[ "$(dpkg-query -W elasticsearch | cut -f2)" = 2.* ]]; then | |
/usr/share/elasticsearch/bin/elasticsearch-systemd-pre-exec | |
/usr/share/elasticsearch/bin/elasticsearch \ | |
-Des.insecure.allow.root=true \ | |
-Des.pidfile=$ES_PID_DIR/elasticsearch.pid \ | |
-Des.default.path.home=$ES_HOME \ | |
-Des.default.path.logs=$ES_LOG_DIR \ | |
-Des.default.path.data=$ES_DATA_DIR \ | |
-Des.default.path.conf=$ES_CONF_DIR > /dev/null & | |
else | |
/usr/share/elasticsearch/bin/elasticsearch \ | |
-Des.pidfile=$ES_PID_DIR/elasticsearch.pid \ | |
-Des.default.path.home=$ES_HOME \ | |
-Des.default.path.logs=$ES_LOG_DIR \ | |
-Des.default.path.data=$ES_DATA_DIR \ | |
-Des.default.config=$ES_CONF_FILE \ | |
-Des.default.path.conf=$ES_CONF_DIR > /dev/null & | |
fi | |
} | |
es_stop() { | |
[[ -f $ES_PID_DIR/elasticsearch.pid ]] || return | |
es_pid=$(cat $ES_PID_DIR/elasticsearch.pid) | |
[[ -n "$es_pid" ]] || return | |
[[ -d "/proc/$es_pid" ]] || return | |
kill "$es_pid" | |
} | |
es_ready() { | |
sleep 20 | |
} | |
db_upgrade_needed() { | |
ret=0 | |
libreant-db -d upgrade --check-only || ret=$? | |
if [[ "$ret" -eq 0 ]]; then | |
return 1 | |
elif [[ "$ret" -eq 123 ]]; then | |
return 0 | |
else | |
die "Unexpected in update_needed, exit status=$ret" | |
fi | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
run() { | |
systemd-nspawn -D /var/lib/machines/$machine_name \ | |
--bind-ro="$basedir:/tools" \ | |
--chdir=/tools/ \ | |
-a "$@" | |
} | |
eph_run() { | |
systemd-nspawn -D /var/lib/machines/$machine_name \ | |
--bind-ro="$basedir:/tools" \ | |
--chdir=/tools/ \ | |
-a -x \ | |
"$@" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment