I am new to the the world of init scripts and still a BASH neophyte. I'm currently in a situation where I could use some guidance.
We run an application that utilizes JBOSS and I need to be able to handle it like a daemon using an init script. This is my first time writing an init script and I understand that often '.pid' files are used to keep track of a process using an init script, however I wonder if they are really needed in my situation.
For example, when I go to use the "stop" function of my init script, I can have it check the .pid file to get the process ID, or I can simply have it get the PID using "checkproc".
Here is an example of what I have written.
JBOSSPID=$(checkproc -v $JBOSS_PROCESS_NAME)
function _stop {
# Check if JBOSS is running..
if [ -z "$JBOSSPID" ]; then
echo "Service is not running.."
exit
fi
# Attempt to shutdown JBOSS gracefully..
echo "Stopping service.."
./stop_jboss.sh
# Loop until JBOSS PID no longer exists..
RUNNING=0
while [ "$RUNNING" == "0" ]
do
JBOSSPID=$(checkproc -v $JBOSS_PROCESS_NAME)
if [ "$JBOSSPID" == "" ]; then
RUNNING=1
fi
done
}
I've wrote my "start" and "status" functions to obtain the PID like this as well. I tested it and it seems to work fine, but I don't know if there is something I'm missing that could go wrong without a .pid file. Are there any reasons for me to scrap this logic and instead utilize a .pid file?