summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/cleanup/__init__.py5
-rw-r--r--kvmd/apps/kvmd/__init__.py7
-rw-r--r--kvmd/apps/kvmd/server.py17
3 files changed, 25 insertions, 4 deletions
diff --git a/kvmd/apps/cleanup/__init__.py b/kvmd/apps/cleanup/__init__.py
index c99fd271..22a9cede 100644
--- a/kvmd/apps/cleanup/__init__.py
+++ b/kvmd/apps/cleanup/__init__.py
@@ -37,4 +37,9 @@ def main() -> None:
except subprocess.CalledProcessError:
pass
+ unix_path = config["server"]["unix"]
+ if unix_path and os.path.exists(unix_path):
+ logger.info("Removing socket %r ...", unix_path)
+ os.remove(unix_path)
+
logger.info("Bye-bye")
diff --git a/kvmd/apps/kvmd/__init__.py b/kvmd/apps/kvmd/__init__.py
index 3c3ca6e4..7662fae0 100644
--- a/kvmd/apps/kvmd/__init__.py
+++ b/kvmd/apps/kvmd/__init__.py
@@ -94,8 +94,11 @@ def main() -> None:
loop=loop,
).run(
- host=str(config["server"]["host"]),
- port=int(config["server"]["port"]),
+ host=str(config["server"].get("host", "localhost")),
+ port=int(config["server"].get("port", 0)),
+ unix_path=str(config["server"].get("unix", "")),
+ unix_rm=bool(config["server"].get("unix_rm", False)),
+ unix_mode=int(config["server"].get("unix_mode", 0)),
)
get_logger().info("Bye-bye")
diff --git a/kvmd/apps/kvmd/server.py b/kvmd/apps/kvmd/server.py
index 222712d3..5a0f0758 100644
--- a/kvmd/apps/kvmd/server.py
+++ b/kvmd/apps/kvmd/server.py
@@ -1,5 +1,6 @@
import os
import signal
+import socket
import asyncio
import json
import time
@@ -149,7 +150,7 @@ class Server: # pylint: disable=too-many-instance-attributes
self.__reset_streamer = False
self.__streamer_params = streamer.get_params()
- def run(self, host: str, port: int) -> None:
+ def run(self, host: str, port: int, unix_path: str, unix_rm: bool, unix_mode: int) -> None:
self.__hid.start()
setproctitle.setproctitle("[main] " + setproctitle.getproctitle())
@@ -187,7 +188,19 @@ class Server: # pylint: disable=too-many-instance-attributes
self.__loop.create_task(self.__poll_streamer_state()),
])
- aiohttp.web.run_app(app, host=host, port=port, print=self.__run_app_print)
+ assert port or unix_path
+ if unix_path:
+ kwargs: Dict = {}
+ if unix_rm and os.path.exists(unix_path):
+ os.remove(unix_path)
+ server_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ server_socket.bind(unix_path)
+ if unix_mode:
+ os.chmod(unix_path, unix_mode)
+ kwargs = {"sock": server_socket}
+ else:
+ kwargs = {"host": host, "port": port}
+ aiohttp.web.run_app(app, print=self.__run_app_print, **kwargs)
async def __make_info(self) -> Dict:
return {