4.2.10 Enabling Restarting OSCAR
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
Contents
|
Prerequisites
It is assumed that- A default Ubuntu/Tomcat6 based installation of OSCAR older than Oscar 12_1 build 29.
- You have a basic level of Linux knowledge
- You can open a Linux terminal
- You can use a Linux text editor
- You can cut and paste EXACTLY the following instructions
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