Check status of process

Hi All,
Have a query
How to check for a process and if down start it , try if for 2 times and its not starting don't do it
My code is working to some extent but while starting try starting both times.

Please advise , whats wrong here ?
if you have any other approach please do share.

My code

#!/bin/bash


file="/root/jboss.txt"
if [ -f "$file" ]
   then
   Exit 1
                else
		 
               
                A=$(ps -ef | grep 'jboss' | grep -v 'grep' | awk '{ printf $2 }')
                echo $A
                    if [ -z "$A" ]; then
                       
                                 starting jboss
                                if [ $? -eq 0 ]; then
                                   
                                else
                                   
								fi
                                  #starting jboss 2nd time
                                  starting jboss 
                                if [ $? -eq 0 ]; then
                                   echo "startted
                                else
                                   echo "Failed"
                                   touch jboss.txt
                                fi
                    else
                    echo "jboss is RUNNING"
                    fi
fi


Thanks
abhaydas

Please explain what you mean by:

Thanks.