mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 17:20:30 +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:
|
except subprocess.CalledProcessError:
|
||||||
pass
|
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")
|
logger.info("Bye-bye")
|
||||||
|
|||||||
@ -94,8 +94,11 @@ def main() -> None:
|
|||||||
|
|
||||||
loop=loop,
|
loop=loop,
|
||||||
).run(
|
).run(
|
||||||
host=str(config["server"]["host"]),
|
host=str(config["server"].get("host", "localhost")),
|
||||||
port=int(config["server"]["port"]),
|
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")
|
get_logger().info("Bye-bye")
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
|
import socket
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
@ -149,7 +150,7 @@ class Server: # pylint: disable=too-many-instance-attributes
|
|||||||
self.__reset_streamer = False
|
self.__reset_streamer = False
|
||||||
self.__streamer_params = streamer.get_params()
|
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()
|
self.__hid.start()
|
||||||
|
|
||||||
setproctitle.setproctitle("[main] " + setproctitle.getproctitle())
|
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()),
|
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:
|
async def __make_info(self) -> Dict:
|
||||||
return {
|
return {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user