|
| 1 | +#!/bin/bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# Set HOOT_HOME to another location prior to running this script |
| 5 | +# if ~/hoot isn't the correct location |
| 6 | +if [ -z "$HOOT_HOME" ]; then |
| 7 | + HOOT_HOME=~/hoot |
| 8 | +fi |
| 9 | +TOMCAT_NAME=tomcat8 |
| 10 | +TOMCAT_LEGACY_SYSTEMD=/etc/systemd/system/${TOMCAT_NAME}.service |
| 11 | +TOMCAT_SYSTEMD=/usr/lib/systemd/system/${TOMCAT_NAME}.service |
| 12 | +TOMCAT_LOGS=/var/log/tomcat8 # logs go here |
| 13 | +TOMCAT_CONFIG=/etc/tomcat8 # config files go here |
| 14 | + |
| 15 | +echo "######## Begin ${TOMCAT_NAME} installation ########" |
| 16 | + |
| 17 | +# If old systemd service unit exists, then Tomcat was installed manually |
| 18 | +# and must be uninstalled. |
| 19 | +if test -f $TOMCAT_LEGACY_SYSTEMD; then |
| 20 | + # Disable, stop, and remove the previous systemd service. |
| 21 | + sudo systemctl disable tomcat8 |
| 22 | + sudo systemctl stop tomcat8 |
| 23 | + sudo rm -f $TOMCAT_LEGACY_SYSTEMD |
| 24 | + sudo systemctl daemon-reload |
| 25 | + |
| 26 | + # Clean up all manually-installed folders. |
| 27 | + sudo rm -fr /usr/share/tomcat8 |
| 28 | + sudo rm -fr /var/lib/tomcat8 |
| 29 | + sudo rm -fr /var/cache/tomcat8 |
| 30 | + sudo rm -fr $TOMCAT_LOGS |
| 31 | + sudo rm -fr $TOMCAT_CONFIG |
| 32 | +fi |
| 33 | + |
| 34 | +# Install Tomcat from our package in Hootenanny's dependency repo. |
| 35 | +sudo yum install -y tomcat8 |
| 36 | + |
| 37 | +# Modify the vagrant user to be a part of the tomcat group, so it |
| 38 | +# can write same directories as the tomcat service user. |
| 39 | +sudo usermod -a -G tomcat vagrant |
| 40 | + |
| 41 | +# Add local configuration file that sets up environment variables |
| 42 | +# for Hootenanny development. |
| 43 | +sudo bash -c "cat >> ${TOMCAT_CONFIG}/conf.d/hoot.conf" << EOF |
| 44 | +export GDAL_DATA=/usr/share/gdal |
| 45 | +export HOOT_HOME=${HOOT_HOME} |
| 46 | +export HOOT_WORKING_NAME=hootenanny |
| 47 | +export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib:${HOOT_HOME}/lib |
| 48 | +export PATH=${HOOT_HOME}/bin:${PATH} |
| 49 | +EOF |
| 50 | + |
| 51 | +# Have the service run as the vagrant user and group. |
| 52 | +sudo sed -i "s/User=tomcat/User=vagrant/g" $TOMCAT_SYSTEMD |
| 53 | +sudo sed -i "s/Group=tomcat/Group=vagrant/g" $TOMCAT_SYSTEMD |
| 54 | + |
| 55 | +sudo systemctl daemon-reload |
| 56 | +sudo systemctl enable $TOMCAT_NAME |
| 57 | + |
| 58 | +if ! grep -i --quiet 'ingest/processed' ${TOMCAT_CONFIG}/server.xml; then |
| 59 | + echo "Adding Tomcat context path for tile images..." |
| 60 | + sudo sed -i.bak 's@<\/Host>@ <Context docBase=\"'"$HOOT_HOME"'\/userfiles\/ingest\/processed\" path=\"\/static\" \/>\n &@' ${TOMCAT_CONFIG}/server.xml |
| 61 | +fi |
| 62 | + |
| 63 | +# Note: tomcat8 package already has `allowLinking=true` set in: |
| 64 | +# ${TOMCAT_CONFIG}/context.xml |
| 65 | + |
| 66 | +# Clean out tomcat logfile. We restart tomcat after provisioning. |
| 67 | +sudo systemctl stop $TOMCAT_NAME |
| 68 | +sudo rm -f ${TOMCAT_LOGS}/catalina.out |
| 69 | + |
| 70 | +# Recreate catalina.out to prevent error pop-up. |
| 71 | +sudo bash -c "cat >> ${TOMCAT_LOGS}/catalina.out" <<EOF |
| 72 | +Please login to the host to view the logs: |
| 73 | +
|
| 74 | + sudo journalctl -u tomcat8 |
| 75 | +EOF |
| 76 | +sudo chown vagrant:vagrant ${TOMCAT_LOGS}/catalina.out |
| 77 | + |
| 78 | +echo "######## End ${TOMCAT_NAME} installation ########" |
0 commit comments