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

Commit

Permalink
Merge pull request #652 from gamechanger/tnt-shutdown
Browse files Browse the repository at this point in the history
Add dusty shutdown command
  • Loading branch information
thieman committed Feb 17, 2016
2 parents 997aade + 0cabd98 commit f1cc89d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Dusty app and lib spec filenames must now abide by Docker image naming conventions: `[a-z0-9]+(?:[._-][a-z0-9]+)*`. Your file name must start with a number or lowercase letter, cannot have uppercase letters, and can only have `.`, `_`, and `-` as special characters.
* Dusty requires Docker Machine 0.5.0+
* **New**
* Added `dusty shutdown` command to shut down Dusty's virtual machine
* Added `--only` flag to `bundles activate` which makes it easier to turn on a selection of bundles and deactivate all others
* Added support for SCP style GitHub urls. Example: [email protected]:gamechanger/dusty.git
* Added `image_requires_login` key to specs which can specify Docker images to pull. If set, Dusty will make sure the user is logged in to this image's repository before trying to pull the image
Expand Down
8 changes: 8 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,14 @@ Example:
dusty shell website
```

#### shutdown
```
Shut down the Dusty VM.
Usage:
shutdown
```

#### status
```
Give information on activated apps, services and
Expand Down
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 f1cc89d

Please sign in to comment.