Check if daemon is running, clean up stale PID files. Returns: True if daemon is running, False otherwise
()
| 50 | |
| 51 | |
| 52 | def is_daemon_running() -> bool: |
| 53 | """Check if daemon is running, clean up stale PID files. |
| 54 | |
| 55 | Returns: |
| 56 | True if daemon is running, False otherwise |
| 57 | """ |
| 58 | if not PID_FILE.exists(): |
| 59 | return False |
| 60 | |
| 61 | try: |
| 62 | with open(PID_FILE, "r") as f: |
| 63 | pid = int(f.read().strip()) |
| 64 | |
| 65 | # Check if process exists |
| 66 | if psutil.pid_exists(pid): |
| 67 | return True |
| 68 | else: |
| 69 | # Stale PID file - remove it |
| 70 | print(f"Removing stale PID file: {PID_FILE}") |
| 71 | PID_FILE.unlink() |
| 72 | return False |
| 73 | except KeyboardInterrupt as ki: |
| 74 | handle_keyboard_interrupt(ki) |
| 75 | raise |
| 76 | except Exception: |
| 77 | # Corrupted PID file - remove it |
| 78 | try: |
| 79 | PID_FILE.unlink(missing_ok=True) |
| 80 | except KeyboardInterrupt as ki: |
| 81 | handle_keyboard_interrupt(ki) |
| 82 | raise |
| 83 | except Exception: |
| 84 | pass |
| 85 | return False |
| 86 | |
| 87 | |
| 88 | def start_daemon() -> None: |
no test coverage detected