LXCize GNU Health setup

This commit is contained in:
Disassembler 2018-09-13 20:32:57 +02:00
parent 01fc001990
commit 986c13f4c7
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499
2 changed files with 22 additions and 26 deletions

View File

@ -1,21 +1,17 @@
#!/bin/sh #!/bin/sh
set -e set -e
SOURCE_DIR=$(realpath $(dirname "${0}"))/gnuhealth SOURCE_DIR=$(realpath $(dirname "${0}"))/setup
# Check prerequisites # Check prerequisites
lxc-ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh # TODO: Have setup prereqs in a manifest file
lxc-ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh for SERVICE in postgres; do
service postgres start [ ! -e /run/openrc/started/${SERVICE} ] && service ${SERVICE} start && STOP_SERVICES="${STOP_SERVICES} ${SERVICE}"
done
# Build Docker container
docker build -t gnuhealth ${SOURCE_DIR}
cp ${SOURCE_DIR}/etc/init.d/gnuhealth /etc/init.d/gnuhealth
rc-update -u
# Create databases # Create databases
export GNUHEALTH_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '/+=') export GNUHEALTH_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '/+=')
envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql envsubst <${SOURCE_DIR}/createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
# Configure GNU Health # Configure GNU Health
mkdir -p /srv/gnuhealth/conf/ mkdir -p /srv/gnuhealth/conf/
@ -24,15 +20,21 @@ envsubst <${SOURCE_DIR}/srv/gnuhealth/conf/trytond.conf >/srv/gnuhealth/conf/try
# Populate database # Populate database
export GNUHEALTH_ADMIN_USER="admin" export GNUHEALTH_ADMIN_USER="admin"
export GNUHEALTH_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) export GNUHEALTH_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
echo ${GNUHEALTH_ADMIN_PWD} >/tmp/.adminpwd echo ${GNUHEALTH_ADMIN_PWD} >/var/lib/lxc/gnuhealth/gnuhealth/tmp/.adminpwd
docker run --rm -h gnuhealth --link postgres -v /srv/gnuhealth/conf:/srv/gnuhealth/gnuhealth/tryton/server/config -v /tmp/.adminpwd:/tmp/.adminpwd -e TRYTONPASSFILE=/tmp/.adminpwd gnuhealth /srv/gnuhealth/gnuhealth/tryton/server/trytond-4.2.15/bin/trytond-admin -d gnuhealth --all -v lxc-execute gnuhealth -- sh -c 'TRYTONPASSFILE=/tmp/.adminpwd trytond-admin -d gnuhealth --all -v'
rm -f /tmp/.adminpwd rm -f /var/lib/lxc/gnuhealth/gnuhealth/tmp/.adminpwd
vmmgr update-login gnuhealth "${GNUHEALTH_ADMIN_USER}" "${GNUHEALTH_ADMIN_PWD}" vmmgr update-login gnuhealth "${GNUHEALTH_ADMIN_USER}" "${GNUHEALTH_ADMIN_PWD}"
# Populate demo database # Populate demo database
wget http://health.gnu.org/downloads/postgres_dumps/gnuhealth-32-demo.sql.gz -O /tmp/gnuhealth_demo.sql.gz wget http://health.gnu.org/downloads/postgres_dumps/gnuhealth-32-demo.sql.gz -O /tmp/gnuhealth_demo.sql.gz
zcat /tmp/gnuhealth_demo.sql.gz | docker exec -i -e PGPASSWORD=${GNUHEALTH_PWD} postgres psql gnuhealth_demo gnuhealth zcat /tmp/gnuhealth_demo.sql.gz | lxc-attach -u 5432 -g 5432 postgres -- sh -c 'PGPASSWORD=${GNUHEALTH_PWD} psql gnuhealth_demo gnuhealth'
rm -f /tmp/gnuhealth_demo.sql.gz rm -f /tmp/gnuhealth_demo.sql.gz
# Stop services required for build # Install service
service postgres stop cp ${SOURCE_DIR}/etc/init.d/gnuhealth /etc/init.d/gnuhealth
rc-update -u
# Stop services required for setup
for SERVICE in ${STOP_SERVICES}; do
service ${SERVICE} stop
done

View File

@ -1,19 +1,13 @@
#!/sbin/openrc-run #!/sbin/openrc-run
description="GNU Health docker container" description="GNU Health container"
depend() { depend() {
need docker postfix postgres need cgroups postgres
} }
start() { start() {
/usr/bin/docker run -d --rm \ lxc-start gnuhealth
--name gnuhealth \
-h gnuhealth \
--link postfix \
--link postgres \
-v /srv/gnuhealth/conf:/srv/gnuhealth/gnuhealth/tryton/server/config \
gnuhealth
} }
start_post() { start_post() {
@ -25,5 +19,5 @@ stop_pre() {
} }
stop() { stop() {
/usr/bin/docker kill -s SIGINT gnuhealth lxc-stop gnuhealth
} }