Skip to content

Commit

Permalink
prevents multiple copies of same service with lockfile (Chia-Network#…
Browse files Browse the repository at this point in the history
  • Loading branch information
wbendick committed May 12, 2021
1 parent d3a71c3 commit 25f4b6c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions chia/daemon/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,14 @@ def daemon_launch_lock_path(root_path: Path) -> Path:
return root_path / "run" / "start-daemon.launching"


def service_launch_lock_path(root_path: Path, service: str) -> Path:
"""
A path to a file that is lock when a service is running.
"""
service_name = service.replace(" ", "-").replace("/", "-")
return root_path / "run" / f"{service_name}.lock"


def pid_path_for_service(root_path: Path, service: str, id: str = "") -> Path:
"""
Generate a path for a PID file for the given service name.
Expand Down Expand Up @@ -766,6 +774,11 @@ def launch_service(root_path: Path, service_command) -> Tuple[subprocess.Popen,

log.debug(f"Launching service with CHIA_ROOT: {os.environ['CHIA_ROOT']}")

lockfile = singleton(service_launch_lock_path(root_path, service_command))
if lockfile is None:
logging.error(f"{service_command}: already running")
raise subprocess.SubprocessError

# Insert proper e
service_array = service_command.split()
service_executable = executable_for_service(service_array[0])
Expand Down

0 comments on commit 25f4b6c

Please sign in to comment.