mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2026-09-05 02:24:21 -05:00
* cmds: Adjust stop daemon output
Stopping the daemon without this patch prints:
```
daemon: {'ack': True, 'command': 'exit', 'data': {'success': True},
'destination': 'client', 'origin': 'daemon', 'request_id': 'some
request_id hash here'}
```
Stopping the daemon with this patch prints:
```
Daemon stopped
```
and if it fails:
```
Stop daemon failed {'ack': True, 'command': 'exit', 'data': {'success':
True},
'destination': 'client', 'origin': 'daemon', 'request_id': 'some
request_id hash here'}
```
* Simplify check
Co-authored-by: Kyle Altendorf <sda@fstab.net>
Co-authored-by: Kyle Altendorf <sda@fstab.net>
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
import sys
|
|
from pathlib import Path
|
|
|
|
import click
|
|
|
|
from chia.util.service_groups import all_groups, services_for_groups
|
|
|
|
|
|
async def async_stop(root_path: Path, group: str, stop_daemon: bool) -> int:
|
|
from chia.daemon.client import connect_to_daemon_and_validate
|
|
|
|
daemon = await connect_to_daemon_and_validate(root_path)
|
|
if daemon is None:
|
|
print("Couldn't connect to chia daemon")
|
|
return 1
|
|
|
|
if stop_daemon:
|
|
r = await daemon.exit()
|
|
await daemon.close()
|
|
if r.get("data", {}).get("success", False):
|
|
print("Daemon stopped")
|
|
else:
|
|
print(f"Stop daemon failed {r}")
|
|
return 0
|
|
|
|
return_val = 0
|
|
|
|
for service in services_for_groups(group):
|
|
print(f"{service}: ", end="", flush=True)
|
|
if not await daemon.is_running(service_name=service):
|
|
print("Not running")
|
|
elif await daemon.stop_service(service_name=service):
|
|
print("Stopped")
|
|
else:
|
|
print("Stop failed")
|
|
return_val = 1
|
|
|
|
await daemon.close()
|
|
return return_val
|
|
|
|
|
|
@click.command("stop", short_help="Stop services")
|
|
@click.option("-d", "--daemon", is_flag=True, type=bool, help="Stop daemon")
|
|
@click.argument("group", type=click.Choice(list(all_groups())), nargs=-1, required=True)
|
|
@click.pass_context
|
|
def stop_cmd(ctx: click.Context, daemon: bool, group: str) -> None:
|
|
import asyncio
|
|
|
|
sys.exit(asyncio.run(async_stop(ctx.obj["root_path"], group, daemon)))
|