LXCize Sigmah setup

This commit is contained in:
Disassembler 2018-09-14 09:09:46 +02:00
parent d1991ddc7d
commit f74586c94c
Signed by: Disassembler
GPG Key ID: 524BD33A0EE29499
2 changed files with 16 additions and 26 deletions

View File

@ -1,28 +1,21 @@
#!/bin/sh
set -e
SOURCE_DIR=$(realpath $(dirname "${0}"))/sigmah
SOURCE_DIR=$(realpath $(dirname "${0}"))/setup
# Check prerequisites
lxc-ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh
lxc-ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh
service postgres start
# Build Docker container
docker build -t sigmah ${SOURCE_DIR}
cp ${SOURCE_DIR}/etc/init.d/sigmah /etc/init.d/sigmah
rc-update -u
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
# Create database
export SIGMAH_PWD=$(head -c 18 /dev/urandom | base64)
envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql
envsubst <${SOURCE_DIR}/createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
# Configure Sigmah
mkdir -p /srv/sigmah/conf /srv/sigmah/data/files /srv/sigmah/data/archives
chown -R 8011:8011 /srv/sigmah/data
envsubst <${SOURCE_DIR}/srv/sigmah/conf/persistence.xml >/srv/sigmah/conf/persistence.xml
cp ${SOURCE_DIR}/srv/sigmah/conf/sigmah.properties /srv/sigmah/conf/sigmah.properties
docker run --rm -v /srv/sigmah/data:/srv/sigmah/data sigmah cp /srv/tomcat/webapps/sigmah/sigmah/images/header/org-default-logo.png /srv/sigmah/data/files/logo.png
cp /var/lib/lxc/sigmah/sigmah/srv/tomcat/webapps/sigmah/sigmah/images/header/org-default-logo.png /srv/sigmah/data/files/logo.png
# Populate database
wget https://github.com/sigmah-dev/sigmah/releases/download/v2.0.2/sigmah-MinimumDataKit-2.0.postgresql.sql -O /tmp/sigmah-MinimumDataKit.sql
@ -30,6 +23,7 @@ wget https://github.com/sigmah-dev/sigmah/releases/download/v2.0.2/sigmah-newOrg
export SIGMAH_ADMIN_USER=Admin
export SIGMAH_ADMIN_EMAIL=admin@example.com
export SIGMAH_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
# TODO: python-bcrypt
apk --no-cache add apache2-utils
export SIGMAH_ADMIN_HASH=$(htpasswd -bnBC 10 "" ${SIGMAH_ADMIN_PWD} | tr -d ':\n' | sed 's/$2y/$2a/')
apk --no-cache del apache2-utils
@ -41,10 +35,14 @@ sed -i "s|§UserName§|${SIGMAH_ADMIN_USER}|g" /tmp/sigmah-newOrganizationLaunch
sed -i "s|§UserFirstName§|${SIGMAH_ADMIN_USER}|g" /tmp/sigmah-newOrganizationLaunchScript.sql
sed -i "s|§UserLocale§|en|g" /tmp/sigmah-newOrganizationLaunchScript.sql
sed -i "s|\$2a\$10\$pMcTA1p9fefR8U9NoOPei.H0eq/TbbdSF27M0tn9iDWBrA4JHeCDC|${SIGMAH_ADMIN_HASH}|" /tmp/sigmah-newOrganizationLaunchScript.sql
cat /tmp/sigmah-MinimumDataKit.sql | docker exec -i -e PGPASSWORD=${SIGMAH_PWD} postgres psql -U sigmah sigmah
cat /tmp/sigmah-newOrganizationLaunchScript.sql | docker exec -i -e PGPASSWORD=${SIGMAH_PWD} postgres psql -U sigmah sigmah
cat /tmp/sigmah-MinimumDataKit.sql | lxc-attach postgres -- sh -c "PGPASSWORD=${SIGMAH_PWD} psql -U sigmah sigmah"
cat /tmp/sigmah-newOrganizationLaunchScript.sql | lxc-attach postgres -- sh -c "PGPASSWORD=${SIGMAH_PWD} postgres psql -U sigmah sigmah"
rm -f /tmp/sigmah-MinimumDataKit.sql /tmp/sigmah-newOrganizationLaunchScript.sql
vmmgr update-login sigmah "${SIGMAH_ADMIN_EMAIL}" "${SIGMAH_ADMIN_PWD}"
# Install service
cp ${SOURCE_DIR}/etc/init.d/sigmah /etc/init.d/sigmah
rc-update -u
# Stop services required for build
service postgres stop
[ ! -z ${STOP_POSTGRES} ] && service postgres stop

View File

@ -1,21 +1,13 @@
#!/sbin/openrc-run
description="Sigmah docker container"
description="Sigmah container"
depend() {
need docker postfix postgres
need cgroups postgres
}
start() {
/usr/bin/docker run -d --rm \
--name sigmah \
-h sigmah \
--link postfix \
--link postgres \
-v /srv/sigmah/data:/srv/sigmah/data \
-v /srv/sigmah/conf/persistence.xml:/srv/tomcat/webapps/sigmah/WEB-INF/classes/META-INF/persistence.xml \
-v /srv/sigmah/conf/sigmah.properties:/srv/tomcat/webapps/sigmah/WEB-INF/classes/sigmah.properties \
sigmah
lxc-start sigmah
}
start_post() {
@ -27,5 +19,5 @@ stop_pre() {
}
stop() {
/usr/bin/docker stop sigmah
lxc-stop sigmah
}