Compare commits
1 Commits
f218f3ebc2
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 4c9cd00c90 |
@@ -2,7 +2,6 @@ import os
|
||||
import shlex
|
||||
import shutil
|
||||
import signal
|
||||
import socket
|
||||
import subprocess
|
||||
import time
|
||||
from dataclasses import dataclass
|
||||
@@ -115,20 +114,9 @@ def build_autossh_cmd(tunnel: TunnelConfig) -> list[str]:
|
||||
return cmd
|
||||
|
||||
|
||||
def _is_port_in_use(port: int) -> bool:
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
try:
|
||||
s.bind(("127.0.0.1", port))
|
||||
return False
|
||||
except OSError:
|
||||
return True
|
||||
|
||||
|
||||
def start_tunnel(config_dir: Path, tunnel: TunnelConfig) -> int:
|
||||
if not shutil.which("autossh"):
|
||||
raise click.ClickException("autossh not found. Install it first.")
|
||||
if _is_port_in_use(tunnel.local_port):
|
||||
raise click.ClickException(f"Port {tunnel.local_port} is already in use")
|
||||
|
||||
log_path = config_dir / "logs" / f"{tunnel.name}.log"
|
||||
log_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
Reference in New Issue
Block a user