From fc2c9cb04ef80de02dc127527461692052f7a6e4 Mon Sep 17 00:00:00 2001 From: ldericher Date: Tue, 25 Aug 2020 15:42:53 +0200 Subject: [PATCH] Subcommand "restart" --- src/etc/command_help.txt | 1 + src/kiwi/subcommands/__init__.py | 2 ++ src/kiwi/subcommands/restart.py | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 src/kiwi/subcommands/restart.py diff --git a/src/etc/command_help.txt b/src/etc/command_help.txt index d730f3b..798a699 100644 --- a/src/etc/command_help.txt +++ b/src/etc/command_help.txt @@ -2,6 +2,7 @@ Commands for Operation: up Bring up the whole instance, a project or service(s) inside a project down Bring down the whole instance, a project or service(s) inside a project update Update the whole instance, a project or service(s) inside a project + restart Restart the whole instance, a project or service(s) inside a project purge Remove all running docker artifacts of this instance Commands for Instance Management: diff --git a/src/kiwi/subcommands/__init__.py b/src/kiwi/subcommands/__init__.py index aed1a90..f7829e1 100644 --- a/src/kiwi/subcommands/__init__.py +++ b/src/kiwi/subcommands/__init__.py @@ -13,6 +13,7 @@ from .new import NewCommand from .pull import PullCommand from .purge import PurgeCommand from .push import PushCommand +from .restart import RestartCommand from .shell import ShellCommand from .up import UpCommand from .update import UpdateCommand @@ -33,6 +34,7 @@ __all__ = [ 'PullCommand', 'PurgeCommand', 'PushCommand', + 'RestartCommand', 'ShellCommand', 'UpCommand', 'UpdateCommand', diff --git a/src/kiwi/subcommands/restart.py b/src/kiwi/subcommands/restart.py new file mode 100644 index 0000000..d8856c9 --- /dev/null +++ b/src/kiwi/subcommands/restart.py @@ -0,0 +1,26 @@ +# local +from ..subcommand import ServiceCommand +from ..misc import are_you_sure + + +class RestartCommand(ServiceCommand): + """kiwi restart""" + + def __init__(self): + super().__init__( + 'restart', num_projects='?', num_services='*', + action="Restarting", + description="Restart the whole instance, a project or service(s) inside a project" + ) + + def _run_instance(self, runner, args): + if are_you_sure([ + "This will restart the entire instance." + ]): + return super()._run_instance(runner, args) + + return False + + def _run_services(self, runner, args, project, services): + project.compose_run(['restart', *services]) + return True