From 099850980d4a0097b5ecbeda4e8db6021d1ecde0 Mon Sep 17 00:00:00 2001 From: Dmitry Volodin Date: Tue, 1 Oct 2024 10:48:20 +0200 Subject: [PATCH] Restart command --- CHANGELOG.md | 4 ++++ src/gufo/thor/cli.py | 2 +- src/gufo/thor/docker.py | 13 +++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 072e80c..a1cfb16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ To see unreleased changes, please see the [CHANGELOG on the master branch](https * Do not raise exception when cannot start browser. +### Added + +* `restart` command. + ## 0.6.0 - 2024-08-05 ### Added diff --git a/src/gufo/thor/cli.py b/src/gufo/thor/cli.py index e7ea915..91cf22e 100644 --- a/src/gufo/thor/cli.py +++ b/src/gufo/thor/cli.py @@ -245,7 +245,7 @@ def handle_restart(self: "Cli", ns: argparse.Namespace) -> ExitCode: r = self.handle_prepare(ns) if r != ExitCode.OK: return r - if not docker.restart(ns.services): + if not docker.restart(*ns.services): return ExitCode.ERR return ExitCode.OK diff --git a/src/gufo/thor/docker.py b/src/gufo/thor/docker.py index 70ae78f..ecd2767 100644 --- a/src/gufo/thor/docker.py +++ b/src/gufo/thor/docker.py @@ -135,6 +135,19 @@ def stop(self: "Docker") -> bool: logger.warning("Stopping containers") return self._commpose_command("stop") + def restart(self: "Docker", *args: str) -> bool: + """ + Perform services restart. + + Returns: + True: if command executed successfully. + False: otherwise. + """ + logger.warning("Restarting containers: %s", ", ".join(args)) + return self._commpose_command( + *("stop", *args) + ) and self._commpose_command(*("up", "-d", *args)) + def shell(self: "Docker") -> bool: """ Run shell in container.