Run Openoffice As Service Script

OpenOffice

If you are using open office or star office service to generate/process word documents , then you will be requiring below small shell script to monitor the life cycle and open office process. Below given script will perform start, stop, restart, online monitoring and offline monitoring with auto restart when ever openoffice service goes down.

Script Name: oomonitor.sh

 

Configurable entries:

 

export OO_HOME=”/opt/openoffice.org3/program”      # The path to open office installation or soffice.bin file.

export OO_PORT=”8100″                                                              # Port number the service shall bind to, default is 8100.

export OO_HOST=”0.0.0.0″                                                          # Host name it shall bind to, keep it 0.0.0.0 if you are unsure.

export CRON_TIME=”2″                                                                # Time interval in minutes for checking OpenOffice service status.

 

Available Functions:

Open Office Service Monitoring Script Available Options

Open Office Service Monitoring Script Available Options

Life Cycle Run Details:

OpenOffice script lifecycle details

OpenOffice script life cycle details

Live Monitoring(3secs interval): (Starts the service in case it goes down during monitoring)

OpenOffice Service Live Monitoring

OpenOffice Service Live Monitoring

Automated Monitoring: (Adding entry to crontab)

Open Office Service Offline Monitoring

Open Office Service Offline Monitoring

 

Script Code:

#!/bin/sh
# Shell Script to manage OpenOffice services start,stop,restart,online monitor and auto restart.

###################################
# EDIT AREA
###################################

export OO_HOME="/opt/openoffice.org3/program" # The path to open office installation or soffice.bin file.
export OO_PORT="8100" # Port number the service shall bind to, default is 8100.
export OO_HOST="0.0.0.0" # Host name it shall bind to, keep it 0.0.0.0 if you are unsure.
export CRON_TIME="2" # Time interval in minutes for checking OpenOffice service status.

###################################
# DO NOT EDIT ANYTHING BELOW
###################################

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SCRIPT_NAME="`basename $0`"

startOO() {
###################################
# Start Open Office Service
###################################
statusOO
status=$?
if [[ "${status}" == 0 && -d "${OO_HOME}" ]]; then
cd ${OO_HOME};
echo -e "OpenOffice Service : \t\t\E[1;33m[ STARTING ]\E[0m ";
export DISPLAY=:0
nohup ${OO_HOME}/soffice.bin -headless -nofirststartwizard -accept="socket,host=${OO_HOST},port=${OO_PORT};urp;StarOffice.Service" >/dev/null 2>&1 &
sleep 5;
statusOO
else
echo -e "OpenOffice Service : \t\t\E[0;32m[ RUNNING ]\E[0m ";
fi;
}

stopOO() {
###################################
# Stop Open Office Service
###################################
statusOO
status=$?
#echo "Status value: $status"
if [[ "${status}" == 1 && -d "${OO_HOME}" ]]; then
cd ${OO_HOME};
oopid=`ps -eaf | grep soffice | grep -v grep | awk '{print $2}'`
kill -9 $oopid
statusOO
else
statusOO
fi;
}

monitorOO() {
###################################
# Open Office Live Monitoring
###################################
while true;do
statusOO
status=$?
if [[ "${status}" == 1 && -d "${OO_HOME}" ]]; then
sleep 3;
continue;
else
stopOO;
sleep 2;
startOO;
fi;
done;
}

addcron() {
###################################
# Open Office Cron Job
###################################
if [[ -d "${OO_HOME}" ]]; then

command -v crontab >/dev/null 2>&1 || { echo >&2 "I require crontab access but it's not available. Aborting."; exit 1; }
CRONGREP=`crontab -l | grep "${SCRIPT_DIR}/${SCRIPT_NAME} startOO" | grep -v grep`
if [ "$CRONGREP" != "" ];
then
echo "Crontab entry already exists, please enable it if disabled.";
crontab -l;
exit
else
crontab -l | { cat; echo "*/$CRON_TIME * * * * ${SCRIPT_DIR}/${SCRIPT_NAME} startOO"; } | crontab -
echo "New Cron Entry Added: `crontab -l`";
fi;

fi;
}

statusOO() {
###################################
# Open Office Status
###################################
cd ${OO_HOME}
oopid=`ps -eaf | grep soffice | grep -v grep | awk '{print $2}'`
ooport=`netstat -an | grep -v grep | grep ":${OO_PORT}" | grep LISTEN`
if [[ $oopid && $ooport ]]; then
echo -e "OpenOffice Service : \t\t\E[0;32m[ RUNNING ]\E[0m ";
retval=1
else
echo -e "OpenOffice Service : \t\t\E[0;31m[ SHUTDOWN ]\E[0m ";
retval=0
fi;

return "$retval"
}

restartOO() {
###################################
# Restart Open Office Service
###################################
stopOO
startOO
}
case $1 in
stopOO)stopOO;;
startOO)startOO;;
statusOO)statusOO;;
restartOO)restartOO;;
monitorOO)monitorOO;;
addcron)addcron;;
*) echo -e "\E[32m Usage: $0 {OPTION}\E[0m\n\E[36m Available Options:\n {\E[0m\n stopOO\t\tstartOO\n restartOO\taddcron\n statusOO\tmonitorOO\n \E[0m\E[36m}\E[0m "
;;
esac

If You want to know more about open office you can go to Open Office Wikipedia Link.

In case of any ©Copyright or missing credits issue please check CopyRights page for faster resolutions.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.