-
Notifications
You must be signed in to change notification settings - Fork 4
Install Script
Krzysiek Madejski edited this page May 31, 2017
·
37 revisions
#!/bin/bash
:' This script is a valid Markdown document and bash script in its raw form. Script should be run partly (in paragraphs) to add occasional keyboard input and handle errors that may come up due to different server configuration.'
:' This script was tested on: Ubuntu 14.04 LTS.'
:' Requirements versions: Postgres 9.0 or later.'
sudo su
apt-get update
apt-get -y install linux-headers-generic
apt-get -y install python-dev postgresql libpq-dev python-pip solr-jetty vim build-essential libxslt1-dev libxml2-dev git supervisor libffi-dev libjpeg-dev redis-server
apt-get -y install apache2 libapache2-mod-wsgi # If using apache
# 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
adduser ckan
adduser ckan sudo # For convenience, will be unsudoed later
adduser datapusher --system --no-create-home
addgroup ckan-logs
addgroup ckan-data
adduser www-data ckan-logs
adduser www-data ckan-data
adduser datapusher ckan-data
adduser datapusher ckan-logs
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 ckan:ckan-logs /var/log/ckan
ln -s /var/log/$JETTYV/ /var/log/ckan/solr-jetty
chmod 755 /var/log/$JETTYV
sudo -u ckan mkdir /home/ckan/data -m=775
sudo -u ckan mkdir /home/ckan/data/archiver -m=775
chgrp -R ckan-data /home/ckan/data
:'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/ckan/.bashrc
echo 'source /usr/local/bin/virtualenvwrapper_lazy.sh' >> /home/ckan/.bashrc
su ckan
cd /home/ckan
mkdir ~/.virtualenvs
mkvirtualenv ckan -p /usr/bin/python2.7
wget https://raw.githubusercontent.com/DanePubliczneGovPl/ckanext-danepubliczne/master/requirements-danepublicznegovpl.txt
pip install -r requirements-danepublicznegovpl.txt
ln -s /home/ckan/.virtualenvs/ckan/src /home/ckan/src
mkvirtualenv datapusher -p /usr/bin/python2.7
pip install -e git+https://github.com/DanePubliczneGovPl/datapusher@develop#egg=datapusher
pip install -r /home/ckan/.virtualenvs/datapusher/src/datapusher/requirements.txt
workon ckan
:'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
sudo mkdir /etc/ckan
cp prod.default.ini prod.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 >> prod.ini
grep app_instance_uuid template.ini >> prod.ini
vim +/"Make sure following settings are correct" prod.ini
sudo cp prod.ini /etc/ckan/
sudo cp who.ini /etc/ckan/
sudo cp ckan.py /etc/ckan/
sudo cp celery-supervisor.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
sudo cp datapusher.apache2-4.conf /etc/apache2/sites-available/datapusher.conf
sudo cp ckan.conf /etc/apache2/sites-available/000-ckan.conf
sudo cp datapusher.wsgi /etc/ckan/
sudo cp datapusher_settings.py /etc/ckan/
# export CKAN_INI so it doesn't have to be specified on command line
export CKAN_INI=/etc/ckan/prod.ini
echo 'export CKAN_INI=/etc/ckan/prod.ini' >> /home/ckan/.bashrc
# Fix for Ubuntu 14.04, TODO is it needed for 15, 17?
# sudo sh -c "echo /usr/share/java/tomcat-coyote.jar >> /etc/$JETTYV/start.config"
# open up port 8800 on Apache where the DataPusher accepts connections.
# make sure this line appear only once in /etc/apache2/ports.conf.
sudo sh -c 'echo "Listen 8800" >> /etc/apache2/ports.conf'
sudo sh -c 'echo "ServerName danepubliczne.gov.pl" >> /etc/apache2/apache2.conf'
sudo a2ensite 000-ckan
sudo a2ensite datapusher
sudo rm /etc/apache2/sites-enabled/000-default.conf > /dev/null
sudo -u postgres psql -c "CREATE USER ckan WITH PASSWORD 'ckan';"
sudo -u postgres createdb -O ckan ckan -E utf-8
# This DB should probably go on a separate server
sudo -u postgres psql -c "CREATE USER datastore WITH PASSWORD 'datastore';"
sudo -u postgres createdb -O ckan datastore -E utf-8
sudo service $JETTYV start
paster --plugin=ckan 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-qa qa init
paster --plugin=ckanext-report report initdb
sudo apt-get -y install unzip libapache2-mod-php5 php5 php5-mysql mysql-server
cd /home/ckan
wget http://builds.piwik.org/piwik.zip
unzip piwik.zip
rm "How to install Piwik.html" piwik.zip
cd piwik
sudo chgrp -R www-data tmp config
sudo chmod g+w -R tmp config
# Webserver
sudo a2enmod ssl proxy
sudo apachectl restart
# Celery tasks run by supervisor
sudo supervisorctl reread
sudo supervisorctl update
# Page tracking
sudo ln -s /home/ckan/src/ckanext-danepubliczne/scripts/cron.d/ckan-tracking /etc/cron.d/ckan-tracking
sudo ln -s /home/ckan/src/ckanext-danepubliczne/scripts/cron.d/reports_qa /etc/cron.d/reports_qa
sudo chmod u+x /home/ckan/src/ckanext-danepubliczne/scripts/ckan-tracking.sh
# Use this api-key to import data
sudo -u postgres psql -d ckan -c "SELECT apikey FROM public.user WHERE name = 'danepubliczne.gov.pl';"
# If you're not importing data, you have to at list create metadata vocabularies
paster --plugin=ckanext-danepubliczne init required
# TODO open http://stats.danepubliczne.gov.pl and configure piwik
# Lock password access & remove ckan from sudo
sudo usermod --lock ckan
sudo deluser ckan sudo
# Check logs for errors
tail -f /var/log/ckan/ckan.error.log