<commit_before># Grasshopper Event Engine

Puppet configuration and environment management for the Grasshopper event engine.

## Environments

 * The app server logs can be found at /opt/grasshopper/server.log
 * If you make changes to the backend code you will need to restart the app server. This can be done by ssh'ing into the client machine by running `service grasshopper restart`.
 * Even if you'd install all the components on your host OS, you would not be able to run the server as some of the npm modules are compiled during the provisioning step.

### Dev Environment

```
# Provision an Ubuntu Trusty server (e.g. on EC2)
# Then:
local$ ssh devserver.ontheinternet
devserver$ sudo apt-get update
devserver$ sudo apt-get install git
devserver$ sudo git clone git://github.com/CUL-DigitalServices/grasshopper-puppet /opt/grasshopper-puppet
devserver$ cd /opt/grasshopper-puppet
# Edit common.json to make web_domain match your new server's hostname
devserver$ sudo vim environments/dev/hiera/common.json
# Set username and password to protect externally visible server with play data in
devserver$ sudo apt-get install apache2-utils
devserver$ sudo htpasswd -bc /etc/apache2/dev_auth_file #username# #password#
# Copy some timetable data to import onto the server
local$ scp timetabledata.json devserver.ontheinternet:/tmp/timetabledata.json
# Back to the server to run puppet
devserver$ sudo ./provisioning/grasshopper/init.sh

# Now we have a server, put some data in it:
devserver$ ./provisioning/setup-via-api.sh admin.devserver.ontheinternet devserver.ontheinternet
devserver$ sudo stop grasshopper
# This next step could take up to around 30mins if you have a slow server and lots of data!
devserver$ sudo node /opt/grasshopper/etc/scripts/data/timetable-import.js -f /tmp/timetabledata.json -a 1
devserver$ sudo start grasshopper

# You can monitor grasshopper's logs:
devserver$ sudo tail -f /var/log/upstart/grasshopper.log

## TODO some of the above steps will be automated
## NOTE: you may get some of the following warnings and errors, but these can safely be ignored:
- Warning: Setting templatedir is deprecated ...
- Could not retrieve fact='apt_updates'...
- Could not retrieve fact='apt_security_updates'...
(Last two pertain to /usr/lib/update-notifier/apt-check)<commit_msg>Warn not to change hostname<commit_after># Grasshopper Event Engine

Puppet configuration and environment management for the Grasshopper event engine.

## Environments

 * The app server logs can be found at /opt/grasshopper/server.log
 * If you make changes to the backend code you will need to restart the app server. This can be done by ssh'ing into the client machine by running `service grasshopper restart`.
 * Even if you'd install all the components on your host OS, you would not be able to run the server as some of the npm modules are compiled during the provisioning step.

### Dev Environment

```
## TODO some of these steps will be automated

# Provision an Ubuntu Trusty server (e.g. on EC2)
# Then:
local$ ssh devserver.ontheinternet
devserver$ sudo apt-get update
devserver$ sudo apt-get install git
devserver$ sudo git clone git://github.com/CUL-DigitalServices/grasshopper-puppet /opt/grasshopper-puppet
devserver$ cd /opt/grasshopper-puppet
# Edit common.json to make web_domain match your new server's hostname
devserver$ sudo vim environments/dev/hiera/common.json
# Set username and password to protect externally visible server with play data in
devserver$ sudo apt-get install apache2-utils
devserver$ sudo htpasswd -bc /etc/apache2/dev_auth_file #username# #password#
# Copy some timetable data to import onto the server
local$ scp timetabledata.json devserver.ontheinternet:/tmp/timetabledata.json
# Back to the server to run puppet
devserver$ sudo ./provisioning/grasshopper/init.sh

# Now we have a server, put some data in it:
devserver$ ./provisioning/setup-via-api.sh admin.devserver.ontheinternet devserver.ontheinternet
devserver$ sudo stop grasshopper
# This next step could take up to around 30mins if you have a slow server and lots of data!
devserver$ sudo node /opt/grasshopper/etc/scripts/data/timetable-import.js -f /tmp/timetabledata.json -a 1
devserver$ sudo start grasshopper

# You can monitor grasshopper's logs:
devserver$ sudo tail -f /var/log/upstart/grasshopper.log

## HANDY HINT, especially for EC2 users (and similar)
## You may want to avoid changing your hostname - either get a static IP, or don't shutdown!
## Otherwise reconfiguring the system with a new hostname might be fiddly
## (Have not yet tested/audited how fiddly or whether puppet will fix it all;
##  but for instance, the setup-via-api.sh script won't know how to rename an app etc)

## NOTE: you may get some of the following warnings and errors, but these can safely be ignored:
- Warning: Setting templatedir is deprecated ...
- Could not retrieve fact='apt_updates'...
- Could not retrieve fact='apt_security_updates'...
(Last two pertain to /usr/lib/update-notifier/apt-check)
{'fraction_non_alphanumeric': 0.07231322413104276, 'fraction_numerical': 0.0025968837395125848, 'mean_word_length': 4.588169642857143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5334171', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1425, 'n_words': 632}