Compare commits
2 Commits
5f06d7e04c
...
26a54848f1
| Author | SHA1 | Date | |
|---|---|---|---|
| 26a54848f1 | |||
| 015337d75c |
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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] = {}
|
||||
|
||||
@ -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:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user