Coverage for frappe_manager / commands / restart.py: 43%
37 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-07-02 18:13 +0530
« prev ^ index » next coverage.py v7.13.5, created at 2026-07-02 18:13 +0530
1from typing import Annotated
3import typer
4from typer_examples import example
6from frappe_manager.commands import check_bench_migration_required
7from frappe_manager.output_manager import get_global_output_handler, spinner
8from frappe_manager.site_manager.site import Bench
9from frappe_manager.utils.callbacks import sitename_callback, sites_autocompletion_callback
12@example(
13 "Restart web and workers (default)",
14 "{benchname}",
15 detail="Restarts both web and worker services for the bench. Safe for applying configuration changes.",
16 benchname="mybench",
17)
18@example(
19 "Restart via container restart",
20 "{benchname} --container",
21 detail="Restarts by restarting the entire Docker containers (slower but thorough).",
22 benchname="mybench",
23)
24@example(
25 "Restart via supervisor (faster)",
26 "{benchname} --supervisor",
27 detail="Uses supervisor to restart processes inside containers for a faster restart without recreating containers.",
28 benchname="mybench",
29)
30@example(
31 "Restart web services only",
32 "{benchname} --web --no-workers",
33 detail="Restarts only web-related services (frappe, socketio) without touching workers.",
34 benchname="mybench",
35)
36@example(
37 "Restart workers only",
38 "{benchname} --workers --no-web",
39 detail="Restarts worker processes (schedule, long/short workers) while leaving web services running.",
40 benchname="mybench",
41)
42@example(
43 "Force restart (immediate kill)",
44 "{benchname} --force",
45 detail="Performs an immediate kill and restart; use when processes are unresponsive.",
46 benchname="mybench",
47)
48@example(
49 "Restart redis services",
50 "{benchname} --redis",
51 detail="Restarts Redis instances used by the bench (cache and queue backends).",
52 benchname="mybench",
53)
54@example(
55 "Restart nginx service",
56 "{benchname} --nginx",
57 detail="Restarts the nginx service for the bench, useful after configuration changes to proxy or TLS.",
58 benchname="mybench",
59)
60def restart(
61 ctx: typer.Context,
62 benchname: Annotated[
63 str | None,
64 typer.Argument(
65 help="Name of the bench.",
66 autocompletion=sites_autocompletion_callback,
67 callback=sitename_callback,
68 ),
69 ] = None,
70 web: Annotated[
71 bool,
72 typer.Option(help="Restart web service i.e socketio and frappe server."),
73 ] = True,
74 workers: Annotated[
75 bool,
76 typer.Option(help="Restart worker services i.e schedule and all workers."),
77 ] = True,
78 redis: Annotated[
79 bool,
80 typer.Option(help="Restart redis services."),
81 ] = False,
82 nginx: Annotated[
83 bool,
84 typer.Option(help="Restart nginx service."),
85 ] = False,
86 container: Annotated[
87 bool,
88 typer.Option(
89 "--container",
90 help="Restart entire Docker container(s). Stops and starts the container.",
91 ),
92 ] = False,
93 supervisor: Annotated[
94 bool,
95 typer.Option(
96 "--supervisor",
97 help="Restart supervisor processes inside container. Faster than container restart.",
98 ),
99 ] = False,
100 force: Annotated[
101 bool,
102 typer.Option(
103 "--force",
104 help="Force restart: --supervisor uses stop+start (kills processes), --container uses timeout=0 (immediate kill).",
105 ),
106 ] = False,
107):
108 """
109 Restart bench services (web, workers, redis, nginx).
111 Choose between container-level restarts or supervisor-level restarts for faster in-container restarts.
112 """
114 check_bench_migration_required(benchname)
116 services_manager = ctx.obj["services"]
117 verbose = ctx.obj["verbose"]
119 output = get_global_output_handler()
120 logger = ctx.obj.get("logger")
121 bench = Bench.get_object(benchname, services_manager, logger=logger, output_handler=output)
123 use_container_restart = container
124 use_supervisor_restart = supervisor
126 if not use_container_restart and not use_supervisor_restart:
127 use_supervisor_restart = True
129 if use_container_restart and use_supervisor_restart:
130 output.error("Cannot use both --container and --supervisor flags simultaneously", exception=typer.Exit(code=1))
132 with spinner(output, f"Restarting {benchname}"):
133 if web:
134 bench.restart_web_containers_services(use_container_restart=use_container_restart, force=force)
136 if workers:
137 bench.restart_workers_containers_services(use_container_restart=use_container_restart, force=force)
139 if redis:
140 bench.restart_redis_services_containers()
142 if nginx:
143 bench.restart_nginx_service(force=force)