File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 28
28
template_files = files ("murfey" ) / "templates"
29
29
templates = Jinja2Templates (directory = template_files )
30
30
31
+ _running_server : uvicorn .Server | None = None
32
+
31
33
32
34
def respond_with_template (filename : str , parameters : dict [str , Any ] | None = None ):
33
35
template_parameters = {
@@ -179,16 +181,26 @@ def run():
179
181
logger .info (
180
182
f"Starting Murfey server version { murfey .__version__ } , listening on { args .host } :{ args .port } "
181
183
)
182
- uvicorn .run (
184
+ global _running_server
185
+ config = uvicorn .Config (
183
186
"murfey.server.main:app" ,
184
187
host = args .host ,
185
188
port = args .port ,
186
189
env_file = args .env_file ,
187
190
log_config = None ,
188
191
)
192
+ _running_server = uvicorn .Server (config = config )
193
+ _running_server .run ()
189
194
logger .info ("Server shutting down" )
190
195
191
196
197
+ def shutdown ():
198
+ global _running_server
199
+ if _running_server :
200
+ _running_server .should_exit = True
201
+ _running_server .force_exit = True
202
+
203
+
192
204
@functools .lru_cache ()
193
205
def get_microscope ():
194
206
try :
Original file line number Diff line number Diff line change 1
1
from __future__ import annotations
2
2
3
3
import datetime
4
+ import logging
4
5
5
6
import ispyb
6
7
import packaging .version
11
12
from ispyb .sqlalchemy import BLSession , Proposal
12
13
from pydantic import BaseModel
13
14
14
- import murfey
15
+ import murfey . server
15
16
import murfey .server .bootstrap
16
17
import murfey .server .websocket as ws
17
18
from murfey .server import get_hostname , get_microscope , template_files , templates
18
19
20
+ log = logging .getLogger ("murfey.server.main" )
21
+
19
22
tags_metadata = [murfey .server .bootstrap .tag ]
20
23
21
24
app = FastAPI (title = "Murfey server" , debug = True , openapi_tags = tags_metadata )
@@ -185,3 +188,13 @@ def get_version(client_version: str = ""):
185
188
result ["client-needs-downgrade" ] = client > server
186
189
187
190
return result
191
+
192
+
193
+ @app .get ("/shutdown" , include_in_schema = False )
194
+ def shutdown ():
195
+ """A method to stop the server. This should be removed before Murfey is
196
+ deployed in production. To remove it we need to figure out how to control
197
+ to process (eg. systemd) and who to run it as."""
198
+ log .info ("Server shutdown request received" )
199
+ murfey .server .shutdown ()
200
+ return {"success" : True }
You can’t perform that action at this time.
0 commit comments