-
Notifications
You must be signed in to change notification settings - Fork 150
feat(cli): dimos restart command (DIM-683) #1476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e9f90c1
4762372
fd0b8a9
9b0efa8
da57ea1
7406c2c
49fb529
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,9 @@ | |
|
|
||
| import inspect | ||
| import json | ||
| import os | ||
| import sys | ||
| import time | ||
| from typing import Any, get_args, get_origin | ||
|
|
||
| import click | ||
|
|
@@ -190,6 +192,7 @@ def run( | |
| log_dir=str(log_dir), | ||
| cli_args=list(robot_types), | ||
| config_overrides=cli_config_overrides, | ||
| original_argv=sys.argv, | ||
| ) | ||
| entry.save() | ||
| install_signal_handlers(entry, coordinator) | ||
|
|
@@ -203,6 +206,7 @@ def run( | |
| log_dir=str(log_dir), | ||
| cli_args=list(robot_types), | ||
| config_overrides=cli_config_overrides, | ||
| original_argv=sys.argv, | ||
| ) | ||
| entry.save() | ||
| try: | ||
|
|
@@ -394,6 +398,46 @@ def agent_send_cmd( | |
| typer.echo(text) | ||
|
|
||
|
|
||
| @main.command() | ||
| def restart( | ||
| force: bool = typer.Option(False, "--force", "-f", help="Force kill before restarting"), | ||
| ) -> None: | ||
| """Restart the running DimOS instance with the same arguments.""" | ||
|
Comment on lines
+401
to
+405
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The PR description explicitly advertises If background restart is genuinely desired, a |
||
| from dimos.core.run_registry import get_most_recent, stop_entry | ||
|
|
||
| entry = get_most_recent(alive_only=True) | ||
| if not entry: | ||
| typer.echo("No running DimOS instance to restart", err=True) | ||
| raise typer.Exit(1) | ||
|
|
||
| if not entry.original_argv: | ||
| typer.echo("Cannot restart: run entry missing original command", err=True) | ||
| raise typer.Exit(1) | ||
|
|
||
| # Save argv and pid before stopping (stop removes the entry) | ||
| argv = entry.original_argv | ||
| old_pid = entry.pid | ||
|
|
||
| typer.echo(f"Restarting {entry.run_id} ({entry.blueprint})...") | ||
| msg, _ok = stop_entry(entry, force=force) | ||
| typer.echo(f" {msg}") | ||
|
|
||
| # Wait for the old process to fully exit so ports are released. | ||
| from dimos.core.run_registry import is_pid_alive | ||
|
|
||
| for _ in range(20): # up to 2s | ||
| if not is_pid_alive(old_pid): | ||
| break | ||
| time.sleep(0.1) | ||
|
|
||
| typer.echo(f" Running: {' '.join(argv)}") | ||
| try: | ||
| os.execvp(argv[0], argv) | ||
| except OSError as exc: | ||
| typer.echo(f"Error: failed to restart — {exc}", err=True) | ||
| raise typer.Exit(1) | ||
|
|
||
|
|
||
| @main.command() | ||
| def show_config(ctx: typer.Context) -> None: | ||
| """Show current config settings and their values.""" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very minor suggestion, but it might be good to make these kind of things immutable in future generally. This also avoids needing the default_factory: