Skip to content

Commit

Permalink
Daemon: Fix false-positive of stopped daemon in verdi daemon status (
Browse files Browse the repository at this point in the history
…aiidateam#5862)

A number of `verdi` commands will check whether the daemon process ID,
which is stored in a PID-file, has gone stale in which case it is
removed and the daemon is considered stopped.

The check is based on the PID written in the file still existing but to
be sure the same PID hadn't be recycled for another process (unlikely
but possible) it compared the command name of the process with what it
would expect. The expected command is `start-circus` since that is the
`verdi` command that is launched by `verdi daemon start`. However, on
certain machines (for reasons as of yet unknown) the command name is
`circusd` instead.

In this case, the `delete_stale_pid_file` utility would always conclude
the PID was stale and so remove the PID-file. This would result in
`verdi daemon status` to always say the daemon is not running (since it
simply checks the existance of a PID-file) even though multiple daemon
processes would be running in the background (which could also not be
killed through `verdi`).
  • Loading branch information
ltalirz authored Jan 26, 2023
1 parent 65c1b32 commit b35704f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions aiida/cmdline/utils/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

from aiida.cmdline.utils import echo

_START_CIRCUS_COMMAND = 'start-circus'
# circus daemon process can appear as 'start-circus' or 'circusd'
# see https://github.com/aiidateam/aiida-core/issues/5336#issuecomment-1376093322
_START_CIRCUS_COMMANDS = ['start-circus', 'circusd']


def print_client_response_status(response):
Expand Down Expand Up @@ -127,7 +129,7 @@ class StartCircusNotFound(Exception):
try:
process = psutil.Process(pid)
# the PID got recycled, but a different process
if _START_CIRCUS_COMMAND not in process.cmdline():
if not any(cmd in process.cmdline() for cmd in _START_CIRCUS_COMMANDS):
raise StartCircusNotFound() # Also this is a case in which the process is not there anymore

# the PID got recycled, but for a daemon of someone else
Expand Down

0 comments on commit b35704f

Please sign in to comment.