Spotter-VM/lxc-apps/ckan/install.sh

81 lines
3.2 KiB
Bash
Raw Normal View History

2019-09-18 11:29:58 +02:00
#!/bin/sh
set -ev
# Create Postgres instance
mkdir -p /srv/ckan/postgres_data
chown -R 105432:105432 /srv/ckan/postgres_data
chmod 700 /srv/ckan/postgres_data
2019-09-24 19:49:02 +02:00
lxc-execute -n ckan-postgres -- initdb -D /var/lib/postgresql
2019-09-18 11:29:58 +02:00
# Configure Postgres
cp postgres_data/postgresql.conf /srv/ckan/postgres_data/postgresql.conf
cp postgres_data/pg_hba.conf /srv/ckan/postgres_data/pg_hba.conf
# Create database
export CKAN_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
export CKAN_DS_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
2019-11-30 22:11:38 +01:00
service lxc-ckan-postgres start
2019-09-24 19:49:02 +02:00
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 ckan-postgres -- psql
2019-09-18 11:29:58 +02:00
# Configure Redis
mkdir -p /srv/ckan/redis_conf /srv/ckan/redis_data
cp redis_conf/redis.conf /srv/ckan/redis_conf/redis.conf
2019-09-27 11:28:00 +02:00
chown -R 100000:100000 /srv/ckan/redis_conf
2019-09-18 11:29:58 +02:00
chown -R 106379:106379 /srv/ckan/redis_data
2019-11-30 22:11:38 +01:00
service lxc-ckan-redis start
2019-09-18 11:29:58 +02:00
# Configure Solr
mkdir -p /srv/ckan/solr_data
2019-09-24 19:49:02 +02:00
lxc-execute ckan-solr -- cat /opt/solr/server/solr/solr.xml >/srv/ckan/solr_data/solr.xml
2019-09-18 11:29:58 +02:00
chown -R 108983:108983 /srv/ckan/solr_data
2019-11-30 22:11:38 +01:00
service lxc-ckan-solr start
2019-09-18 11:29:58 +02:00
# Configure CKAN Solr core
2019-09-27 11:28:00 +02:00
lxc-attach -u 8983 -g 8983 ckan-solr -- solr create -p 8983 -c ckan
2019-11-30 22:11:38 +01:00
service lxc-ckan-solr stop
2019-09-18 11:29:58 +02:00
cp solr_data/ckan/conf/schema.xml /srv/ckan/solr_data/ckan/conf/schema.xml
cp solr_data/ckan/conf/solrconfig.xml /srv/ckan/solr_data/ckan/conf/solrconfig.xml
2019-09-27 11:28:00 +02:00
chown -R 108983:108983 /srv/ckan/solr_data
2019-11-30 22:11:38 +01:00
service lxc-ckan-solr start
2019-09-18 11:29:58 +02:00
# Configure CKAN DataPusher
mkdir -p /srv/ckan/datapusher_conf /srv/ckan/datapusher_data
cp datapusher_conf/datapusher.wsgi /srv/ckan/datapusher_conf/datapusher.wsgi
cp datapusher_conf/datapusher_settings.py /srv/ckan/datapusher_conf/datapusher_settings.py
2019-09-27 11:28:00 +02:00
chown -R 100000:100000 /srv/ckan/datapusher_conf
2019-09-18 11:29:58 +02:00
chown -R 108080:108080 /srv/ckan/datapusher_data
# Configure CKAN
mkdir -p /srv/ckan/ckan_conf /srv/ckan/ckan_data
export CKAN_SECRET=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
export CKAN_UUID=$(cat /proc/sys/kernel/random/uuid)
envsubst <ckan_conf/ckan.ini >/srv/ckan/ckan_conf/ckan.ini
cp ckan_conf/who.ini /srv/ckan/ckan_conf/who.ini
2019-09-27 11:28:00 +02:00
chown -R 100000:100000 /srv/ckan/ckan_conf
2019-09-18 11:29:58 +02:00
chown -R 108080:108080 /srv/ckan/ckan_data
# Populate database
2019-09-24 19:15:40 +02:00
lxc-execute ckan -- paster --plugin=ckan db init -c /etc/ckan/ckan.ini
lxc-execute ckan -- paster --plugin=ckanext-spatial spatial initdb -c /etc/ckan/ckan.ini
2019-09-24 19:49:02 +02:00
lxc-execute ckan -- paster --plugin=ckan datastore set-permissions -c /etc/ckan/ckan.ini | lxc-attach -u 5432 -g 5432 ckan-postgres -- psql
2019-09-18 11:29:58 +02:00
# Create admin account
export CKAN_ADMIN_USER="admin"
export CKAN_ADMIN_UUID=$(cat /proc/sys/kernel/random/uuid)
export CKAN_ADMIN_APIKEY=$(cat /proc/sys/kernel/random/uuid)
export CKAN_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
2019-09-24 19:15:40 +02:00
export CKAN_ADMIN_HASH=$(lxc-execute ckan -- python -c "from passlib.hash import pbkdf2_sha512;print pbkdf2_sha512.encrypt('${CKAN_ADMIN_PWD}')")
2019-09-18 11:29:58 +02:00
export CKAN_ADMIN_EMAIL="admin@example.com"
2019-09-24 19:49:02 +02:00
envsubst <adminpwd.sql | lxc-attach -u 5432 -g 5432 ckan-postgres -- psql ckan
2019-09-18 11:29:58 +02:00
# Install config update script
cp update-conf.sh /srv/ckan/update-conf.sh
# Stop services required for setup
2019-11-30 22:11:38 +01:00
service lxc-ckan-solr stop
service lxc-ckan-postgres stop
service lxc-ckan-redis stop
2019-09-18 11:29:58 +02:00
# Register application
vmmgr register-app ckan ckan "${CKAN_ADMIN_USER}" "${CKAN_ADMIN_PWD}"