Skip to content

GoKB 7.x Installation and Bootstrapping Guide

Ian Ibbotson edited this page Dec 13, 2016 · 14 revisions

This document explains how to set up a local clean gokb server and synchronise the data with the live GoKB server.

Base Server

These instructions are based upon an AWS t2.large EC2 instance running (Ubuntu Server 16.04 LTS (HVM), SSD Volume Type - ami-0d77397e).

Background

Always worth checking base packages are up to date

sudo su - root
apt-get update
apt-get dist-upgrade

Required Dependencies

Java

gokb needs java 8. The Webupd8 team provide a ppa: https://launchpad.net/~webupd8team/+archive/ubuntu/java

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
apt-get install oracle-java8-installer
## Accept the license agreement screen

Tomcat

The app needs a java container - tomcat is the default deployment choice. See the info at https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-ubuntu-16-04 for more details. Tomcat can be installed as a user space process, this document sets out a systemd approach.

apt-get install tomcat8

We add a setenv.sh file in /usr/share/tomcat8/bin/setenv.sh

#!/bin/sh
export JAVA_HOME="/usr/lib/jvm/java-8-oracle"
export JRE_HOME="/usr/lib/jvm/java-8-oracle"
export JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true -server -Xms768m -Xmx3g -Dfile.encoding=UTF-8 -Dusrsetenv=1 -noverify "
export CLASSPATH="$CLASSPATH:$JAVA_HOME/lib/tools.jar"

This will also create a tomcat user with a home directory of /usr/share/tomcat8. This is important as the app will need a ~/.grails/gokb-config.groovy file.

Elasticsearch

v7 is tested against ES 2.4.1. As root::

wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.4.1/elasticsearch-2.4.1.deb
dpkg --install ./elasticsearch-2.4.1.deb

PostgreSQL

GOKb 7 has migrated to PostgreSQL. PostgreSQL can be installed directly or via docker. This document uses a local install.

apt-get install postgresql

The default app config insulates installers from postgres location by using a domain name of pghost in the config. If you're using a local install, add pghost to /etc/localhost as follows

127.0.0.1 localhost pghost

Configuration

The app relies upon a configuration file. Since we are deploying using systemd, become the tomcat user and create a folder

mkdir /usr/share/tomcat8/.grails

And add the following contents to /usr/share/tomcat8/.grails/gokb-config.groovy

grails.plugins.springsecurity.ui.forgotPassword.emailFrom='[email protected]'
grails.plugins.springsecurity.ui.register.emailFrom = '[email protected]'
grails.plugins.springsecurity.ui.forgotPassword.emailSubject = 'GoKB Forgotten Password'
gokb.theme='yeti'  // spacelab,cosmo,cyborg,yeti
gokb.es.cluster='elasticsearch'
serverUrl='https://your.public.domain.name/gokb'

grails {
  mail {
    host = "Email Hostname"
    port = Email-port
    username = "Email Username"
    password = "Email Password"
    props = ["mail.smtp.auth":"false",
             "mail.smtp.socketFactory.port":"465",
             "mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
             "mail.smtp.socketFactory.fallback":"false"]
  }
}

searchApi = [
  'path'        : '/es/',
  'indices'     : 'gokb',
  'types'       : 'component',
  'typingField' : 'componentType',
  'port'        : 443
]

// newDash=true

Database Configuration

As root

sudo su - postgres
psql
CREATE DATABASE gokb;
CREATE USER knowint WITH PASSWORD 'knowint';
GRANT ALL PRIVILEGES ON DATABASE gokb to knowint;
\q

(These values match the default values in the war file [prod] configuration)

Application Install

Download and install

You can grab war from github or build yourself locally --

service tomcat8 stop
cd /var/lib/tomcat8/webapps
wget https://github.com/k-int/gokb-phase1/releases/download/v7.0.24/gokb-7.0.24.war
mv gokb-7.0.24.war gokb.war
chown tomcat8:tomcat8 gokb.war

Tomcat should autodeploy the war. If you downloaded the war as root, the deployment folder should still be owned by tomcat8:tomcat8

Startup

tomcat can be stopped/started as root with

service tomcat8 start

or later on

service tomcat8 restart

Validate/Test Installation

Check /var/log/tomcat8/catalina.out for any obvious errors, then check the DB (As root)

psql -h pghost --password gokb knowint
    ## Password knowint or your local variant
\dt
    ## You should see gokb tables including title_instance - 
\d title_instance
    ## You should see the table definition for title_instance

Sync Scripts

The sync scripts are written using groovysh, sdkman is a handy way to manage groovy and grails installations:

sudo apt-get install zip
curl -s "https://get.sdkman.io" | bash
source "/home/ubuntu/.sdkman/bin/sdkman-init.sh"     # Only needed first time
sdk use groovy
# Prompted, reply "Y"

It's probably best to clone the source repository to get the scripts

git clone https://github.com/k-int/gokb-phase1.git
git checkout ebooks-pilot
cd scripts

We assume your purpose in cloning here is to copy the data rather than create a like-for-like duplicate of the gokb server (With users, curatorial groups, etc, etc). The order is important - we suggest Orgs, Titles, Platforms, Packages

Orgs Data

Get orgs data. Create a config file for orgs upload - edit ./sync-gokb-orgs-cfg.json and add the following. You may adjust values to match local upload user/pass account.

{
    "uploadUser":"admin",
    "uploadPass":"admin",
    "resumptionToken":null
}

And run the update

groovy ./sync_gokb_orgs.groovy

First time through grape will download all required dependencies, may take a moment... Eventually you should see status messages downloading blocks of orgs data and then a series of 200 OK responses showing that orgs are being loaded.

Check the orgs loaded::

psql -h pghost --password gokb knowint
## Enter knowint pw
select o.kbc_id, c.kbc_name from kbcomponent as c join org as o on c.kbc_id = o.kbc_id;

Title Data

Get titles data. Create a config file for titles upload - edit ./sync-gokb-titles-cfg.json and add the following. You may adjust values to match local upload user/pass account.

{
    "uploadUser":"admin",
    "uploadPass":"admin",
    "resumptionToken":null
}

And run the update

groovy ./sync_gokb_titles.groovy