Skip to content

Commit

Permalink
fix: remove lock file when the service fails to start
Browse files Browse the repository at this point in the history
  • Loading branch information
raymond-u committed Mar 15, 2024
1 parent cd14db9 commit 48dc393
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Remove lock file when the service fails to start
- Fix the recurrent Nginx socket binding issue
- Remove an incorrect instruction from the documentation

Expand Down
22 changes: 13 additions & 9 deletions src/lungo_cli/core/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ def build(self, working_dir: str | PathLike[str] | None = None, service: EApp |
def up(self, working_dir: str | PathLike[str] | None = None) -> None:
if self.storage.lock_file.is_file():
self.console.print_error(
f"An existing instance of {APP_NAME_CAPITALIZED} is running. Please stop it before proceeding. "
f"Or, you can use the {format_command('--ignore-lock')} option."
f"An existing instance of {APP_NAME_CAPITALIZED} is running. Please stop it before proceeding, "
f"or use the {format_command('--ignore-lock')} flag."
)
raise Exit(code=1)

Expand All @@ -132,13 +132,17 @@ def up(self, working_dir: str | PathLike[str] | None = None) -> None:
if not working_dir:
self.file_utils.create(self.storage.lock_file)

match tool:
case EContainer.DOCKER:
self.run_shell_command("docker", "compose", "up", "-d", "--build", cwd=working_dir)
case EContainer.DOCKER_COMPOSE:
self.run_shell_command("docker-compose", "up", "-d", "--build", cwd=working_dir)
case EContainer.PODMAN_COMPOSE:
self.run_shell_command("podman-compose", "up", "-d", "--build", cwd=working_dir)
try:
match tool:
case EContainer.DOCKER:
self.run_shell_command("docker", "compose", "up", "-d", "--build", cwd=working_dir)
case EContainer.DOCKER_COMPOSE:
self.run_shell_command("docker-compose", "up", "-d", "--build", cwd=working_dir)
case EContainer.PODMAN_COMPOSE:
self.run_shell_command("podman-compose", "up", "-d", "--build", cwd=working_dir)
except Exception:
self.file_utils.remove(self.storage.lock_file)
raise

def down(self, working_dir: str | PathLike[str] | None = None) -> None:
match self.choose_tool():
Expand Down

0 comments on commit 48dc393

Please sign in to comment.