mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-13 01:30:31 +08:00
kvmd: supported unix sockets
This commit is contained in:
parent
78e773cf82
commit
8229363ff6
@ -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")
|
||||
|
||||
@ -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")
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user