From 4ac414c69125a2219a6ddc3ceef223340fbb3f0d Mon Sep 17 00:00:00 2001 From: Disassembler Date: Sat, 5 Oct 2019 15:34:42 +0200 Subject: [PATCH] Rework Sigmah --- lxc-apps/sigmah/install.sh | 45 +++++++++++-------- lxc-apps/sigmah/install/etc/init.d/sigmah | 23 ---------- .../conf => sigmah_conf}/persistence.xml | 0 .../conf => sigmah_conf}/sigmah.properties | 0 .../install/{srv/sigmah => }/update-conf.sh | 0 lxc-apps/sigmah/lxcfile | 4 -- lxc-apps/sigmah/meta | 27 +++++++++++ lxc-apps/sigmah/uninstall.sh | 10 +---- 8 files changed, 55 insertions(+), 54 deletions(-) delete mode 100755 lxc-apps/sigmah/install/etc/init.d/sigmah rename lxc-apps/sigmah/install/{srv/sigmah/conf => sigmah_conf}/persistence.xml (100%) rename lxc-apps/sigmah/install/{srv/sigmah/conf => sigmah_conf}/sigmah.properties (100%) rename lxc-apps/sigmah/install/{srv/sigmah => }/update-conf.sh (100%) mode change 100755 => 100644 create mode 100644 lxc-apps/sigmah/meta diff --git a/lxc-apps/sigmah/install.sh b/lxc-apps/sigmah/install.sh index 9a58e62..e9b5b2f 100755 --- a/lxc-apps/sigmah/install.sh +++ b/lxc-apps/sigmah/install.sh @@ -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 /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 /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? diff --git a/lxc-apps/sigmah/install/etc/init.d/sigmah b/lxc-apps/sigmah/install/etc/init.d/sigmah deleted file mode 100755 index 88c95af..0000000 --- a/lxc-apps/sigmah/install/etc/init.d/sigmah +++ /dev/null @@ -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 -} diff --git a/lxc-apps/sigmah/install/srv/sigmah/conf/persistence.xml b/lxc-apps/sigmah/install/sigmah_conf/persistence.xml similarity index 100% rename from lxc-apps/sigmah/install/srv/sigmah/conf/persistence.xml rename to lxc-apps/sigmah/install/sigmah_conf/persistence.xml diff --git a/lxc-apps/sigmah/install/srv/sigmah/conf/sigmah.properties b/lxc-apps/sigmah/install/sigmah_conf/sigmah.properties similarity index 100% rename from lxc-apps/sigmah/install/srv/sigmah/conf/sigmah.properties rename to lxc-apps/sigmah/install/sigmah_conf/sigmah.properties diff --git a/lxc-apps/sigmah/install/srv/sigmah/update-conf.sh b/lxc-apps/sigmah/install/update-conf.sh old mode 100755 new mode 100644 similarity index 100% rename from lxc-apps/sigmah/install/srv/sigmah/update-conf.sh rename to lxc-apps/sigmah/install/update-conf.sh diff --git a/lxc-apps/sigmah/lxcfile b/lxc-apps/sigmah/lxcfile index f1d99df..ab397ec 100644 --- a/lxc-apps/sigmah/lxcfile +++ b/lxc-apps/sigmah/lxcfile @@ -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 diff --git a/lxc-apps/sigmah/meta b/lxc-apps/sigmah/meta new file mode 100644 index 0000000..a0faf6b --- /dev/null +++ b/lxc-apps/sigmah/meta @@ -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"] + ] + } + } +} diff --git a/lxc-apps/sigmah/uninstall.sh b/lxc-apps/sigmah/uninstall.sh index 3205ed6..c2e1c7c 100755 --- a/lxc-apps/sigmah/uninstall.sh +++ b/lxc-apps/sigmah/uninstall.sh @@ -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