How detect shutdown of a dedicated server application?

For the client, the closing of the game client can be detect in the shoutdown event in the gameInstance, is there something similar for the server?

The only thing that comes to mind is a crutch solution such as a sub process that checks if the server process is running …
Is there a more adequate solution?

UGameEngine :: PreExit ()
called only at client closing, when closing server - not…

Sorry to revive an old post, but I’m actually in the same boat as Hellgn here but my case is a little more specific if anyone wants to chime in.

I’m running a dedicated server build and a client build, source version of UE5.3. I’ve created my own class from UGameViewportClient and then implemented a custom WindowCloseRequested() override that calls FGenericPlatformMisc::RequestExit(false); and then returns false to ensure a clean shutdown of the game in the event of actions like Alt-F4, X on the window, etc…

Unfortunately though, the Dedicated Server doesn’t seem to build with my custom UGameViewportClient, and thus never overrides the WindowCloseRequested() function. Ideally, the server would already shut down cleanly regardless of how it’s closed, however if a user runs the -log argument to create a live console window of the server, any of the aforementioned methods will instantly close the server before it has the chance to cleanly shut down.

So my question is this: Is there any possible way to check when a Dedicated Server is shut down through external means (Alt+F4, X on windows, etc…) and override/intercept that to direct the server to shutdown cleanly? Ideally it would avoid checking for platform-specific closure methods and be a “One method to rule them all” solution, but I have yet to find any and would greatly appreciate the help.