[med-svn] [vista] 03/04: Added scripts for deploying instances.
Luis Ibanez
luisibanez-guest at moszumanska.debian.org
Thu Jan 16 02:25:43 UTC 2014
This is an automated email from the git hooks/post-receive script.
luisibanez-guest pushed a commit to branch master
in repository vista.
commit bd3a94c3aa3bf1e89ffa34224198477a400d0299
Author: Luis Ibanez <luis.ibanez at kitware.com>
Date: Wed Jan 15 20:49:00 2014 -0500
Added scripts for deploying instances.
Based on scripts created by Christopher Edwards in the directory
VistA/Scripts/Install/GTM
This scripts are intended to be used after the installation of the
vista-foia package, to deploy specific running instances of VistA.
They create Linux users dedicated to the new running instance.
---
debian/changelog | 1 +
debian/deploy/bin/rpcbroker.sh | 16 +++
debian/deploy/bin/vistalink.sh | 16 +++
debian/deploy/createVistaInstance.sh | 218 +++++++++++++++++++++++++++++
debian/deploy/etc/init.d/vista | 100 +++++++++++++
debian/deploy/etc/xinetd.d/vista-rpcbroker | 13 ++
debian/deploy/etc/xinetd.d/vista-vistalink | 13 ++
debian/rules | 2 +-
8 files changed, 378 insertions(+), 1 deletion(-)
diff --git a/debian/changelog b/debian/changelog
index 76edd66..e061162 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -21,5 +21,6 @@ vista-foia (0.20140106-1) UNRELEASED; urgency=low
* In rules, started to add management of arch. Mostly x64 so far.
* In control, added xinetd and ssh as dependencies.
* In rules, removing .pyc files in clean: target.
+ * Started adding deployment scripts to create instances.
-- Luis Ibanez <luis.ibanez at kitware.com> Wed, 4 Jul 2012 17:16:45 -0500
diff --git a/debian/deploy/bin/rpcbroker.sh b/debian/deploy/bin/rpcbroker.sh
new file mode 100755
index 0000000..ff7cff6
--- /dev/null
+++ b/debian/deploy/bin/rpcbroker.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+#
+# This is a file to run RPCBroker as a Linux service
+#
+export HOME=/home/foia
+export REMOTE_HOST=`echo $REMOTE_HOST | sed 's/::ffff://'`
+source $HOME/etc/env
+
+LOG=$HOME/log/cprs.log
+
+echo "$$ Job begin `date`" >> ${LOG}
+echo "$$ ${gtm_dist}/mumps -run GTMLNX^XWBTCPM" >> ${LOG}
+
+${gtm_dist}/mumps -run GTMLNX^XWBTCPM "${CPRS_BANNER}" 2>> ${LOG}
+echo "$$ RPCBroker stopped with exit code $?" >> ${LOG}
+echo "$$ Job ended `date`"
diff --git a/debian/deploy/bin/vistalink.sh b/debian/deploy/bin/vistalink.sh
new file mode 100755
index 0000000..533f004
--- /dev/null
+++ b/debian/deploy/bin/vistalink.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+#
+# This is a file to run VistALink as a Linux service
+#
+export HOME=/home/foia
+export REMOTE_HOST=`echo $REMOTE_HOST | sed 's/::ffff://'`
+source $HOME/etc/env
+
+LOG=$HOME/log/vistalink.log
+
+echo "$$ Job begin `date`" >> ${LOG}
+echo "$$ ${gtm_dist}/mumps -run GTMLNX^XOBVTCP" >> ${LOG}
+
+${gtm_dist}/mumps -run GTMLNX^XOBVTCP 2>> ${LOG}
+echo "$$ Vistalink stopped with exit code $?" >> ${LOG}
+echo "$$ Job ended `date`"
diff --git a/debian/deploy/createVistaInstance.sh b/debian/deploy/createVistaInstance.sh
new file mode 100755
index 0000000..42afa05
--- /dev/null
+++ b/debian/deploy/createVistaInstance.sh
@@ -0,0 +1,218 @@
+#!/usr/bin/env bash
+#---------------------------------------------------------------------------
+# Copyright 2011-2012 The Open Source Electronic Health Record Agent
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#---------------------------------------------------------------------------
+
+# Create directories for instance Routines, Objects, Globals, Journals,
+# Temp Files
+# This utility requires root priviledges
+
+# Make sure we are root
+if [[ $EUID -ne 0 ]]; then
+ echo "This script must be run as root" 1>&2
+ exit 1
+fi
+
+# Options
+# instance = name of instance
+# used http://rsalveti.wordpress.com/2007/04/03/bash-parsing-arguments-with-getopts/
+# for guidance
+
+usage()
+{
+ cat << EOF
+ usage: $0 options
+
+ This script will create a VistA instance for GT.M
+
+ OPTIONS:
+ -h Show this message
+ -i Instance name
+EOF
+}
+
+while getopts "i:" option
+do
+ case $option in
+ h)
+ usage
+ exit 1
+ ;;
+ i)
+ instance=$(echo $OPTARG |tr '[:upper:]' '[:lower:]')
+ ;;
+ esac
+done
+
+if [[ -z $instance ]]
+then
+ usage
+ exit 1
+fi
+
+echo "Creating $instance..."
+
+# Determine processor architecture - used to determine if we can use GT.M
+# Shared Libraries
+# Default to x86 (32bit) - algorithm similar to gtminstall script
+arch=$(uname -m | tr -d _)
+if [ $arch == "x8664" ]; then
+ gtm_arch="x86_64"
+else
+ gtm_arch="x86"
+fi
+
+# Find GT.M:
+gtm_ver=6.0-003
+gtm_dist=/usr/lib/fis-gtm/{gtm_ver}_{gtm_arch}
+gtmver=$gtm_ver
+
+# $basedir is the base directory for the instance
+basedir=/home/$instance
+
+# Create $instance User/Group
+# $instance user is a programmer user
+# $instance group is for permissions to other users
+# $instance group is auto created by adduser script
+adduser --gecos "$instance instance owner,,," \
+ --shell /bin/bash \
+ $instance
+
+adduser --gecos "Tied user account for $instance,,," \
+ --home /home/$instance \
+ --ingroup $instance \
+ --shell /home/$instance/bin/tied.sh \
+ ${instance}tied
+
+adduser --gecos "Programmer user account for $instance,,," \
+ --home /home/$instance \
+ --ingroup $instance \
+ --shell /home/$instance/bin/prog.sh \
+ ${instance}prog
+
+
+# Change password for tied accounts
+echo ${instance}tied:tied | chpasswd
+echo ${instance}prog:prog | chpasswd
+
+# Make instance Directories
+su $instance -c "mkdir -p $basedir/{p,p/$gtmver,s,s/$gtmver,r,r/$gtmver,g,j,etc,etc/xinetd.d,log,tmp,bin,lib,www,backup}"
+
+# Copy standard etc and bin items from repo
+su $instance -c "cp -R instance/etc $basedir"
+su $instance -c "cp -R instance/bin $basedir"
+
+# Modify xinetd.d scripts to reflect $instance
+perl -pi -e 's/foia/'$instance'/g' $basedir/bin/*.sh
+perl -pi -e 's/foia/'$instance'/g' $basedir/etc/xinetd.d/vista-*
+
+# Create symbolic link to enable brokers
+ln -s $basedir/etc/xinetd.d/vista-rpcbroker /etc/xinetd.d/$instance-vista-rpcbroker
+ln -s $basedir/etc/xinetd.d/vista-vistalink /etc/xinetd.d/$instance-vista-vistalink
+
+# Symlink libs
+su $instance -c "ln -s $gtm_dist $basedir/lib/gtm"
+
+# Create profile for instance
+# Required GT.M variables
+echo "export gtm_dist=$basedir/lib/gtm" >> $basedir/etc/env
+echo "export gtm_log=$basedir/log" >> $basedir/etc/env
+echo "export gtm_tmp=$basedir/tmp" >> $basedir/etc/env
+echo "export gtm_prompt=\"${instance^^}>\"" >> $basedir/etc/env
+echo "export gtmgbldir=$basedir/g/$instance.gld" >> $basedir/etc/env
+echo "export gtm_zinterrupt='I \$\$JOBEXAM^ZU(\$ZPOSITION)'" >> $basedir/etc/env
+echo "export gtm_lvnullsubs=2" >> $basedir/etc/env
+echo "export PATH=\$PATH:\$gtm_dist" >> $basedir/etc/env
+echo "export basedir=$basedir" >> $basedir/etc/env
+echo "export gtm_arch=$gtm_arch" >> $basedir/etc/env
+echo "export gtmver=$gtmver" >> $basedir/etc/env
+echo "export instance=$instance" >> $basedir/etc/env
+
+# Ensure correct permissions for env
+chown $instance:$instance $basedir/etc/env
+
+# Source envrionment in bash shell
+echo "source $basedir/etc/env" >> $basedir/.bashrc
+
+# Setup base gtmroutines
+gtmroutines="\$basedir/r/\$gtmver(\$basedir/r)"
+
+# 64bit GT.M can use a shared library instead of $gtm_dist
+# TODO: libgtmutil.so isn't being generated by gtminstall, need to figure out what is going on
+if [ $gtm_arch == "x86_64" ]; then
+ echo "export gtmroutines=\"$gtmroutines $basedir/lib/gtm/libgtmutil.so $basedir/lib/gtm\"" >> $basedir/etc/env
+else
+ echo "export gtmroutines=\"$gtmroutines $basedir/lib/gtm\"" >> $basedir/etc/env
+fi
+
+# prog.sh - priviliged (programmer) user access
+# Allow access to ZSY
+echo "#!/bin/bash" >> $basedir/bin/prog.sh
+echo "source $basedir/etc/env" >> $basedir/bin/prog.sh
+echo "export SHELL=/bin/bash" >> $basedir/bin/prog.sh
+echo "#These exist for compatibility reasons" >> $basedir/bin/prog.sh
+echo "alias gtm=\"\$gtm_dist/mumps -dir\"" >> $basedir/bin/prog.sh
+echo "alias GTM=\"\$gtm_dist/mumps -dir\"" >> $basedir/bin/prog.sh
+echo "alias gde=\"\$gtm_dist/mumps -run GDE\"" >> $basedir/bin/prog.sh
+echo "alias lke=\"\$gtm_dist/mumps -run LKE\"" >> $basedir/bin/prog.sh
+echo "alias dse=\"\$gtm_dist/mumps -run DSE\"" >> $basedir/bin/prog.sh
+echo "\$gtm_dist/mumps -dir" >> $basedir/bin/prog.sh
+
+# Ensure correct permissions for prog.sh
+chown $instance:$instance $basedir/bin/prog.sh
+chmod +x $basedir/bin/prog.sh
+
+# tied.sh - unpriviliged user access
+# $instance is their shell - no access to ZSY
+# need to set users with $basedir/bin/tied.sh as their shell
+echo "#!/bin/bash" >> $basedir/bin/tied.sh
+echo "source $basedir/etc/env" >> $basedir/bin/tied.sh
+echo "export SHELL=/bin/false" >> $basedir/bin/tied.sh
+echo "export gtm_nocenable=true" >> $basedir/bin/tied.sh
+echo "exec \$gtm_dist/mumps -run ^ZU" >> $basedir/bin/tied.sh
+
+# Ensure correct permissions for tied.sh
+chown $instance:$instance $basedir/bin/tied.sh
+chmod +x $basedir/bin/tied.sh
+
+# Create Global mapping
+# Thanks to Sam Habiel, Gus Landis, and others for the inital values
+echo "c -s DEFAULT -ACCESS_METHOD=BG -BLOCK_SIZE=4096 -ALLOCATION=200000 -EXTENSION_COUNT=1024 -GLOBAL_BUFFER_COUNT=4096 -LOCK_SPACE=400 -FILE=$basedir/g/$instance.dat" >> $basedir/etc/db.gde
+echo "a -s TEMP -ACCESS_METHOD=MM -BLOCK_SIZE=4096 -ALLOCATION=10000 -EXTENSION_COUNT=1024 -GLOBAL_BUFFER_COUNT=4096 -LOCK_SPACE=400 -FILE=$basedir/g/TEMP.dat" >> $basedir/etc/db.gde
+echo "c -r DEFAULT -RECORD_SIZE=16368 -KEY_SIZE=1019 -JOURNAL=(BEFORE_IMAGE,FILE_NAME=\"$basedir/j/$instance.mjl\") -DYNAMIC_SEGMENT=DEFAULT" >> $basedir/etc/db.gde
+echo "a -r TEMP -RECORD_SIZE=16368 -KEY_SIZE=1019 -NOJOURNAL -DYNAMIC_SEGMENT=TEMP" >> $basedir/etc/db.gde
+echo "a -n TMP -r=TEMP" >> $basedir/etc/db.gde
+echo "a -n TEMP -r=TEMP" >> $basedir/etc/db.gde
+echo "a -n UTILITY -r=TEMP" >> $basedir/etc/db.gde
+echo "a -n XTMP -r=TEMP" >> $basedir/etc/db.gde
+echo "a -n CacheTemp* -r=TEMP" >> $basedir/etc/db.gde
+echo "sh -a" >> $basedir/etc/db.gde
+
+# Ensure correct permissions for db.gde
+chown $instance:$instance $basedir/etc/db.gde
+
+# create the global directory
+# TODO redirect output to file
+# have to source the environment first to have GTM env vars available
+su $instance -c "source $basedir/etc/env && \$gtm_dist/mumps -run GDE < $basedir/etc/db.gde"
+
+# Create the database
+su $instance -c "source $basedir/etc/env && \$gtm_dist/mupip create"
+
+# Set permissions
+chown -R $instance:$instance $basedir
+chmod -R g+rw $basedir
+
+echo "Done creating $instance"
diff --git a/debian/deploy/etc/init.d/vista b/debian/deploy/etc/init.d/vista
new file mode 100755
index 0000000..a7b45b0
--- /dev/null
+++ b/debian/deploy/etc/init.d/vista
@@ -0,0 +1,100 @@
+#!/usr/bin/env bash
+#---------------------------------------------------------------------------
+# Copyright 2011-2012 The Open Source Electronic Health Record Agent
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#---------------------------------------------------------------------------
+
+# init script for VistA
+
+# Debian LSB info
+### BEGIN INIT INFO
+# Provides: foiavista
+# Required-Start: $remote_fs $syslog
+# Required-Stop: $remote_fs $syslog
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Start VistA services at boot time
+# Description: Starts/Stops VistA instances in a sane way.
+# Includes starting TaskMan.
+### END INIT INFO
+
+instance="FOIA"
+
+# setup environment variables
+source /opt/$instance/etc/env
+
+# Start VistA background tasks
+start() {
+ # TODO: logging
+
+ # Check to see if database is clean
+ # TODO: check here
+
+ #if(!clean)
+ # echo "DATABASE IS NOT CLEAN!"
+ # echo "Trying auto recovery (mupip recover --backwards)
+ # $gtm_dist/mupip journal -recover -backward /opt/$instance/$gtmver/j/$instacne.mjl
+ #fi
+
+ # Start TaskMan
+ $gtm_dist/mumps -run START^ZTMB
+
+ # Others? MailMan?
+ # HL7, VistALink, RPC Broker are all handled by xinetd
+}
+stop() {
+ # TODO: logging
+
+ # Stop TaskMan
+ mumps -run STOP^ZTMB <"y\r\ny\n"
+
+ # Wait for TaskMan to stop
+ sleep 60
+
+ # Look for mumps processes and terminate them nicely
+ processes=$(psgrep mumps)
+ if [ ! -z "${processes}" ] ; then
+ for i in ${processes}
+ do
+ mupip stop ${i}
+ done
+
+ # Wait for process to react to mupip stop instead of force kill later
+ sleep 5
+ fi
+
+ # Look for mumps processes that are still running
+ processes=$(psgrep mumps)
+ if [ ! -z "${processes}" ] ; then
+ #TODO: logging required here
+ echo "mumps process are being shutdown forcefully!"
+ pkill -9 mumps
+ fi
+}
+
+case "$1" in
+ (start)
+ start()
+ ;;
+ (stop)
+ stop()
+ ;;
+ (restart)
+ stop()
+ start()
+ ;;
+ (*)
+ echo "Usage: $0 {start|stop|restart}"
+ ;;
+esac
diff --git a/debian/deploy/etc/xinetd.d/vista-rpcbroker b/debian/deploy/etc/xinetd.d/vista-rpcbroker
new file mode 100644
index 0000000..6bb9bba
--- /dev/null
+++ b/debian/deploy/etc/xinetd.d/vista-rpcbroker
@@ -0,0 +1,13 @@
+service vista-rpcbroker
+{
+ port = 9430
+ socket_type = stream
+ protocol = tcp
+ type = UNLISTED
+ user = foia
+ server = /home/foia/bin/rpcbroker.sh
+ wait = no
+ disable = no
+ per_source = UNLIMITED
+ instances = UNLIMITED
+}
diff --git a/debian/deploy/etc/xinetd.d/vista-vistalink b/debian/deploy/etc/xinetd.d/vista-vistalink
new file mode 100644
index 0000000..1c8244f
--- /dev/null
+++ b/debian/deploy/etc/xinetd.d/vista-vistalink
@@ -0,0 +1,13 @@
+service vista-vistalink
+{
+ port = 8001
+ socket_type = stream
+ protocol = tcp
+ type = UNLISTED
+ user = foia
+ server = /home/foia/bin/vistalink.sh
+ wait = no
+ disable = no
+ per_source = UNLIMITED
+ instances = UNLIMITED
+}
diff --git a/debian/rules b/debian/rules
index 1f3bd3f..af54dc8 100755
--- a/debian/rules
+++ b/debian/rules
@@ -56,6 +56,7 @@ override_dh_auto_install:
(export gtmgbldir=$(VISTA_GTM_DATABASE); export gtmroutines=$(VISTA_GTM_ROUTINES); export gtm_dist=$(GTM_INSTALL_DIR); echo "change -s DEFAULT -f=$(VISTAINSTANCEDIR)/g/database" | $(GTM_INSTALL_DIR)/mumps -r GDE)
(export gtmgbldir=$(VISTA_GTM_DATABASE); export gtmroutines=$(VISTA_GTM_ROUTINES); export gtm_dist=$(GTM_INSTALL_DIR); $(GTM_INSTALL_DIR)/mupip create)
(export gtmgbldir=$(VISTA_GTM_DATABASE); export gtmroutines=$(VISTA_GTM_ROUTINES); export gtm_dist=$(GTM_INSTALL_DIR); $(GTM_INSTALL_DIR)/dse change -f -key_max=1023 -rec=4096)
+ cp -r debian/deploy $(VISTAINSTANCEDIR)
override_dh_auto_build:
(export gtmgbldir=$(VISTA_GTM_DATABASE); export gtmroutines=$(VISTA_GTM_ROUTINES); export gtm_dist=$(GTM_INSTALL_DIR); \
@@ -63,7 +64,6 @@ cd $(VISTA_TESTING_BINARY_DIR); \
make ExperimentalStart; \
make ExperimentalConfigure; \
make ExperimentalBuild)
-# make ExperimentalTest)
get-orig-source:
--
Alioth's /git/debian-med/git-commit-notice on /srv/git.debian.org/git/debian-med/vista.git
More information about the debian-med-commit
mailing list