Compare commits

...

2 Commits

Author SHA1 Message Date
26a54848f1 Update. 2025-06-11 01:28:35 +02:00
015337d75c Update signals. 2025-06-11 01:21:33 +02:00
4 changed files with 20 additions and 1 deletions

View File

@ -14,5 +14,5 @@ RUN echo 'root:root' | chpasswd
COPY ./terminal /opt/bootstrap
COPY ./terminal /opt/snek
RUN cp -r ./root /opt/bootrap/root
RUN cp -r /root /opt/bootstrap/root
COPY ./terminal/entry /usr/local/bin/entry

View File

@ -3,6 +3,7 @@ import logging
import pathlib
import ssl
import uuid
import signal
from datetime import datetime
from snek import snode
@ -210,6 +211,10 @@ class Application(BaseApplication):
# app.loop = asyncio.get_running_loop()
app.executor = ThreadPoolExecutor(max_workers=200)
app.loop.set_default_executor(self.executor)
for sig in (signal.SIGINT, signal.SIGTERM):
app.loop.add_signal_handler(
sig, lambda: asyncio.create_task(self.services.container.shutdown())
)
async def create_task(self, task):
await self.tasks.put(task)

View File

@ -12,6 +12,9 @@ class ContainerService(BaseService):
self.compose = ComposeFileManager(self.compose_path,self.container_event_handler)
self.event_listeners = {}
async def shutdown(self):
return await self.compose.shutdown()
async def add_event_listener(self, name, event,event_handler):
if not name in self.event_listeners:
self.event_listeners[name] = {}

View File

@ -17,6 +17,17 @@ class ComposeFileManager:
self.running_instances = {}
self.event_handler = event_handler
async def shutdown(self):
print("Stopping all sessions")
for name in self.list_instances():
proc = self.running_instances.get(name)
if not proc:
continue
if proc['proc'].returncode == None:
print("Stopping",name)
await proc['proc'].stop()
print("Stopped",name,"gracefully")
def _load(self):
try:
with open(self.compose_path) as f: