Recycle Jboss server script

Hello, I need help writing a script to restart our Jboss server when it crashes. I am not very good with scripting but here is the basics.

1) I'm hoping to use KornShell
2) The command to stop the Jboss is "/var/opt/HP/ALM/jboss/bin/run.sh stop"
3) I want to verify the jboss is stopped before attempting to restart, not sure how to do this at all
4) Start the jboss "/var/opt/HP/ALM/jboss/bin/run.sh start"

Should be very simple but I just am not sure where to start, how to get that stop/start command to be input into the string. Can anyone help?

For detecting the server crash, you need some info from which to tell that, maybe from a log file generated by the JBoss server, you can setup a cron job to grep the log file regularly. After that, you can try to stop the JBoss server with its stop script, wait some time and then use ps -ef | grep my_jboss_server to check whether it's stopped, if it is not, you may want to directly kill the process(Caution, killing a JBoss process directly may cause some damage to your data, some lifecycle code may not be executed).

The following script is for reference:

crash_msg=$(grep -o "AN_ERROR_MSG_MEANS_CRASH" jboss_log_file)
if [[ $crash_msg != "" ]]; then
    /var/opt/HP/ALM/jboss/bin/run.sh stop
    sleep 5
    ps -ef | awk '/my_jboss_server/{print $2}' | xargs kill -9 # change my_jboss_server to a relevant string in your environment
    /var/opt/HP/ALM/jboss/bin/run.sh start
fi

Note: Try these commands at home before you use them on production environment.