#!/usr/bin/env bash #--------------------------------------------------------------------------- # Copyright 2011-2017 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 # Start VistA vista_instance="/path/to/vista/instance" start() { # If a database is shutdown cleanly there shouldn't be anything in the # journals to replay, so we can run this without worry source ${vista_instance}/env.vista su - vistauser -c "source ${vista_instance}/env.vista && if [ -f ${vista_home}/j/mumps.mjl ]; then echo \"Recovering old journals...\" mupip journal -recover -backward ${vista_home}/j/mumps.mjl fi" if (( $(find ${vista_home}/j -name '*_*' -mtime +3 -print | wc -l) > 0 )); then echo "Deleting old journals..." find ${vista_home}/j -name '*_*' -mtime +3 -print -delete fi # Rundown readonly GT.M/YDB databases for f in $gtm_dist/*.dat; do $gtm_dist/mupip rundown -f $f; done # Delete temp and then recreate echo "Deleting and recreating temp region" rm -vf $basedir/g/tempgbl.dat su - vistauser -c "source ${vista_instance}/env.vista && $gtm_dist/mupip create -region=TEMPGBL" su - vistauser -c "source ${vista_instance}/env.vista; mupip rundown -region '*'" su - vistauser -c "source ${vista_instance}/env.vista; mupip set -journal=\"enable,on,before,f=${vista_home}/j/mumps.mjl\" -region DEFAULT" echo "Starting TaskMan" su - vistauser -c "source ${vista_instance}/env.vista; mumps -run ZTMB" } # Stop VistA stop() { su - vistauser -c "source ${vista_instance}/env.vista; mumps -run %XCMD 'S U=\"^\" D STOP^ZTMKU' << EOF Y Y Y EOF" # Wait for TaskMan to stop echo "Waiting for TaskMan to stop (2 sec)" sleep 2 echo "Stopping any remaining M processes nicely" su - vistauser -c ". ${vista_instance}/env.vista && pgrep mumps | xargs --max-args=1 mupip stop" sleep 2 processes=$(pgrep mumps) if [ ! -z "${processes}" ] ; then echo "M process are being shutdown forcefully!" pkill -9 mumps fi rm -fv /tmp/gtm_* } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; *) echo "Usage: $0 {start|stop|restart}" ;; esac