Skip to content

Install Script dev version

Krzysiek Madejski edited this page May 31, 2017 · 14 revisions

#!/bin/bash

Install Dane Publiczne CKAN's site for development

:' This script is a valid Markdown document and bash script in its raw form. It's advised to run script partly to handle errors that may come up due to different server configuration.'

:' This script was tested on: Ubuntu 12, 14.04 LTS.'

:' Requirements versions: Postgres 9.0 or later.'

Install required packages

sudo su
apt-get update
apt-get -y install python-dev postgresql libpq-dev python-pip solr-jetty vim build-essential libxslt1-dev libxml2-dev git supervisor npm libjpeg-dev redis-server

# Install Oracle JDK
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/server-jre-8u131-linux-x64.tar.gz
mkdir /opt/jdk
tar -zxvf server-jre-8u131-linux-x64.tar.gz -C /opt/jdk
update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_131/bin/java 4108131
rm server-jre-8u131-linux-x64.tar.gz

Define users

export LOCALUSER=user # TODO change to your local account

addgroup ckan-logs
addgroup ckan-data

adduser $LOCALUSER ckan-logs 
adduser $LOCALUSER ckan-data

Create dir structure

export JETTYV=`ls -d /var/log/jetty* | cut -d "/" -f 4`

mkdir /var/log/ckan -m=775 # All logs go there [webserver, datapusher, celeryd]
chown $LOCALUSER:ckan-logs /var/log/ckan
ln -s /var/log/$JETTYV/ /var/log/ckan/solr-jetty
chmod 755 /var/log/$JETTYV

mkdir /home/ckan
chown $LOCALUSER:$LOCALUSER /home/ckan
sudo -u $LOCALUSER mkdir /home/ckan/data -m=775
sudo -u $LOCALUSER mkdir /home/ckan/data/archiver -m=775
chgrp -R ckan-data /home/ckan/data

Install Python VirtualEnv

:'see: http://simononsoftware.com/virtualenv-tutorial-part-2/'

pip install virtualenvwrapper
# Autoloads environment, so you can type anytime 'workon'
echo 'export WORKON_HOME=$HOME/.virtualenvs' >> /home/$LOCALUSER/.bashrc
echo 'source /usr/local/bin/virtualenvwrapper_lazy.sh' >> /home/$LOCALUSER/.bashrc

Create virtual env for ckan, download all plugins

CKAN + ckanext-danepubliczne

# switch to local user
su $LOCALUSER
cd /home/ckan
mkdir ~/.virtualenvs
mkvirtualenv ckan -p /usr/bin/python2.7

pip install -e [email protected]:DanePubliczneGovPl/[email protected]#egg=ckan
pip install -e [email protected]:DanePubliczneGovPl/ckanext-report@danepubliczne#egg=ckanext-report
pip install -e [email protected]:DanePubliczneGovPl/ckanext-archiver@danepubliczne#egg=ckanext-archiver    
pip install -e [email protected]:DanePubliczneGovPl/ckanext-qa@danepubliczne#egg=ckanext-qa
pip install -e [email protected]:DanePubliczneGovPl/ckanext-searchhistory@danepubliczne#egg=ckanext-searchhistory
pip install -e [email protected]:DanePubliczneGovPl/ckanext-danepubliczne@develop#egg=ckanext-danepubliczne
# TODO fork your own repo if you want to propose changes

Install pip dependencies

ln -s /home/$LOCALUSER/.virtualenvs/ckan/src /home/ckan/src    
pip install -r /home/ckan/src/ckan/requirements.txt
pip install -r /home/ckan/src/ckanext-archiver/requirements.txt

pip install -r /home/ckan/src/ckanext-archiver/dev-requirements.txt
pip install -r /home/ckan/src/ckanext-qa/dev-requirements.txt

pip install redis~=2.10

Create config files [TODO na deweloperke]

:'Update config files residing in /home/ckan/src/ckanext-danepubliczne/config if you did not follow exactly this configuration'

cd /home/ckan/src/ckanext-danepubliczne/config

cp dev.default.ini dev.ini
rm template.ini 2>/dev/null
paster make-config ckan template.ini > /dev/null # Creates unique values for some settings
grep beaker.session.secret template.ini >> dev.ini
grep app_instance_uuid template.ini >> dev.ini
 
cp celery-supervisor.conf celery-supervisor.dev.conf 
echo "user=$LOCALUSER" >> celery-supervisor.dev.conf
sudo ln -s /home/ckan/src/ckanext-danepubliczne/config/celery-supervisor.dev.conf /etc/supervisor/conf.d/ckan-celery.conf

sudo cp jetty /etc/default/$JETTYV

# With Ubuntu 17/jetty9 the structure of code has changed so two tweaks are needed
# 1) set jetty.port=8983 in /etc/jetty9/start.ini
# 2) sudo ln -s /etc/solr/solr-jetty.xml /var/lib/jetty9/webapps/solr.xml

sudo cp /home/ckan/src/ckan/ckan/config/solr/schema.xml /etc/solr/conf/schema.xml

# export CKAN_INI so it doesn't have to be specified on command line
export CKAN_INI=/home/ckan/src/ckanext-danepubliczne/config/dev.ini
echo 'export CKAN_INI=/home/ckan/src/ckanext-danepubliczne/config/dev.ini' >> /home/$LOCALUSER/.bashrc

# Fix for Ubuntu 14.04, 15 (is it needed?)
# sudo sh -c "echo /usr/share/java/tomcat-coyote.jar >> /etc/$JETTYV/start.config"

Create database for CKAN & Datastore extension

sudo -u postgres psql -c "CREATE USER ckan WITH PASSWORD 'ckan';"
sudo -u postgres createdb -O ckan ckan -E utf-8

sudo -u postgres psql -c "CREATE USER datastore WITH PASSWORD 'datastore';"
sudo -u postgres createdb -O ckan datastore -E utf-8

Initialize data

sudo service $JETTYV start

cd /home/ckan/src/ckan

paster datastore set-permissions | sudo -u postgres psql --set ON_ERROR_STOP=1
paster --plugin=ckan db init
paster --plugin=ckanext-archiver archiver init
paster --plugin=ckanext-report report initdb 
paster --plugin=ckanext-qa qa init
paster --plugin=ckanext-danepubliczne init required

# Register admin user and add sysadmins rights
paster user add admin [email protected] password=Password1
paster sysadmin add admin    

If you want to enable datapusher

sudo adduser datapusher --system --no-create-home
sudo adduser datapusher ckan-data
sudo adduser datapusher ckan-logs

cd /home/ckan/src/ckanext-danepubliczne/config
sudo cp datapusher.apache2-4.conf /etc/apache2/sites-available/datapusher.conf
sudo cp datapusher.wsgi /etc/ckan/
sudo cp datapusher_settings.py /etc/ckan/

mkvirtualenv datapusher -p /usr/bin/python2.7

pip install -e git+https://github.com/DanePubliczneGovPl/datapusher@develop#egg=datapusher
pip install -r /home/$LOCALUSER/.virtualenvs/datapusher/src/datapusher/requirements.txt 
workon ckan

Run the development server

# In another console/terminal start process that compiles css files
echo -n "Type enter and open new console to run this command" && read text
cd /home/ckan/src/ckan
npm install less nodewatch
# TODO install node
./bin/less

# In the main console Run the dev server
cd /home/ckan/src/ckan
workon ckan # Enable Python virtualenv  
paster serve /home/ckan/src/ckanext-danepubliczne/config/dev.ini --reload

Initialize with sample data (or)

# TODO init script with sample data (categories from https://github.com/DanePubliczneGovPl/infona-to-ckan/blob/master/epforgpl/infona_to_ckan/Process.py, user, datasets)
# 1. Login
# 2. Go to http://localhost:5000/group/new and create sample category
# 3. Go to http://localhost:5000/organization/new and add organization
# 4. Add dataset http://localhost:5000/dataset/new

Or import data

# Use this api-key to import data (if needed)
# sudo -u postgres psql -d ckan -c "SELECT apikey FROM public.user WHERE name = 'danepubliczne.gov.pl';"

Code in /home/ckan/src/ckanext-danepubliczne!