Load process information from .env file.
(cls)
| 72 | |
| 73 | @classmethod |
| 74 | def load(cls) -> 'ProcessInfo': |
| 75 | """Load process information from .env file.""" |
| 76 | try: |
| 77 | for key in dotenv_values(cls._env_file).keys(): |
| 78 | os.environ.pop(key, None) # Remove old values |
| 79 | |
| 80 | if ProcessInfo._env_file.exists(): |
| 81 | load_dotenv(ProcessInfo._env_file, override=True) |
| 82 | |
| 83 | pid_str = os.getenv('KEEPER_SERVICE_PID') |
| 84 | pid = int(pid_str) if pid_str else None |
| 85 | |
| 86 | terminal = os.getenv('KEEPER_SERVICE_TERMINAL') or None |
| 87 | |
| 88 | is_running_str = os.getenv('KEEPER_SERVICE_IS_RUNNING', 'false') |
| 89 | is_running = ProcessInfo._str_to_bool(is_running_str) |
| 90 | |
| 91 | ngrok_pid_str = os.getenv('KEEPER_SERVICE_NGROK_PID') |
| 92 | ngrok_pid = int(ngrok_pid_str) if ngrok_pid_str else None |
| 93 | |
| 94 | cloudflare_pid_str = os.getenv('KEEPER_SERVICE_CLOUDFLARE_PID') |
| 95 | cloudflare_pid = int(cloudflare_pid_str) if cloudflare_pid_str else None |
| 96 | |
| 97 | tailscale_enabled_str = os.getenv('KEEPER_SERVICE_TAILSCALE_ENABLED', 'false') |
| 98 | tailscale_enabled = ProcessInfo._str_to_bool(tailscale_enabled_str) |
| 99 | |
| 100 | tailscale_port_str = os.getenv('KEEPER_SERVICE_TAILSCALE_PORT') |
| 101 | tailscale_port = int(tailscale_port_str) if tailscale_port_str else None |
| 102 | |
| 103 | logger.debug("Process information loaded successfully from .env") |
| 104 | return ProcessInfo( |
| 105 | pid=pid, |
| 106 | terminal=terminal, |
| 107 | is_running=is_running, |
| 108 | ngrok_pid=ngrok_pid, |
| 109 | cloudflare_pid=cloudflare_pid, |
| 110 | tailscale_enabled=tailscale_enabled, |
| 111 | tailscale_port=tailscale_port |
| 112 | ) |
| 113 | except Exception as e: |
| 114 | logger.error(f"Failed to load process information: {e}") |
| 115 | pass |
| 116 | |
| 117 | return ProcessInfo(pid=None, terminal=None, is_running=False, ngrok_pid=None, cloudflare_pid=None, |
| 118 | tailscale_enabled=False, tailscale_port=None) |
| 119 | |
| 120 | @classmethod |
| 121 | def clear(cls) -> None: |
no test coverage detected