CKAN setup

This commit is contained in:
Disassembler 2018-09-12 11:44:30 +02:00
parent cff204ca46
commit bc4c073b43
Signed by: Disassembler
GPG Key ID: 524BD33A0EE29499
2 changed files with 18 additions and 13 deletions

View File

@ -36,6 +36,10 @@ SCRIPT
pip install -r /srv/ckan/src/ckanext-spatial/pip-requirements.txt pip install -r /srv/ckan/src/ckanext-spatial/pip-requirements.txt
pip install -r /srv/ckan/src/ckanext-dgvat-xls/requirements.txt pip install -r /srv/ckan/src/ckanext-dgvat-xls/requirements.txt
# Create mountpoints
mkdir /etc/ckan
mkdir /srv/ckan/storage
# Create OS user # Create OS user
addgroup -S -g 8003 ckan addgroup -S -g 8003 ckan
adduser -S -u 8003 -h /srv/ckan -s /bin/false -g ckan -G ckan ckan adduser -S -u 8003 -h /srv/ckan -s /bin/false -g ckan -G ckan ckan

View File

@ -4,17 +4,18 @@ set -e
SOURCE_DIR=$(realpath $(dirname "${0}"))/setup SOURCE_DIR=$(realpath $(dirname "${0}"))/setup
# Check prerequisites # Check prerequisites
service postgres start # TODO: Have setup prereqs in a manifest file
service redis start for SERVICE in postgres redis solr; do
service solr start [ ! -e /run/openrc/started/${SERVICE} ] && service ${SERVICE} start && STOP_SERVICES="${STOP_SERVICES} ${SERVICE}"
done
# Create database # Create database
export CKAN_PWD=$(head -c 18 /dev/urandom | base64) export CKAN_PWD=$(head -c 18 /dev/urandom | base64)
export CKAN_DS_PWD=$(head -c 18 /dev/urandom | base64) export CKAN_DS_PWD=$(head -c 18 /dev/urandom | base64)
envsubst <${SOURCE_DIR}/createdb.sql | lxc-attach postgres -- /bin/s6-setuidgid 5432:5432 psql envsubst <${SOURCE_DIR}/createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
# Configure CKAN Solr core # Configure CKAN Solr core
# TODO lxc-execute solr -- solr create -p 8983 -c ckan lxc-attach -u 8983 -g 8983 solr -- /usr/bin/solr create -p 8983 -c ckan
cp ${SOURCE_DIR}/srv/solr/data/ckan/conf/schema.xml /srv/solr/data/ckan/conf/schema.xml cp ${SOURCE_DIR}/srv/solr/data/ckan/conf/schema.xml /srv/solr/data/ckan/conf/schema.xml
cp ${SOURCE_DIR}/srv/solr/data/ckan/conf/solrconfig.xml /srv/solr/data/ckan/conf/solrconfig.xml cp ${SOURCE_DIR}/srv/solr/data/ckan/conf/solrconfig.xml /srv/solr/data/ckan/conf/solrconfig.xml
chown 8983:8983 /srv/solr/data/ckan/conf/schema.xml chown 8983:8983 /srv/solr/data/ckan/conf/schema.xml
@ -26,6 +27,7 @@ export CKAN_SECRET=$(head -c 18 /dev/urandom | base64)
export CKAN_UUID=$(cat /proc/sys/kernel/random/uuid) export CKAN_UUID=$(cat /proc/sys/kernel/random/uuid)
envsubst <${SOURCE_DIR}/srv/ckan/conf/ckan.ini >/srv/ckan/conf/ckan.ini envsubst <${SOURCE_DIR}/srv/ckan/conf/ckan.ini >/srv/ckan/conf/ckan.ini
cp ${SOURCE_DIR}/srv/ckan/conf/who.ini /srv/ckan/conf/who.ini cp ${SOURCE_DIR}/srv/ckan/conf/who.ini /srv/ckan/conf/who.ini
chown -R 8003:8003 /srv/ckan/data
# Set "production values" (increases performance) only if the DEBUG environment variable is not set # Set "production values" (increases performance) only if the DEBUG environment variable is not set
if [ ${DEBUG:-0} -eq 0 ]; then if [ ${DEBUG:-0} -eq 0 ]; then
@ -35,17 +37,16 @@ fi
# Populate database # Populate database
lxc-execute ckan -- /usr/bin/paster --plugin=ckan db init -c /etc/ckan/ckan.ini lxc-execute ckan -- /usr/bin/paster --plugin=ckan db init -c /etc/ckan/ckan.ini
lxc-execute ckan -- /usr/bin/paster --plugin=ckanext-spatial spatial initdb -c /etc/ckan/ckan.ini lxc-execute ckan -- /usr/bin/paster --plugin=ckanext-spatial spatial initdb -c /etc/ckan/ckan.ini
lxc-execute ckan -- /usr/bin/paster --plugin=ckan datastore set-permissions -c /etc/ckan/ckan.ini | lxc-attach postgres -- /bin/s6-setuidgid 5432:5432 psql lxc-execute ckan -- /usr/bin/paster --plugin=ckan datastore set-permissions -c /etc/ckan/ckan.ini | lxc-attach -u 5432 -g 5432 postgres -- /usr/bin/psql
chown -R 8003:8003 /srv/ckan/data # TODO: re)move as uid is now correct ?
# Create admin account # Create admin account
export CKAN_ADMIN_USER="admin" export CKAN_ADMIN_USER="admin"
export CKAN_ADMIN_UUID=$(cat /proc/sys/kernel/random/uuid) export CKAN_ADMIN_UUID=$(cat /proc/sys/kernel/random/uuid)
export CKAN_ADMIN_APIKEY=$(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) export CKAN_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
export CKAN_ADMIN_HASH=$(docker run --rm ckan python -c "from passlib.hash import pbkdf2_sha512;print pbkdf2_sha512.encrypt('${CKAN_ADMIN_PWD}')") export CKAN_ADMIN_HASH=$(lxc-execute ckan -- /usr/bin/python -c "from passlib.hash import pbkdf2_sha512;print pbkdf2_sha512.encrypt('${CKAN_ADMIN_PWD}')")
export CKAN_ADMIN_EMAIL="admin@example.com" export CKAN_ADMIN_EMAIL="admin@example.com"
envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i postgres psql ckan envsubst <${SOURCE_DIR}/adminpwd.sql | lxc-attach -u 5432 -g 5432 postgres -- /usr/bin/psql ckan
vmmgr update-login ckan "${CKAN_ADMIN_USER}" "${CKAN_ADMIN_PWD}" vmmgr update-login ckan "${CKAN_ADMIN_USER}" "${CKAN_ADMIN_PWD}"
# Install cron job # Install cron job
@ -55,7 +56,7 @@ cp ${SOURCE_DIR}/etc/periodic/hourly/ckan /etc/periodic/hourly/ckan
cp ${SOURCE_DIR}/etc/init.d/ckan /etc/init.d/ckan cp ${SOURCE_DIR}/etc/init.d/ckan /etc/init.d/ckan
rc-update -u rc-update -u
# Stop services required for build # Stop services required for setup
service solr stop for SERVICE in ${STOP_SERVICES}; do
service redis stop service ${SERVICE} stop
service postgres stop done