>_ IzzyLab

Topic breakdown

Many daemons use a lock file (pidfile) as a sign of "I'm already running", so as not to bring up a second instance on top of a live one. The problem is that on a crash the process doesn't get to clean up this file — and a "stale" lock remains, because of which the start script thinks the daemon is running, even though the process is long gone. The correct order is to first confirm via pgrep/ps that there really is no live process (otherwise you get a race between two instances), and only then delete the stale lock. When starting the daemon, keep in mind that a foreground process will die together with the session — it needs to be detached from the TTY (setsid, nohup, disown).

What's checked

  1. the worker daemon is running
  2. exactly one worker instance is running
  3. the lock points to the running worker

What it looks like