Rework Sigmah

This commit is contained in:
Disassembler 2019-10-05 15:34:42 +02:00
parent 4391b33fbc
commit 4ac414c691
Signed by: Disassembler
GPG Key ID: 524BD33A0EE29499
8 changed files with 55 additions and 54 deletions

View File

@ -3,23 +3,32 @@ set -ev
cd $(realpath $(dirname "${0}"))/install
# Check prerequisites
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
# Create Postgres instance
mkdir -p /srv/sigmah/postgres_data
chown -R 105432:105432 /srv/sigmah/postgres_data
chmod 700 /srv/sigmah/postgres_data
lxc-execute -n sigmah-postgres -- initdb -D /var/lib/postgresql
# Configure Postgres
cp postgres_data/postgresql.conf /srv/sigmah/postgres_data/postgresql.conf
cp postgres_data/pg_hba.conf /srv/sigmah/postgres_data/pg_hba.conf
# Create database
export SIGMAH_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
service sigmah-postgres start
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 sigmah-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 <srv/sigmah/conf/persistence.xml >/srv/sigmah/conf/persistence.xml
cp srv/sigmah/conf/sigmah.properties /srv/sigmah/conf/sigmah.properties
cp /var/lib/lxc/sigmah/sigmah/srv/tomcat/webapps/sigmah/sigmah/images/header/org-default-logo.png /srv/sigmah/data/files/logo.png
mkdir -p /srv/sigmah/sigmah_conf /srv/sigmah/sigmah_data/files /srv/sigmah/sigmah_data/archives
chown -R 108011:108011 /srv/sigmah/sigmah_data
envsubst <sigmah_conf/persistence.xml >/srv/sigmah/sigmah_conf/persistence.xml
cp sigmah_conf/sigmah.properties /srv/sigmah/sigmah_conf/sigmah.properties
chown -R 108011:108011 /srv/sigmah/sigmah_conf
lxc-execute sigmah -- cat /srv/tomcat/webapps/sigmah/sigmah/images/header/org-default-logo.png >/srv/sigmah/sigmah_data/files/logo.png
# Populate database
cp -f /var/lib/lxc/sigmah/sigmah/srv/sigmah-MinimumDataKit.sql /tmp/
cp -f /var/lib/lxc/sigmah/sigmah/srv/sigmah-newOrganizationLaunchScript.sql /tmp/
lxc-execute sigmah -- cat /srv/sigmah-MinimumDataKit.sql >/tmp/sigmah-MinimumDataKit.sql
lxc-execute sigmah -- cat /srv/sigmah-newOrganizationLaunchScript.sql >/tmp/sigmah-newOrganizationLaunchScript.sql
export SIGMAH_ADMIN_USER=Admin
export SIGMAH_ADMIN_EMAIL=admin@example.com
export SIGMAH_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
@ -32,19 +41,17 @@ 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 | 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} psql -U sigmah sigmah"
cat /tmp/sigmah-MinimumDataKit.sql | lxc-attach sigmah-postgres -- sh -c "PGPASSWORD=${SIGMAH_PWD} psql -U sigmah sigmah"
cat /tmp/sigmah-newOrganizationLaunchScript.sql | lxc-attach sigmah-postgres -- sh -c "PGPASSWORD=${SIGMAH_PWD} psql -U sigmah sigmah"
rm -f /tmp/sigmah-MinimumDataKit.sql /tmp/sigmah-newOrganizationLaunchScript.sql
# Install service
cp etc/init.d/sigmah /etc/init.d/sigmah
rc-update -u
# Install config update script
cp srv/sigmah/update-conf.sh /srv/sigmah/update-conf.sh
cp update-conf.sh /srv/sigmah/update-conf.sh
# Stop services required for build
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
# Stop services required for setup
service sigmah-postgres stop
# Register application
vmmgr register-app sigmah sigmah "${SIGMAH_ADMIN_EMAIL}" "${SIGMAH_ADMIN_PWD}"
# TODO: SQL skripty jako soucast installu?

View File

@ -1,23 +0,0 @@
#!/sbin/openrc-run
description="Sigmah container"
depend() {
need postgres
}
start() {
lxc-start sigmah
}
start_post() {
vmmgr register-proxy sigmah
}
stop_pre() {
vmmgr unregister-proxy sigmah
}
stop() {
lxc-stop sigmah
}

View File

@ -32,10 +32,6 @@ EOF
COPY lxc
MOUNT DIR /srv/sigmah/data srv/sigmah/data
MOUNT FILE /srv/sigmah/conf/persistence.xml srv/tomcat/webapps/sigmah/WEB-INF/classes/META-INF/persistence.xml
MOUNT FILE /srv/sigmah/conf/sigmah.properties srv/tomcat/webapps/sigmah/WEB-INF/classes/sigmah.properties
USER 8011 8011
WORKDIR /srv/tomcat
CMD catalina.sh run

27
lxc-apps/sigmah/meta Normal file
View File

@ -0,0 +1,27 @@
{
"version": "5.1.9-190620",
"meta": {
"title": "Sigmah",
"desc-cs": "Finanční řízení sbírek",
"desc-en": "Donation management",
"license": "GPL",
},
"containers": {
"sigmah": {
"image": "sigmah_5.1.9-190620",
"depends": [
"sigmah-postgres"
],
"mounts": [
["DIR", "/srv/sigmah/sigmah_conf", "/srv/sigmah/conf"],
["DIR", "/srv/sigmah/sigmah_data", "/srv/sigmah/data"]
]
},
"sigmah-postgres": {
"image": "postgis_11.3.0-190620",
"mounts": [
["DIR", "/srv/sigmah/postgres_data", "/var/lib/postgresql"]
]
}
}
}

View File

@ -1,14 +1,8 @@
#!/bin/sh
set -ev
# Remove service
rm -f /etc/init.d/sigmah
rc-update -u
# Drop database and user
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
echo 'DROP DATABASE IF EXISTS sigmah; DROP ROLE IF EXISTS sigmah;' | lxc-attach -u 5432 -g 5432 postgres -- psql
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
# Remove persistent data
rm -rf /srv/sigmah
# Unregister application
vmmgr unregister-app sigmah