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.


function _stop {
   # Check if JBOSS is running..
   if [ -z "$JBOSSPID" ]; then
      echo "Service is not running.."

   # Attempt to shutdown JBOSS gracefully..
   echo "Stopping service.."

   # Loop until JBOSS PID no longer exists..
   while [ "$RUNNING" == "0" ]
      JBOSSPID=$(checkproc -v $JBOSS_PROCESS_NAME)
      if [ "$JBOSSPID" == "" ]; then

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?

  • 1
    You can avoid this hassle if your OS supports upstart jobs (Ubuntu, Centos 6) or Systemd (Debian, Centos 7).
    – jordanm
    Nov 9, 2015 at 14:28
  • actually, PID files come from sysvinit only starting services and not keeping track of them afterwards. sysvinit is every bit as flexible as upstart or systemd...but its design criteria is much simpler, from a simpler age. PID files exist to help other tools (or the admin on the command line) keep track of and manage daemons after they've been started.
    – cas
    Nov 10, 2015 at 1:49

1 Answer 1


You can make your init script without a pid file, there will be no problems with it. Unless another user will start a jboss instance manually. I don't think your init script can cope with multiple lines returned by "checkproc -v $JBOSS_PROCESS_NAME"

The pid file is mainly useful when there is a possibility that multiple applications will be started on the same machine. You don't want your init script to stop instances started by other users.

So, instead of killing the first (or all) programs that have a specific string, you save the pid file of the program started from the init script. This way, when you try to kill the program, you will only kill the one started by you.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .