LXCize SeedDMS setup

This commit is contained in:
Disassembler 2018-09-14 09:02:16 +02:00
parent 8cc184c7e7
commit d1991ddc7d
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499
2 changed files with 17 additions and 27 deletions

View File

@ -1,28 +1,21 @@
#!/bin/sh #!/bin/sh
set -e set -e
SOURCE_DIR=$(realpath $(dirname "${0}"))/seeddms SOURCE_DIR=$(realpath $(dirname "${0}"))/setup
# Check prerequisites # Check prerequisites
lxc-ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh [ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
lxc-ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh
service postgres start
# Build Docker container
docker build -t seeddms ${SOURCE_DIR}
cp ${SOURCE_DIR}/etc/init.d/seeddms /etc/init.d/seeddms
rc-update -u
# Populate database # Populate database
export SEEDDMS_PWD=$(head -c 18 /dev/urandom | base64) export SEEDDMS_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
docker run --rm seeddms cat /srv/seeddms/create_tables-postgres.sql | docker exec -i -e PGPASSWORD=${SEEDDMS_PWD} postgres psql seeddms seeddms cat /var/lib/lxc/seeddms/seeddms/srv/seeddms/create_tables-postgres.sql | lxc-attach postgres -- sh -c "PGPASSWORD=${SEEDDMS_PWD} psql seeddms seeddms"
cat ${SOURCE_DIR}/custom.sql | docker exec -i -e PGPASSWORD=${SEEDDMS_PWD} postgres psql seeddms seeddms cat ${SOURCE_DIR}/custom.sql | lxc-attach -u 5432 -g 5432 postgres -- psql seeddms
# Copy existing files into persistent storage # Copy existing files into persistent storage
mkdir -p /srv/seeddms/conf /srv/seeddms/data mkdir -p /srv/seeddms/conf /srv/seeddms/data
docker run --rm -v /srv/seeddms/conf:/mnt/conf seeddms cp -rp /srv/seeddms/conf/. /mnt/conf cp -rp /var/lib/lxc/seddms/seeddms/srv/seeddms/conf/. /srv/seeddms/conf
docker run --rm -v /srv/seeddms/data:/mnt/data seeddms cp -rp /srv/seeddms/data/. /mnt/data cp -rp /var/lib/lxc/seddms/seeddms/srv/seeddms/data/. /srv/seeddms/data
chown -R 8010:8010 /srv/seeddms/data chown -R 8010:8010 /srv/seeddms/data
# Configure SeedDMS # Configure SeedDMS
@ -30,12 +23,16 @@ envsubst <${SOURCE_DIR}/srv/seeddms/conf/settings.xml >/srv/seeddms/conf/setting
export SEEDDMS_ADMIN_USER=admin export SEEDDMS_ADMIN_USER=admin
export SEEDDMS_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) export SEEDDMS_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
export SEEDDMS_ADMIN_EMAIL=admin@example.com export SEEDDMS_ADMIN_EMAIL=admin@example.com
envsubst <${SOURCE_DIR}/adminpwd.sql | docker exec -i postgres psql seeddms envsubst <${SOURCE_DIR}/adminpwd.sql | lxc-attach -u 5432 -g 5432 postgres -- psql seeddms
chown -R 8010:8010 /srv/seeddms/conf chown -R 8010:8010 /srv/seeddms/conf
vmmgr update-login seeddms "${SEEDDMS_ADMIN_USER}" "${SEEDDMS_ADMIN_PWD}" vmmgr update-login seeddms "${SEEDDMS_ADMIN_USER}" "${SEEDDMS_ADMIN_PWD}"
# Install service
cp ${SOURCE_DIR}/etc/init.d/seeddms /etc/init.d/seeddms
rc-update -u
# Install cron job # Install cron job
cp ${SOURCE_DIR}/etc/periodic/hourly/seeddms /etc/periodic/hourly/seeddms cp ${SOURCE_DIR}/etc/periodic/hourly/seeddms /etc/periodic/hourly/seeddms
# Stop services required for build # Stop services required for build
service postgres stop [ ! -z ${STOP_POSTGRES} ] && service postgres stop

View File

@ -1,20 +1,13 @@
#!/sbin/openrc-run #!/sbin/openrc-run
description="SeedDMS docker container" description="SeedDMS container"
depend() { depend() {
need docker postfix postgres need cgroups postgres
} }
start() { start() {
/usr/bin/docker run -d --rm \ lxc-start seeddms
--name seeddms \
-h seeddms \
--link postfix \
--link postgres \
-v /srv/seeddms/data:/srv/seeddms/data \
-v /srv/seeddms/conf:/srv/seeddms/conf \
seeddms
} }
start_post() { start_post() {
@ -26,5 +19,5 @@ stop_pre() {
} }
stop() { stop() {
/usr/bin/docker stop seeddms lxc-stop seeddms
} }