Skip to content

4.0.0 Vireo Deployment AWS

Frank Smutniak edited this page Aug 19, 2019 · 17 revisions

Vireo 4 AWS Deployment

This deployment was successfully tested on a AWS t2.small. A t2.micro did not have enough memory for java to create a war file. Installations may vary on other systems.

A docker deployment is available at https://github.com/TexasDigitalLibrary/Vireo4Docker

Requirements

The vireo install will need PostgreSQL. The H2 database can be used for testing but PostgreSQL will be needed for persistence across reboots. MySQL is not yet supported.

The base system will need npm, nodejs, grunt and maven. Nodejs is needed for processing assets.

The base system will also need git but this typically comes with the base linux system.

Vireo will also need java 1.8 developer kit.

Edits to src/main/resources/application.yaml will also be needed.

Finally the install should use a proxy web server such as Apache2 or Nginx.

Sign in as root

sudo bash --login

Call apt-get update to be ready for other installs.

yum update

Verify that git is installed.

git --version

Typically it is already part of the base linux system but it may need to be explicitly installed. If so:

yum install git

Install Maven

wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo
yum install -y apache-maven

Install Java

yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel

There may have been an older java installed with the base system so find the newly installed java

alternatives --config java
    #select the correct number for java 1.8
java -version

export JAVA_HOME=/usr/lib/jvm/java-1.8.0

Create an account:

Set up an account under which the deploy will be performed. For these instructions we'll use the account named 'vireo.'

Add user 'vireo' and then enter a requested initial password.

adduser vireo4

Set password for vireo4:

passwd vireo4

Give user 'vireo4' root level privileges:

visudo

Add the following line beneath the similar line for root:

    vireo4    ALL=(ALL) ALL 

Exit editor using ':wq'

Sign out from the root account and sign in with the 'vireo4' account.

Alternatively you can use the vireo4 account with:

sudo -u vireo4 bash

Install npm, node, and grunt

This is the most system specific problem for deployments. This section may be different for later versions of ubuntu or AWS variants.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

nvm --version

nvm install node

npm install -g grunt-cli

Put

export JAVA_HOME=/usr/lib/jvm/java-1.8.0

and

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

in ~/.bashrc

Create a directory for assets:

Uploaded documents are stored in the operating systems directory structure. Create a [assets_store] directory such as /opt/vireo for these files.

sudo mkdir /opt/vireo/
sudo chown vireo4 /opt/vireo/
sudo chgrp vireo4 /opt/vireo/

Install Vireo 4

Sign in as vireo4. Create a directory in vireo4 such as /home/vireo4/etd/ in which to clone Vireo:

mkdir /home/vireo4/etd/
cd /home/vireo4/etd/
git clone https://github.com/TexasDigitalLibrary/Vireo.git
cd Vireo

Use the default master branch or change to the latest point release branch of Vireo4

git checkout 4.0.x

Test!

Try to start vireo4 using spring boot to verify that it has everything it needs to build and run.

mvn clean spring-boot:run -Drun.arguments=console

After several minutes of downloads and processing you will see a generate> prompt. If you get this far then your system is set up properly. Use Control-C or other means to kill this process. If it failed review previous steps and verify the version of OS you are using. Most problems are related to getting the right npm and node versions for the OS.

If you point your browser to your URL or IP address followed by the port number, e.g. http://example.edu:9000, you will see a poorly formatted vireo page. This is OK. The presentation of this page will be remedied by changes to application.yaml further down.

Install PostgreSQL, init, and start the server:

yum install postgresql postgresql-server
sudo service postgresql initdb
sudo service postgresql start
psql --version

Sign in under the postgres account and then use psql to enter commands:

sudo su - postgres
psql

This will give you a 'postgres=#' prompt.

Create role 'vireodb', give privileges, and create database vireo.

postgres=# CREATE ROLE vireodb WITH LOGIN PASSWORD '[your_vireo_postgres_password]';
postgres=# ALTER ROLE vireodb CREATEDB;
postgres=# CREATE DATABASE vireo;
postgres=# GRANT ALL PRIVILEGES ON DATABASE vireo TO vireodb;
postgres=# \q

Exit from the postgres account so you will be back in the vireo4 account.

exit

Edit /var/lib/pgsql9/data/pg_hba.conf Change lines: # "local" is for Unix domain socket connections only local all all peer # IPv4 local connections: host all all 127.0.0.1/32 ident to # "local" is for Unix domain socket connections only local all all md5 # IPv4 local connections: local all all md5

Restart postgres

service postgresql restart

Test with

psql [dbname] [username]
psql vireo vireodb

Determine the server's URL

Your URL can be found on the AWS console under EC2 listings. It is of the form 'ec2-[IP ADDRESS].compute-1.amazonaws.com

e.g. ec2-111-222-333-444.compute-1.amazonaws.com

You can also find the ip address with either:

curl http://checkip.amazonaws.com

or

curl http://icanhazip.com

Edit src/main/resources/application.yaml

A few values will be set at the command line but some should be set in the application.yaml file.

Set a port. For this install we will change port 9000 to port 8080 as we'll be running with embedded tomcat:

server:
  #port: 9000
  port: 8080

Set the database access by commenting out the H2 section and uncommenting the platform, url, and driverClassName in the PostgreSQL entry. Modify as needed for your particular setup (i.e. you elected a different port number):

spring:
  datasource:
    platform: postgresql
    url: jdbc:postgresql://localhost:5432/vireo
    driverClassName: org.postgresql.Driver

Also under datasource, set the database role name and password (as set in the Install PostreSQL section):

    username: vireodb
    password: [your_vireo_postgres_password]

Comment/uncomment the jpa entry to select the correct database-platform for PostgreSQL:

  jpa:
    database-platform: org.hibernate.dialect.PostgreSQLDialect

In the same section change:

    hibernate.ddl-auto: create-drop

To:

    hibernate.ddl-auto: update

Set the application URL with your url such as http://etd.example.edu or ec2-111-222-333-444.compute-1.amazonaws.com.

app:
  url: [your url]

Note that the values which appear under info: build: will be filled either via the pom.xml or the command line.

Finally, set the email relay and addresses:

  email:
    host: [your_smtp_relay]				#e.g. smtp-relay.example.edu
    from: [your_outbound_address]		#e.g. [email protected]
    replyTo: [your_replyto_address]		#e.g. [email protected]

Create user accounts (optional):

If you want to give users some sample accounts to experiment with, you will need to start vireo enabled with a command line interface. Use the -Drun.argumets=console flag, which only works when started with spring-boot.

mvn clean spring-boot:run -Drun.arguments=console

Once you get the prompt:

generate> generate 3
generate> accounts 3
generate> admin_accounts 3

If you sign back in to the database you can see the accounts:

sudo su - postgres
psql
postgres=# \c vireo
postgres=# SELECT * FROM weaver_users;
postgres=# \q
exit

Build production mode war file with assets.uri specified:

mvn clean package -Dproduction -Dassets.uri=file:[assets_path]
	#e.g.  mvn clean package -Dproduction -Dassets.uri=file:/opt/vireo

Run it with the following command using the appropriate war file name based on [version-tag]:

nohup java -jar target/vireo-4.0.0-[version-tag].war &
	e.g.  nohup java -jar target/vireo-4.0.0-RC.war &

Run as a Service

Create file /etc/init.d/vireo4 which contains:

#!/bin/sh
SERVICE_NAME=vireo4
PATH_TO_JAR=/home/vireo4/etd/Vireo/target/vireo-4.0.0-RC.war
PID_PATH_NAME=/tmp/vireo4-pid
case $1 in
    start)
        echo "Starting $SERVICE_NAME ..."
        if [ ! -f $PID_PATH_NAME ]; then
            nohup sudo -u vireo4 java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &
            echo $! > $PID_PATH_NAME
            echo "$SERVICE_NAME started ..."
        else
            echo "$SERVICE_NAME is already running ..."
        fi
    ;;
    stop)
        if [ -f $PID_PATH_NAME ]; then
            PID=$(cat $PID_PATH_NAME);
            echo "$SERVICE_NAME stopping ..."
            kill $PID;
            echo "$SERVICE_NAME stopped ..."
            rm $PID_PATH_NAME
        else
            echo "$SERVICE_NAME is not running ..."
        fi
    ;;
    restart)
        if [ -f $PID_PATH_NAME ]; then
            PID=$(cat $PID_PATH_NAME);
            echo "$SERVICE_NAME stopping ...";
            kill $PID;
            echo "$SERVICE_NAME stopped ...";
            rm $PID_PATH_NAME
            echo "$SERVICE_NAME starting ..."
            nohup sudo -u vireo4 java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &
            echo $! > $PID_PATH_NAME
            echo "$SERVICE_NAME started ..."
        else
            echo "$SERVICE_NAME is not running ..."
        fi
    ;;
esac 

Set the permissions:

sudo chmod 0764 vireo4

Start with the command:

service vireo4 start

To test:

sudo reboot 

Run with SSL Proxy

Since you are running on port 8080 you will likely want to have vireo4 served via a proxy server with SSL.

Post Install

Register

Register your account on the vireo4 website.

Grant privileges

There are 4 types of accounts: Admin, Manager, Reviewer, and Student. The Admin account will manage the site for the whole institution. You may need to manually set an initial Administrative permission on an account. This account can then be used to set permissions on other accounts through the user interface.

sudo su - postgres
psql
postgres=# UPDATE weaver_users SET role='ROLE_ADMIN' WHERE id=[user_id_in_weaver_users_table_you_want_to_make_admin];
postgres=#\q
exit

Database backups

While signed in under the unix vireo account create a directory for the backups and create a crontab entry

> mkdir /home/vireo/backups/
> crontab -e

Create an entry such as:

0 1 * * * pg_dump vireo > /home/vireo/backups/vireo_backup_`date +\%Y_\%m_\%dT\%H:\%M:\%S`.sql

This creates a file in your backups directory with a date stamp such as:

vireo_backup_2019_05_13T09:53:47.sql

To restore use:

> sudo -u postgres psql
postgres=# DROP DATABASE vireo;
postgres=# CREATE DATABASE vireo;
postgres=# \q
> sudo -u postgres psql -U postgres vireo < /tmp/vireo_backup_2019_05_13T09\:53\:47.sql 

Then restart:

> nohup java -jar target/vireo-4.0.0-SNAPSHOT.war &

Miscellaneous

If you are having trouble accessing your database, verify the port on which which PostgreSQL is running. The default is 5432.

sudo -u postgres psql
postgres=# SELECT * FROM pg_settings WHERE name = 'port';
postgres=# \q
exit

If you prefer running vireo4 as a jar file this can be generated by changing one line in the pom.xml file:

Edit pom.xml to use jar instead of war. Change:

  <packaging>war</packaging>

to

  <packaging>jar</packaging>