Skip to content
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

Properly handle systemd signals #694

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions backend/decky_loader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# Full imports
import multiprocessing
multiprocessing.freeze_support()
import signal
from asyncio import AbstractEventLoop, CancelledError, Task, all_tasks, current_task, gather, new_event_loop, set_event_loop, sleep
from logging import basicConfig, getLogger
from os import path
Expand Down Expand Up @@ -244,6 +245,10 @@ async def inject_javascript(self, tab: Tab, first: bool=False, request: Request|
def run(self):
run_app(self.web_app, host=get_server_host(), port=get_server_port(), loop=self.loop, access_log=None, handle_signals=True, shutdown_timeout=40)

def handle_systemd():
PluginManager.shutdown()
pass

def main():
setproctitle(f"Decky Loader {get_loader_version()} ({getproctitle()})")
setthreadtitle("Decky Loader")
Expand All @@ -258,6 +263,11 @@ def main():
# Append the system and user python paths
sys.path.extend(get_system_pythonpaths())

#Catch a sigint (CTRL-C) coming from systemd and shut down gracefully
#TODO: Handle the Windows case in the future
if ON_LINUX:
signal.signal(signal.SIGINT, handle_systemd)

logger.info(f"Starting Decky version {get_loader_version()}")

loop = new_event_loop()
Expand Down
Loading