Skip to content

Commit

Permalink
DaemonClient: Clean stale PID file in stop_daemon (#6007)
Browse files Browse the repository at this point in the history
The daemon client was recently refactored to only clean the stale PID
file in the `start_daemon` command. Before it was done when asking the
status which was considered an unexpected side-effect.

Sometimes, the user wants to make sure the daemon is no longer running.
Currently, the status would raise a warning if a stale PID file is found
suggesting the user to start the daemon to fix it. However, this is
counterintuitve and not desirable if the goal is for the daemon to be
stopped.

The `stop_daemon` method is updated to also clean any potentially stale
PID files. The error message is updated to suggest to either start or
stop the daemon to return it to a nominal state.

Co-authored-by: Sebastiaan Huber <mail@sphuber.net>
  • Loading branch information
unkcpz and sphuber committed May 11, 2023
1 parent f36bf58 commit 2bfc3c6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions aiida/engine/daemon/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ def call_client(self, command: dict[str, t.Any], timeout: int | None = None) ->

if self._is_pid_file_stale:
raise DaemonStalePidException(
'The daemon could not be reached, seemingly because of a stale PID file. Try starting the daemon '
'to remove it and restore the daemon.'
'The daemon could not be reached, seemingly because of a stale PID file. Either stop or start the '
'daemon to remove it and restore the daemon to a functional state.'
) from exception

if str(exception) == 'Timed out.':
Expand Down Expand Up @@ -557,6 +557,8 @@ def stop_daemon(self, wait: bool = True, timeout: int | None = None) -> dict[str
:raises DaemonTimeoutException: If the connection to the daemon timed out.
:raises DaemonException: If the connection to the daemon failed for any other reason.
"""
self._clean_potentially_stale_pid_file()

command = {'command': 'quit', 'properties': {'waiting': wait}}
response = self.call_client(command, timeout=timeout)

Expand Down

0 comments on commit 2bfc3c6

Please sign in to comment.