diff --git a/crisiscleanup/setup.sh b/crisiscleanup/setup.sh index aba02f7..8e5a218 100644 --- a/crisiscleanup/setup.sh +++ b/crisiscleanup/setup.sh @@ -1,27 +1,22 @@ #!/bin/sh set -e -SOURCE_DIR=$(realpath $(dirname "${0}"))/crisiscleanup +SOURCE_DIR=$(realpath $(dirname "${0}"))/setup # Check prerequisites -lxc-ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh -lxc-ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh -service postgres start - -# Build Docker container -docker build -t crisiscleanup ${SOURCE_DIR} -cp ${SOURCE_DIR}/etc/init.d/crisiscleanup /etc/init.d/crisiscleanup -rc-update -u +# TODO: Have setup prereqs in a manifest file +for SERVICE in postgres; do + [ ! -e /run/openrc/started/${SERVICE} ] && service ${SERVICE} start && STOP_SERVICES="${STOP_SERVICES} ${SERVICE}" +done # Create database export CRISISCLEANUP_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 # Copy existing config files into persistent storage mkdir -p /srv/crisiscleanup/conf chown 8005:8005 /srv/crisiscleanup/conf -docker run --rm -v /srv/crisiscleanup/conf:/mnt/conf crisiscleanup cp -rp /srv/crisiscleanup/config/. /mnt/conf -chown root:root /srv/crisiscleanup/conf +cp -r /var/lib/lxc/crisiscleanup/crisiscleanup/srv/crisiscleanup/config/. /srv/crisiscleanup/conf # Configure CrisisCleanup export CRISISCLEANUP_ADMIN_USER="Admin" @@ -34,10 +29,16 @@ cp ${SOURCE_DIR}/srv/crisiscleanup/conf/environments/production.rb /srv/crisiscl vmmgr update-login crisiscleanup "${CRISISCLEANUP_ADMIN_EMAIL}" "${CRISISCLEANUP_ADMIN_PWD}" # Populate database -envsubst <${SOURCE_DIR}/srv/crisiscleanup/db/seeds.rb >/tmp/seeds.rb -docker run --rm -h crisiscleanup --link postgres -v /srv/crisiscleanup/conf:/srv/crisiscleanup/config crisiscleanup rake db:schema:load -docker run --rm -h crisiscleanup --link postgres -v /srv/crisiscleanup/conf:/srv/crisiscleanup/config -v /tmp/seeds.rb:/srv/crisiscleanup/db/seeds.rb crisiscleanup rake db:seed -rm /tmp/seeds.rb +envsubst <${SOURCE_DIR}/srv/crisiscleanup/db/seeds.rb >/var/lib/lxc/crisiscleanup/crisiscleanup/tmp/seeds.rb +lxc-execute crisiscleanup -- rake db:schema:load +lxc-execute crisiscleanup -- rake db:seed +rm /var/lib/lxc/crisiscleanup/crisiscleanup/tmp/seeds.rb -# Stop services required for build -service postgres stop +# Install service +cp ${SOURCE_DIR}/etc/init.d/crisiscleanup /etc/init.d/crisiscleanup +rc-update -u + +# Stop services required for setup +for SERVICE in ${STOP_SERVICES}; do + service ${SERVICE} stop +done diff --git a/crisiscleanup/setup/etc/init.d/crisiscleanup b/crisiscleanup/setup/etc/init.d/crisiscleanup index 555dc1b..251fff3 100644 --- a/crisiscleanup/setup/etc/init.d/crisiscleanup +++ b/crisiscleanup/setup/etc/init.d/crisiscleanup @@ -1,19 +1,13 @@ #!/sbin/openrc-run -description="Crisis Cleanup docker container" +description="Crisis Cleanup container" depend() { - need docker postfix postgres + need cgroups postgres } start() { - /usr/bin/docker run -d --rm \ - --name crisiscleanup \ - -h crisiscleanup \ - --link postfix \ - --link postgres \ - -v /srv/crisiscleanup/conf:/srv/crisiscleanup/config \ - crisiscleanup + lxc-start crisiscleanup } start_post() { @@ -25,5 +19,5 @@ stop_pre() { } stop() { - /usr/bin/docker stop crisiscleanup + lxc-stop crisiscleanup } diff --git a/setup-all.sh b/setup-all.sh index d89398c..9e75815 100755 --- a/setup-all.sh +++ b/setup-all.sh @@ -8,7 +8,7 @@ ${SOURCE_DIR}/activemq/setup.sh ${SOURCE_DIR}/ckan-datapusher/setup.sh ${SOURCE_DIR}/mariadb/setup.sh ${SOURCE_DIR}/postgres/setup.sh -#${SOURCE_DIR}/rabbitmq/setup.sh +${SOURCE_DIR}/rabbitmq/setup.sh ${SOURCE_DIR}/redis/setup.sh ${SOURCE_DIR}/solr/setup.sh