Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Commit

Permalink
Add dusty shutdown command
Browse files Browse the repository at this point in the history
  • Loading branch information
thieman committed Feb 17, 2016
1 parent 997aade commit b698377
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
6 changes: 4 additions & 2 deletions dusty/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
scripts Execute predefined scripts inside running containers
setup Configure Dusty after installation
shell Open a shell inside a running container
shutdown Shut down the Dusty VM
status Show info on activated apps, services and libs
stop Stop Dusty-managed containers
test Run test scripts in isolated environments
Expand Down Expand Up @@ -44,8 +45,8 @@
from ..config import get_config_value
from ..log import configure_client_logging, log_to_client
from ..payload import Payload
from . import (assets, bundles, config, cp, dump, disk, env, logs, repos, restart, scripts, shell, stop,
up, upgrade, validate, version, setup, test, status)
from . import (assets, bundles, config, cp, dump, disk, env, logs, repos, restart, scripts, shell,
shutdown, stop, up, upgrade, validate, version, setup, test, status)
from .. import constants

MODULE_MAP = {
Expand All @@ -62,6 +63,7 @@
'scripts': scripts,
'setup': setup,
'shell': shell,
'shutdown': shutdown,
'status': status,
'stop': stop,
'test': test,
Expand Down
14 changes: 14 additions & 0 deletions dusty/cli/shutdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Shut down the Dusty VM.
Usage:
shutdown
"""

from docopt import docopt

from ..payload import Payload
from ..commands.run import shutdown_dusty_vm

def main(argv):
args = docopt(__doc__, argv)
return Payload(shutdown_dusty_vm)
10 changes: 9 additions & 1 deletion dusty/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
from ..systems.docker import compose
from ..systems.docker.config import (get_authed_registries, registry_from_image,
log_in_to_registry)
from ..systems.virtualbox import docker_vm_is_running, shut_down_docker_vm
from ..log import log_to_client
from .repos import update_managed_repos
from .. import constants
from ..command_file import make_up_command_files
from ..source import Repo
from ..payload import daemon_command
from ..warnings import daemon_warnings
from ..subprocess import check_call_demoted
from ..subprocess import check_call_demoted, check_and_log_output_and_error_demoted

@daemon_command
def prep_for_start_local_env(pull_repos):
Expand Down Expand Up @@ -139,3 +140,10 @@ def restart_apps_by_repo(repo_names):
if spec_assembler.get_same_container_repos_from_spec(app_spec).intersection(resolved_repos):
apps_with_repos.add(app_spec.name)
restart_apps_or_services(apps_with_repos)

@daemon_command
def shutdown_dusty_vm():
if docker_vm_is_running():
stop_apps_or_services()
log_to_client('Shutting down Dusty VM')
shut_down_docker_vm()
7 changes: 7 additions & 0 deletions dusty/systems/virtualbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ def initialize_docker_vm():
_ensure_cp_dir_exists()
_ensure_assets_dir_exists()

def shut_down_docker_vm():
if docker_vm_is_running():
check_call_demoted(['docker-machine', 'stop', constants.VM_MACHINE_NAME])
log_to_client('Dusty VM was shut down')
else:
log_to_client('Dusty VM is already shut down')

@memoized
def get_docker_vm_ip():
ssh_port = None
Expand Down

0 comments on commit b698377

Please sign in to comment.