Personal tools
You are here: Home / OSCAR EMR 12.x / 4.0 Developers / 4.2 Installation 12.x / 4.2.10 Enabling Restarting OSCAR

4.2.10 Enabling Restarting OSCAR

A sample script to allow for end user restart of OSCAR or the server itselt

Preface

While OSCAR rarely needs much maintenance, many problems can be fixed, at least temporarily, with an OSCAR restart or server reboot.

Document Version History

  • v1.0 – initial public release on oscarmanual.org – July 28, 2013
This document is copyright by Peter Hutten-Czapski 2013 © under the Creative Commons Attribution-Share Alike 3.0 Unported License

Contents

  1. Preface
    1. Document Version History
  2. Prerequisites
  3. The Reboot Script

Prerequisites

It is assumed that
  1. A default Ubuntu/Tomcat6 based installation of OSCAR older than Oscar 12_1 build 29.
  2. You have a basic level of Linux knowledge
  3. You can open a Linux terminal
  4. You can use a Linux text editor
  5. You can cut and paste EXACTLY the following instructions
NOTE: Firefox will copy with Control+C while a linux terminal requires Shift+Control+V for paste

The Reboot Script

Using a text editor open a blank file to contain the provided script.  NOTE reOscar.sh comes with the latest OSCAR debs and is installed in /usr/share/OscarMcmaster/reOscar.sh

A note about the following command – ‘vi’ (for visual editor) is a classic unix editor. First time users usually find other Linux editors easier to use particularly ‘nano’, if you are running in a terminal environment, and ‘gedit’, if you are running with a GUI. If you elect to use an alternative editor, replace ‘vi’ in the commands that follow with your editor of choice.
sudo vi usr/share/OscarMcmaster/reOscar.sh

Copy and paste the text below into reOscar.sh
#!/bin/bash
# reOscar.sh
# a script file for OSCAR that reboots Tomcat or the OS

#==============================================================
# Copyright Peter Hutten-Czapski 2013 released under the GPL v2
#==============================================================


TMP=/tmp/tomcat6-tmp
data_path=/usr/share/OscarMcmaster
PROGRAM=Oscar12_1
LOG_FILE=${data_path}/${PROGRAM}.log
LOG_ERR=${data_path}/${PROGRAM}.err
SHUTDOWN_WAIT=20

# --- sanity check
if [ "$(id -u)" != "0" ];
then
	echo "This script must be run as root" 1>&2
	exit 1
fi

# --- reboot the server
if [ -f ${TMP}/rebootServer.action ]; then
	echo "#########" `date` "#########" 1>> $LOG_FILE
	echo "reboot command sent" >> $LOG_FILE
	rm ${TMP}/rebootServer.action
	/sbin/shutdown -r now
	exit 0
fi

# --- reload Tomcat
tomcat_pid() {
	echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'`
}

if [ -f ${TMP}/restartOscar.action ]; then
	echo "#########" `date` "#########" 1>> $LOG_FILE
	echo "restart Oscar command sent" >> $LOG_FILE
	rm ${TMP}/restartOscar.action
	pid=$(tomcat_pid)
	if [ -n "$pid" ]; then
		service tomcat6 stop
		let kwait=$SHUTDOWN_WAIT
		count=0;
		until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
		do
			echo -n -e "\nwaiting for processes to exit";
			sleep 1
			let count=$count+1;
		done
	else
		echo "#########" `date` "#########" 1>> $LOG_ERR
		echo "Is tomcat running.." >> $LOG_ERR		
	fi
	if [ $count -gt $kwait ]; then
		echo "Tomcat process had to be killed" >> $LOG_FILE
		kill -9 $pid
	fi
	service tomcat6 start
fi

exit 0
 

Save and exit the editor and make the file executable by root and not readable by anyone else

sudo chmod 700 usr/share/OscarMcmaster/reOscar.sh

We’ll configure Linux to run the command every minute. This is done by creating a cron job for the script we just made. Run the following command to open an editor for the crontab file:

sudo crontab -e

And add to the existing file an entry so that the command looks like below

# m h dom mon dow command
* * * * * usr/share/OscarMcmaster/reOscar.sh

To activate the script go to Admin -> Oscar Status -> and either click either of the bottom buttons

Document Actions