added automated deployment tools
authorJeff Davis <jdavis@sitka.bclibraries.ca>
Tue, 25 Sep 2012 23:49:06 +0000 (16:49 -0700)
committerJeff Davis <jdavis@sitka.bclibraries.ca>
Tue, 25 Sep 2012 23:53:31 +0000 (16:53 -0700)
.gitignore [new file with mode: 0644]
deployment/apache.sh [new file with mode: 0755]
deployment/config-lookup.sh [new file with mode: 0755]
deployment/deployfile.sh [new file with mode: 0755]
deployment/install-eg.sh [new file with mode: 0755]
deployment/install-osrf.sh [new file with mode: 0755]
deployment/parse-osrf-xml.pl [new file with mode: 0644]
deployment/restart-osrf.sh [new file with mode: 0755]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..6c9f944
--- /dev/null
@@ -0,0 +1 @@
+deployment/files/*
diff --git a/deployment/apache.sh b/deployment/apache.sh
new file mode 100755 (executable)
index 0000000..fa9fd45
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/bash
+CMD="$1"
+for HOST in "${@:2}"
+do
+  ssh root@${HOST} "/etc/init.d/apache2 ${CMD}"
+done
diff --git a/deployment/config-lookup.sh b/deployment/config-lookup.sh
new file mode 100755 (executable)
index 0000000..ab1b5c8
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/bash
+for HOST in "$@"
+do
+  scp -q sitkastaff@${HOST}:/srv/openils/conf/opensrf.xml files/${HOST}.opensrf.xml
+  echo "${HOST}"
+  perl ./parse-osrf-xml.pl files/${HOST}.opensrf.xml
+  echo ""
+done
diff --git a/deployment/deployfile.sh b/deployment/deployfile.sh
new file mode 100755 (executable)
index 0000000..d76778f
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/bash
+
+usage()
+{
+  cat <<EOF
+USAGE:
+./deployfile.sh -f filename -p /path/to/destination/ [ -u remoteuser ] [ -b ] host1 [ host2 ... ]
+
+OPTIONS:
+  -f    Name of file to be deployed
+  -p    Path on remote server where file should be deployed to
+  -u    Username to use when logging into remote server; if not provided, defaults to current user
+  -b    Backup flag (optional); creates a backup instead of overwriting file on remote server
+  -h    Print this message and exit
+EOF
+}
+
+while getopts ":f:p:u:bh" opt
+do
+  case $opt in
+    f ) FILE=$OPTARG;;
+    p ) DEST=$OPTARG;;
+    u ) USER=$OPTARG;;
+    b ) BACKUP="-b --suffix=.`date +%Y%m%d%H%M`";;
+    h ) usage && exit 0;;
+  esac
+done
+shift $(($OPTIND - 1))
+
+if [[ -z "$FILE" ]] || [[ -z "$DEST" ]] | [[ $# -lt 1 ]]
+then
+  usage
+  exit 1
+else
+
+  if [[ -z "$BACKUP" ]]
+  then
+    SSH="ssh"
+  else
+    SSH="ssh -l${USER}"
+  fi
+
+  for HOST in "$@"
+  do
+    RSYNC_DEST="${HOST}:${DEST}"
+    #echo -e "$HOST:\n\tFILE=$FILE\n\tDEST=$DEST\n\tUSER=$USER\n\tBACKUP=$BACKUP\n\tSSH=$SSH\n\tRSYNC_DEST=$RSYNC_DEST\n"
+    rsync -e"${SSH}" $BACKUP -avz $FILE $RSYNC_DEST
+  done
+fi
diff --git a/deployment/install-eg.sh b/deployment/install-eg.sh
new file mode 100755 (executable)
index 0000000..0f7c797
--- /dev/null
@@ -0,0 +1,140 @@
+#!/bin/bash
+# IMPORTANT! This script assumes you have already installed OpenSRF.
+
+HOSTNAME="nonprod"
+DEFAULT_USER="sitkastaff"
+HOMEDIR="/home/${DEFAULT_USER}"
+BUILDDIR="${HOMEDIR}/evergreen"
+INSTALLDIR="/srv/openils"
+BRANCH="production/sitka_2_2"
+VERSION="2.2.0.sitka.1"
+STAMP_ID="2_2_0_sitka_1"
+ALT_STAMP_IDS="rel_2_2_0_sitka_1 2_2_0_sitka_0 rel_2_2_0_sitka_0 rel_2_2"
+SITKACONF="${HOMEDIR}/sysadmin"
+DEPLOYDIR="/home/opensrf/deploy"
+OPACSKIN="${DEPLOYDIR}/opacskin"
+OILSPOLICY="${DEPLOYDIR}/oilspolicy"
+
+# as DEFAULT_USER
+
+# grab Sitka config files
+if [ ! -d "${SITKACONF}" ]
+then
+  # this will fail unless DEFAULT_USER has read access to the repo
+  su -l -c "cd ${HOMEDIR} && git clone git+ssh://git@git.sitka.bclibraries.ca/sitka-infra/sysadmin" ${DEFAULT_USER}
+fi
+su -l -c "cd ${SITKACONF} && git pull" ${DEFAULT_USER}
+
+# checkout EG source
+if [ ! -d "${BUILDDIR}" ]
+then
+  su -l -c "cd ${HOMEDIR} && git clone git://git.sitka.bclibraries.ca/sitka/evergreen evergreen" ${DEFAULT_USER}
+fi
+su -l -c "cd ${BUILDDIR} && git checkout ${BRANCH}" ${DEFAULT_USER}
+# as root
+cd ${BUILDDIR} && make -f Open-ILS/src/extras/Makefile.install ubuntu-precise
+# by default, CPAN needs some manual input at this point; you can just accept all defaults
+# as DEFAULT_USER
+su -l -c "cd ${BUILDDIR} && autoreconf -i" ${DEFAULT_USER}
+su -l -c "cd ${BUILDDIR} && ./configure -C --prefix='${INSTALLDIR}' --sysconfdir='\${prefix}/conf' --with-opensrf-headers=${INSTALLDIR}/include/ --with-opensrf-libs=${INSTALLDIR}/lib/ --with-dbi=/usr/lib/dbd/" ${DEFAULT_USER}
+su -l -c "cd ${BUILDDIR} && make" ${DEFAULT_USER}
+su -l -c "cd ${BUILDDIR}/build/i18n && make install_all_locales" ${DEFAULT_USER}
+# as root
+cd ${BUILDDIR} && make STAFF_CLIENT_STAMP_ID=${STAMP_ID} STAFF_CLIENT_VERSION=${VERSION} install
+chown -R opensrf:opensrf ${INSTALLDIR}
+# Apache stuff (as root):
+APACHEFILES="/etc/apache2/eg_vhost.conf /etc/apache2/startup.pl /etc/apache2/sites-available/eg.conf"
+for APACHEFILE in ${APACHEFILES}
+do
+  cp ${SITKACONF}/files/${APACHEFILE}/${HOSTNAME} ${APACHEFILE}
+done
+a2dissite default
+a2ensite eg.conf
+mkdir /etc/apache2/ssl
+cd /etc/apache2/ssl && openssl req -new -x509 -days 365 -nodes -out server.crt -keyout server.key
+# TODO: set up log rotation
+# as opensrf
+# 0. osrf conf stuff 
+# FIXME: ensure osrf conf files point at a real, distinct db!
+OSRFCONFFILES="${INSTALLDIR}/conf/opensrf.xml ${INSTALLDIR}/conf/opensrf_core.xml"
+for OSRFCONFFILE in ${OSRFCONFFILES}
+do
+  cp ${SITKACONF}/files/${OSRFCONFFILE}/${HOSTNAME} ${OSRFCONFFILE}
+done
+cp ${SITKACONF}/files/home/opensrf/.srfsh.xml/${HOSTNAME} ${HOMEDIR}/.srfsh.xml
+# 1. install dojo
+cd /home/opensrf && wget http://download.dojotoolkit.org/release-1.3.3/dojo-release-1.3.3.tar.gz
+tar -C ${INSTALLDIR}/var/web/js -xzf /home/opensrf/dojo-release-1.3.3.tar.gz
+cp -r ${INSTALLDIR}/var/web/js/dojo-release-1.3.3/* ${INSTALLDIR}/var/web/js/dojo/.
+# 2. set up staff client
+cd ${INSTALLDIR}/var/web/xul && ln -s ${STAMP_ID} current && ln -s current/server server
+for ALT_STAMP_ID in ${ALT_STAMP_IDS}
+do
+  cd ${INSTALLDIR}/var/web/xul && ln -s current ${ALT_STAMP_ID}
+done
+# 3. install circ scripts and opac skins
+
+# (a) setup deploy directory
+if [ ! -d "${DEPLOYDIR}" ]
+then
+  mkdir ${DEPLOYDIR}
+fi
+
+# (b) bclibraries skin
+if [ ! -d "${OPACSKIN}" ]
+then
+  cd ${DEPLOYDIR} && git clone git://git.sitka.bclibraries.ca/sitka/opacskin.git
+fi
+cd ${OPACSKIN} && git checkout origin/bclibraries && \
+  cd ${INSTALLDIR}/var/web/opac/skin && mv default orig-default && \
+  rsync -a --exclude=.git ${OPACSKIN}/bclibraries ${INSTALLDIR}/var/web/opac/skin/bclibraries && \
+  ln -s ${INSTALLDIR}/var/web/opac/skin/bclibraries ${INSTALLDIR}/var/web/opac/skin/default
+
+# (b) circ scripts
+if [ ! -d "${OILSPOLICY}" ]
+then
+  cd ${DEPLOYDIR} && git clone git://git.sitka.bclibraries.ca/sitka/oilspolicy.git
+fi
+cd ${OILSPOLICY} && git pull && rsync -a --exclude=.git ${OILSPOLICY} ${INSTALLDIR}/var
+# 4. avoid 404s
+touch ${INSTALLDIR}/var/web/css/skin/default/register_custom.css
+touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/patron_custom.properties
+touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/common_custom.properties
+touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/offline_custom.properties
+touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/auth_custom.properties
+touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/cat_custom.properties
+touch ${INSTALLDIR}/var/web/xul/server/locale/en-CA/circ_custom.properties
+touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/patron_custom.properties
+touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/common_custom.properties
+touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/offline_custom.properties
+touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/auth_custom.properties
+touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/cat_custom.properties
+touch ${INSTALLDIR}/var/web/xul/server/locale/en-US/circ_custom.properties
+touch ${INSTALLDIR}/var/web/xul/server/skin/custom.js
+
+# 5. locale hack
+cd ${INSTALLDIR}/var/web/opac/locale && cp -fdr en-US en-US-bak && cp -fdr en-CA en-US
+# 6. deletepatron
+# ensure apache conf contains deletepatron config (location should be ${INSTALLDIR}/var/web/deletepatron)
+cd ${INSTALLDIR}/var/web && git clone https://github.com/twirlip/deletepatron.git
+cd ${INSTALLDIR}/var/web/deletepatron && git checkout eg22 && find . -name *.pm | xargs sed -i -e 's|/openils|/srv/openils|g'
+
+# 7. support scripts
+cp ${BUILDDIR}/Open-ILS/src/support-scripts/generate_circ_notices.pl ${INSTALLDIR}/bin
+cp ${BUILDDIR}/Open-ILS/src/support-scripts/oils_header.pl ${INSTALLDIR}/bin
+
+# 8. make sure opensrf owns all the stuff we just did
+chown -R opensrf:opensrf ${INSTALLDIR}
+
diff --git a/deployment/install-osrf.sh b/deployment/install-osrf.sh
new file mode 100755 (executable)
index 0000000..38d9ca3
--- /dev/null
@@ -0,0 +1,61 @@
+#!/bin/bash
+OSRF="opensrf-2.1.0"
+INSTALLDIR="/srv/openils"
+DEFAULT_USER="sitkastaff"
+HOMEDIR="/home/${DEFAULT_USER}"
+SITKACONF="${HOMEDIR}/sysadmin"
+
+# as root
+usermod -a -G sudo ${DEFAULT_USER}
+apt-get install git-core build-essential translate-toolkit python-polib bsdmainutils
+# as DEFAULT_USER
+if [ ! -d "${SITKACONF}" ]
+then
+  # this will fail unless DEFAULT_USER has read access to the repo
+  su -l -c "cd ${HOMEDIR} && git clone git+ssh://git@git.sitka.bclibraries.ca/sitka-infra/sysadmin" ${DEFAULT_USER}
+fi
+su -l -c "cd ${HOMEDIR}/sysadmin && git pull" ${DEFAULT_USER}
+su -l -c "cd ${HOMEDIR} && wget http://open-ils.org/downloads/${OSRF}.tar.gz && tar xzf ${OSRF}.tar.gz" ${DEFAULT_USER}
+# as root
+echo "Installing OpenSRF prerequisites for Ubuntu..."
+cd ${HOMEDIR}/${OSRF} && make -f src/extras/Makefile.install ubuntu-precise
+# as DEFAULT_USER
+echo "Configuring and building OpenSRF..."
+su -l -c "cd ${HOMEDIR}/${OSRF} && autoreconf -i" ${DEFAULT_USER}
+su -l -c "cd ${HOMEDIR}/${OSRF} && ./configure --prefix=${INSTALLDIR} --sysconfdir=${INSTALLDIR}/conf" ${DEFAULT_USER}
+su -l -c "cd ${HOMEDIR}/${OSRF} && make" ${DEFAULT_USER}
+# as root
+echo "Installing OpenSRF..."
+cd ${HOMEDIR}/${OSRF} && make install
+useradd -m -s /bin/bash opensrf
+echo "export PATH=\$PATH:${INSTALLDIR}/bin" >> /home/opensrf/.bashrc
+chown -R opensrf:opensrf ${INSTALLDIR}
+# as root, add the following two lines to /etc/hosts:
+#127.0.1.2     public.localhost        public
+#127.0.1.3     private.localhost       private
+echo "Updating /etc/hosts..."
+echo -e "127.0.1.2\tpublic.localhost\tpublic\n127.0.1.3\tprivate.localhost\tprivate\n" | \
+  cat - /etc/hosts > /etc/hosts.new && mv /etc/hosts.new /etc/hosts
+# as root
+echo "ldconfig stuff..."
+echo "${INSTALLDIR}/lib" > /etc/ld.so.conf.d/opensrf.conf
+ldconfig
+# as root
+echo "Setting up ejabberd..."
+mv /etc/ejabberd/ejabberd.cfg /etc/ejabberd/ejabberd.cfg.orig && cp ${SITKACONF}/files/etc/ejabberd/ejabberd.cfg/nonprod /etc/ejabberd/
+chgrp ejabberd /etc/ejabberd/ejabberd.cfg
+chmod 640 /etc/ejabberd/ejabberd.cfg
+/etc/init.d/ejabberd restart
+ejabberdctl register router private.localhost passwd
+ejabberdctl register opensrf private.localhost passwd
+ejabberdctl register router public.localhost passwd
+ejabberdctl register opensrf public.localhost passwd
+
+echo "OpenSRF is installed!"
diff --git a/deployment/parse-osrf-xml.pl b/deployment/parse-osrf-xml.pl
new file mode 100644 (file)
index 0000000..492f84a
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+use XML::LibXML;
+use Data::Dumper;
+
+# load the XML file
+my $filename = shift;
+open my $fh, '<', $filename;
+binmode $fh; # drop all PerlIO layers possibly created by a use open pragma
+my $doc = XML::LibXML->load_xml(IO => $fh);
+
+# get the values we want
+my $xpath_prefix = '/opensrf/default/apps/open-ils.storage/app_settings/databases/database';
+my %config;
+for my $attr ( qw/host port user db pw/ ) {
+    $config{$attr} = $doc->findvalue("$xpath_prefix/$attr");
+    #print $doc->findvalue("$xpath_prefix/$attr") . "\n";
+}
+for my $k ( qw/host port db/ ) {
+    print "$k: " . $config{$k} . "\n";
+}
diff --git a/deployment/restart-osrf.sh b/deployment/restart-osrf.sh
new file mode 100755 (executable)
index 0000000..1349ba1
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+BASEDIR="/srv/openils"
+BINDIR="${BASEDIR}/bin"
+
+BRICK_CTL="/home/opensrf/brick_ctl.sh"
+
+OSRFLG="/srv/openils/var/log/osrfsys.log"
+
+RestartBrick()
+{
+  /etc/init.d/apache2 stop
+  su -l opensrf -c ${BRICK_CTL} -a restart_all
+  /etc/init.d/apache2 start
+  return 1
+}
+
+RestartOsrf()
+{
+  /etc/init.d/apache2 stop
+  su -l opensrf -c ${BINDIR}/osrf_ctl.sh -l -a restart_all
+  /etc/init.d/apache2 start
+  return 1
+}
+
+