Skip to content

Commit

Permalink
or exit everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
mtholder committed Apr 13, 2020
1 parent 2c0776a commit 7e40aaa
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 87 deletions.
68 changes: 34 additions & 34 deletions deploy/push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ done

# Used by oauth
if [ "x$OPENTREE_PUBLIC_DOMAIN" = x ]; then
echo "Defaulting OPENTREE_PUBLIC_DOMAIN to $OPENTREE_HOST"
echo "Defaulting OPENTREE_PUBLIC_DOMAIN to $OPENTREE_HOST" || exit 1
OPENTREE_PUBLIC_DOMAIN=$OPENTREE_HOST
fi
# WEBAPP_BASE_URL is only needed for defaulting other things
Expand Down Expand Up @@ -144,7 +144,7 @@ ASSH="ssh -i ${ADMIN_IDENTITY}"
# For unprivileged actions to server
OT_USER=$OPENTREE_USER

echo "host=$OPENTREE_HOST, admin=$OPENTREE_ADMIN, pem=$OPENTREE_IDENTITY, controller=$CONTROLLER"
echo "host=$OPENTREE_HOST, admin=$OPENTREE_ADMIN, pem=$OPENTREE_IDENTITY, controller=$CONTROLLER" || exit 1

restart_apache=no

Expand Down Expand Up @@ -204,7 +204,7 @@ EOF
err "Unrecognized command, or component not in OPENTREE_COMPONENTS: $command"
fi
# Default if not a recognized command: treat as component name
docomponent $command
docomponent $command || exit 1
esac
}

Expand All @@ -214,32 +214,32 @@ function docomponent {
component=$1
case $component in
opentree)
push_webapps
push_webapps || exit 1
restart_apache=yes
;;
phylesystem-api | api)
# 'api' option is for backward compatibility
push_phylesystem_api
push_phylesystem_api || exit 1
restart_apache=yes
;;
oti)
push_neo4j oti
push_neo4j oti || exit 1
;;
treemachine)
push_neo4j treemachine
push_neo4j treemachine || exit 1
# restart apache to clear the RAM cache (stale results)
restart_apache=yes
;;
taxomachine)
push_neo4j taxomachine
push_neo4j taxomachine || exit 1
# restart apache to clear the RAM cache (stale results)
restart_apache=yes
;;
smasher)
push_smasher
push_smasher || exit 1
;;
otcetera)
push_otcetera
push_otcetera || exit 1
;;
*)
echo "Unrecognized component: $component"
Expand Down Expand Up @@ -294,19 +294,19 @@ function push_neo4j_db {
err "Usage: $0 -c {configfile} push-db {tarball} {application}"
fi
HEREBALL=downloads/$APP.db.tgz
time rsync -vax -e "${SSH}" $TARBALL "$OT_USER@$OPENTREE_HOST":$HEREBALL
install_neo4j_db $HEREBALL $APP
time rsync -vax -e "${SSH}" $TARBALL "$OT_USER@$OPENTREE_HOST":$HEREBALL || exit 1
install_neo4j_db $HEREBALL $APP || exit 1
}

function install_neo4j_db {
HEREBALL=$1
APP=$2
${SSH} "$OT_USER@$OPENTREE_HOST" ./setup/install-db.sh $HEREBALL $APP $CONTROLLER
${SSH} "$OT_USER@$OPENTREE_HOST" ./setup/install-db.sh $HEREBALL $APP $CONTROLLER || exit 1
}

function index_doc_store {
if [ $DRYRUN = "yes" ]; then echo "[index_doc_store]"; return; fi
${SSH} "$OT_USER@$OPENTREE_HOST" ./setup/index-doc-store.sh $OPENTREE_API_BASE_URL $CONTROLLER
${SSH} "$OT_USER@$OPENTREE_HOST" ./setup/index-doc-store.sh $OPENTREE_API_BASE_URL $CONTROLLER || exit 1
}

# Component installation
Expand All @@ -327,19 +327,19 @@ function push_webapps {
# N.B. This includes the final domain name, since we'll need different keys for dev.opentreeoflife.org, www.opentreeoflife.org, etc.
keyfile=${OPENTREE_SECRETS}/treeview-GITHUB_CLIENT_SECRET-$OPENTREE_PUBLIC_DOMAIN
if [ -r $keyfile ]; then
rsync -pr -e "${SSH}" $keyfile "$OT_USER@$OPENTREE_HOST":repo/opentree/webapp/private/GITHUB_CLIENT_SECRET
rsync -pr -e "${SSH}" $keyfile "$OT_USER@$OPENTREE_HOST":repo/opentree/webapp/private/GITHUB_CLIENT_SECRET || exit 1
else
echo "** Cannot find GITHUB_CLIENT_SECRET file $keyfile"
echo "** Cannot find GITHUB_CLIENT_SECRET file $keyfile" || exit 1
fi
keyfile=${OPENTREE_SECRETS}/curation-GITHUB_CLIENT_SECRET-$OPENTREE_PUBLIC_DOMAIN
if [ -r $keyfile ]; then
rsync -pr -e "${SSH}" $keyfile "$OT_USER@$OPENTREE_HOST":repo/opentree/curator/private/GITHUB_CLIENT_SECRET
rsync -pr -e "${SSH}" $keyfile "$OT_USER@$OPENTREE_HOST":repo/opentree/curator/private/GITHUB_CLIENT_SECRET || exit 1
else
echo "** Cannot find GITHUB_CLIENT_SECRET file $keyfile"
echo "** Cannot find GITHUB_CLIENT_SECRET file $keyfile" || exit 1
fi

# we’re using the bot for “anonymous” comments in the synth-tree explorer
push_bot_identity
push_bot_identity || exit 1
}

# Utility for all the webapps.
Expand All @@ -349,10 +349,10 @@ function push_bot_identity {
# place an OAuth token for GitHub API by bot user 'opentreeapi'
tokenfile=${OPENTREE_SECRETS}/OPENTREEAPI_OAUTH_TOKEN
if [ -r $tokenfile ]; then
rsync -pr -e "${SSH}" $tokenfile "$OT_USER@$OPENTREE_HOST":.ssh/OPENTREEAPI_OAUTH_TOKEN
${SSH} "$OT_USER@$OPENTREE_HOST" chmod 600 .ssh/OPENTREEAPI_OAUTH_TOKEN
rsync -pr -e "${SSH}" $tokenfile "$OT_USER@$OPENTREE_HOST":.ssh/OPENTREEAPI_OAUTH_TOKEN || exit 1
${SSH} "$OT_USER@$OPENTREE_HOST" chmod 600 .ssh/OPENTREEAPI_OAUTH_TOKEN || exit 1
else
echo "** Cannot find OPENTREEAPI_OAUTH_TOKEN file $tokenfile"
echo "** Cannot find OPENTREEAPI_OAUTH_TOKEN file $tokenfile" || exit 1
fi
}

Expand All @@ -368,47 +368,47 @@ function push_phylesystem_api {
[ "x$OTI_BASE_URL" != "x" ] || err "OTI_BASE_URL not configured"
[ "x$OTINDEX_BASE_URL" != "x" ] || err "OTINDEX_BASE_URL not configured"

push_bot_identity
push_bot_identity || exit 1

# Place private key for GitHub access
if [ "x$OPENTREE_GH_IDENTITY" = "x" ]; then
echo "Warning: OPENTREE_GH_IDENTITY not specified"
echo "Warning: OPENTREE_GH_IDENTITY not specified" || exit 1
elif [ ! -r $OPENTREE_GH_IDENTITY ]; then
echo "Warning: $OPENTREE_GH_IDENTITY not found"
echo "Warning: $OPENTREE_GH_IDENTITY not found" || exit 1
else
rsync -p -e "${SSH}" "$OPENTREE_GH_IDENTITY" "$OT_USER@$OPENTREE_HOST":.ssh/opentree
${SSH} "$OT_USER@$OPENTREE_HOST" chmod 600 .ssh/opentree
rsync -p -e "${SSH}" "$OPENTREE_GH_IDENTITY" "$OT_USER@$OPENTREE_HOST":.ssh/opentree || exit 1
${SSH} "$OT_USER@$OPENTREE_HOST" chmod 600 .ssh/opentree || exit 1
fi

# Try to place an OAuth token for GitHub API by bot user 'opentreeapi'
tokenfile=${OPENTREE_SECRETS}/OPENTREEAPI_OAUTH_TOKEN
if [ -r $tokenfile ]; then
rsync -p -e "${SSH}" $tokenfile "$OT_USER@$OPENTREE_HOST":.ssh/OPENTREEAPI_OAUTH_TOKEN
${SSH} "$OT_USER@$OPENTREE_HOST" chmod 600 .ssh/OPENTREEAPI_OAUTH_TOKEN
rsync -p -e "${SSH}" $tokenfile "$OT_USER@$OPENTREE_HOST":.ssh/OPENTREEAPI_OAUTH_TOKEN || exit 1
${SSH} "$OT_USER@$OPENTREE_HOST" chmod 600 .ssh/OPENTREEAPI_OAUTH_TOKEN || exit 1
else
echo "****************************\n OAuth token file (${tokenfile}) not found!\n Falling back to any existing token on the server, OR a prompt for manual creation of webhooks.\n****************************"
fi

${SSH} "$OT_USER@$OPENTREE_HOST" ./setup/install-api.sh "$OPENTREE_HOST" \
$OPENTREE_DOCSTORE $COLLECTIONS_REPO $AMENDMENTS_REPO $FAVORITES_REPO $CONTROLLER $OTI_BASE_URL $OPENTREE_API_BASE_URL $COLLECTIONS_API_BASE_URL $AMENDMENTS_API_BASE_URL $FAVORITES_API_BASE_URL $OPENTREE_DEFAULT_APPLICATION $OTINDEX_BASE_URL
$OPENTREE_DOCSTORE $COLLECTIONS_REPO $AMENDMENTS_REPO $FAVORITES_REPO $CONTROLLER $OTI_BASE_URL $OPENTREE_API_BASE_URL $COLLECTIONS_API_BASE_URL $AMENDMENTS_API_BASE_URL $FAVORITES_API_BASE_URL $OPENTREE_DEFAULT_APPLICATION $OTINDEX_BASE_URL || exit 1
}

function push_neo4j {
APP=$1
if [ $DRYRUN = "yes" ]; then echo "[neo4j app: $APP]"; return; fi
${SSH} "$OT_USER@$OPENTREE_HOST" ./setup/install-neo4j-app.sh $CONTROLLER $APP $FORCE_COMPILE
${SSH} "$OT_USER@$OPENTREE_HOST" ./setup/install-neo4j-app.sh $CONTROLLER $APP $FORCE_COMPILE || exit 1
}

function push_smasher {
if [ $DRYRUN = "yes" ]; then echo "[push_smasher]"; return; fi
echo push_smasher: ${OPENTREE_WEBAPI_BASE_URL}
${SSH} "$OT_USER@$OPENTREE_HOST" ./setup/install-smasher.sh ${CONTROLLER} ${OPENTREE_WEBAPI_BASE_URL}
${SSH} "$OT_USER@$OPENTREE_HOST" ./setup/install-smasher.sh ${CONTROLLER} ${OPENTREE_WEBAPI_BASE_URL} || exit 1
}

function push_otcetera {
if [ $DRYRUN = "yes" ]; then echo "[push_otcetera]"; return; fi
echo push_otcetera:
${SSH} "$OT_USER@$OPENTREE_HOST" ./setup/install-otcetera.sh ${CONTROLLER} ${OPENTREE_WEBAPI_BASE_URL}
${SSH} "$OT_USER@$OPENTREE_HOST" ./setup/install-otcetera.sh ${CONTROLLER} ${OPENTREE_WEBAPI_BASE_URL} || exit 1
}

process_arguments $*
process_arguments $* || exit 1
16 changes: 8 additions & 8 deletions deploy/setup/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ fi
# ---------- Setup TWO VIRTUALENVs ----------
# Set up python env
if [ ! -d venv ]; then
virtualenv venv
virtualenv venv || exit 1
fi
source venv/bin/activate
source venv/bin/activate || exit 1


if [ ! -d venvp3 ]; then
python3 -m venv venvp3
python3 -m venv venvp3 || exit 1
fi


Expand All @@ -39,19 +39,19 @@ function log() {
echo "CONTROLLER shell variable is not set !?"
exit 1
fi
mkdir -p log
(echo `date` $CONTROLLER $OPENTREE_TAG " $*") >>log/messages
mkdir -p log || exit 1
(echo `date` $CONTROLLER $OPENTREE_TAG " $*") >>log/messages || exit
}

# ---------- WORKSPACES ----------

# Temporary locations for things downloaded from web. Can delete this
# after server is up and running.

mkdir -p downloads
mkdir -p downloads || exit 1

REPOS_DIR=repo
mkdir -p $REPOS_DIR
mkdir -p $REPOS_DIR || exit 1

# ---------- SHELL FUNCTIONS ----------

Expand All @@ -62,7 +62,7 @@ function opentree_branch {
#echo Set branch for $1 to be ${OPENTREE_BRANCHES[$1]}
}

. setup/CONFIG
. setup/CONFIG || exit

# Refresh a git repo

Expand Down
28 changes: 14 additions & 14 deletions deploy/setup/install-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ FAVORITES_API_BASE_URL=${11}
OPENTREE_DEFAULT_APPLICATION=${12}
OTINDEX_BASE_URL=${13}

. setup/functions.sh
. setup/functions.sh || exit 1

setup/install-common.sh $OPENTREE_DEFAULT_APPLICATION $CONTROLLER
setup/install-common.sh $OPENTREE_DEFAULT_APPLICATION $CONTROLLER || exit 1

echo "Installing API"
echo "Installing API" || exit 1


#Pre installs for normal phylestem-api venv
venv/bin/pip install vine==1.3
venv/bin/pip install vine==1.3 || exit 1
#Force early version of vine in venv to deal with python2 python3 issues
venv/bin/pip install kombu==4.1.0
venv/bin/pip install celery==4.1.0
venv/bin/pip install kombu==4.1.0 || exit 1
venv/bin/pip install celery==4.1.0 || exit 1



Expand All @@ -50,9 +50,9 @@ if ! test -f redis/bin/redis-server ; then
tar xfz "${REDIS_WITH_VERSION}.tar.gz")
fi
if ! test -d redis/work ; then
mkdir -p redis/work
mkdir -p redis/work || exit 1
(cd downloads/${REDIS_WITH_VERSION} ; \
make && make PREFIX="${HOME}/redis" install)
make && make PREFIX="${HOME}/redis" install) || exit 1
fi
fi

Expand All @@ -67,10 +67,10 @@ APPROOT=repo/$WEBAPP
OTHOME=$PWD

# This is required to make "git pull" work correctly
git config --global user.name "OpenTree API"
git config --global user.email api@opentreeoflife.org
git config --global user.name "OpenTree API" || exit 1
git config --global user.email api@opentreeoflife.org || exit 1

echo "...fetching $WEBAPP repo..."
echo "...fetching $WEBAPP repo..." || exit 1
git_refresh OpenTreeOfLife $WEBAPP || true

if [ "${PEYOTL_LOG_FILE_PATH:0:1}" != "/" ]; then
Expand All @@ -80,12 +80,12 @@ fi
git_refresh OpenTreeOfLife peyotl || true
py_package_setup_install peyotl || true

(cd $APPROOT; pip install -r requirements.txt)
(cd $APPROOT/ot-celery; pip install -r requirements.txt ; python setup.py develop)
(cd $APPROOT; pip install -r requirements.txt) || exit 1
(cd $APPROOT/ot-celery; pip install -r requirements.txt ; python setup.py develop) || exit 1

(cd web2py/applications; \
rm -rf ./phylesystem ; \
ln -sf ../../repo/$WEBAPP ./phylesystem)
ln -sf ../../repo/$WEBAPP ./phylesystem) || exit 1

# ---------- DOC STORE ----------

Expand Down
32 changes: 16 additions & 16 deletions deploy/setup/install-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,35 @@ fi
OPENTREE_DEFAULT_APPLICATION=$1
CONTROLLER=$2

. setup/functions.sh
. setup/functions.sh || exit 1

echo "Installing web2py common"
echo "Installing web2py common" || exit 1

bash setup/install-web2py.sh
bash setup/install-web2py.sh || exit 1

echo "...fetching opentree repo..."
echo "...fetching opentree repo..." || exit 1
git_refresh OpenTreeOfLife opentree || true

# requirements list ?

(cd web2py/applications; \
ln -sf ../../repo/$WEBAPP/common ./)
ln -sf ../../repo/$WEBAPP/common ./) || exit 1

# Apply our patches to vanilla web2py 2.8.2
# See comments in each patched file for details.
cp -p repo/opentree/oauth20_account.py web2py/gluon/contrib/login_methods/
cp -p repo/opentree/rewrite.py web2py/gluon/
cp -p repo/opentree/custom_import.py web2py/gluon/
cp -p repo/opentree/oauth20_account.py web2py/gluon/contrib/login_methods/ || exit 1
cp -p repo/opentree/rewrite.py web2py/gluon/ || exit 1
cp -p repo/opentree/custom_import.py web2py/gluon/ || exit 1

TMP=/tmp/tmp.tmp
echo default_application should be "$OPENTREE_DEFAULT_APPLICATION"
echo default_application should be "$OPENTREE_DEFAULT_APPLICATION" || exit 1
sed -e "s+default_application='.*'+default_application='$OPENTREE_DEFAULT_APPLICATION'+" \
repo/opentree/SITE.routes.py >$TMP
cp $TMP web2py/routes.py
rm $TMP
grep default_ web2py/routes.py
repo/opentree/SITE.routes.py >$TMP || exit 1
cp $TMP web2py/routes.py || exit 1
rm $TMP || exit 1
grep default_ web2py/routes.py || exit 1

# Kludge in case OPENTREE_DEFAULT_APPLICATION is set to 'welcome' or (more likely) 'phylesystem'
cp -p repo/opentree/webapp/static/robots.txt web2py/applications/welcome/static/
mkdir -p web2py/applications/phylesystem/static
cp -p repo/opentree/webapp/static/robots.txt web2py/applications/phylesystem/static/
cp -p repo/opentree/webapp/static/robots.txt web2py/applications/welcome/static/ || exit 1
mkdir -p web2py/applications/phylesystem/static || exit 1
cp -p repo/opentree/webapp/static/robots.txt web2py/applications/phylesystem/static/ || exit 1

3 comments on commit 7e40aaa

@jimallman
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gather this is a hygienic measure, yes? And that we don't trust set -e to do the right thing? Just want to make sure I understand these changes.

@snacktavish
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! basically it was silently failing early on, abut only resulting in errors later, so we wanted to be clear as soon as something goes wrong. I don't know about alternatives like set -e as an option though.

@jimallman
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. While set -e looks like a much simpler catch-all solution for errors, the discussion linked above convinces me that it can also lead to confusing behavior. So || exit 1 (as used here) looks like the better way.

Please sign in to comment.