Skip to content

Commit

Permalink
server: allow commandline unix socket configuration
Browse files Browse the repository at this point in the history
Add a command line option that allows the installation to specify
the exact path to Moonraker's unix domain server socket.  The
default location remains at:

<data_path>/comms/moonraker.sock

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
  • Loading branch information
Arksine committed Jul 22, 2023
1 parent fdc3e0e commit 1fadae8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
19 changes: 11 additions & 8 deletions moonraker/components/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,18 @@ async def _handle_call_agent(self, web_request: WebRequest) -> Any:
return await conn.call_method(method, args)

async def start_unix_server(self) -> None:
data_path = pathlib.Path(self.server.get_app_args()["data_path"])
comms_path = data_path.joinpath("comms")
if not comms_path.exists():
comms_path.mkdir()
sock_path = comms_path.joinpath("moonraker.sock")
sockfile: str = self.server.get_app_args()["unix_socket_path"]
sock_path = pathlib.Path(sockfile).expanduser().resolve()
logging.info(f"Creating Unix Domain Socket at '{sock_path}'")
self.uds_server = await asyncio.start_unix_server(
self.on_unix_socket_connected, sock_path, limit=UNIX_BUFFER_LIMIT
)
try:
self.uds_server = await asyncio.start_unix_server(
self.on_unix_socket_connected, sock_path, limit=UNIX_BUFFER_LIMIT
)
except asyncio.CancelledError:
raise
except Exception:
logging.exception(f"Failed to create Unix Domain Socket: {sock_path}")
self.uds_server = None

def on_unix_socket_connected(
self, reader: asyncio.StreamReader, writer: asyncio.StreamWriter
Expand Down
18 changes: 15 additions & 3 deletions moonraker/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,14 @@ def main(from_package: bool = True) -> None:
)
parser.add_argument(
"-c", "--configfile", default=None, metavar='<configfile>',
help="Location of moonraker configuration file")
help="Path to Moonraker's configuration file")
parser.add_argument(
"-l", "--logfile", default=None, metavar='<logfile>',
help="log file name and location")
help="Path to Moonraker's log file")
parser.add_argument(
"-u", "--unixsocket", default=None, metavar="<unixsocket>",
help="Path to Moonraker's unix domain socket"
)
parser.add_argument(
"-n", "--nologfile", action='store_true',
help="disable logging to a file")
Expand Down Expand Up @@ -525,6 +529,13 @@ def main(from_package: bool = True) -> None:
cfg_file: str = cmd_line_args.configfile
else:
cfg_file = str(data_path.joinpath("config/moonraker.conf"))
if cmd_line_args.unixsocket is not None:
unix_sock: str = cmd_line_args.unixsocket
else:
comms_dir = data_path.joinpath("comms")
if not comms_dir.exists():
comms_dir.mkdir()
unix_sock = str(comms_dir.joinpath("moonraker.sock"))
app_args = {
"data_path": str(data_path),
"is_default_data_path": cmd_line_args.datapath is None,
Expand All @@ -535,7 +546,8 @@ def main(from_package: bool = True) -> None:
"asyncio_debug": cmd_line_args.asyncio_debug,
"is_backup_config": False,
"is_python_package": from_package,
"instance_uuid": instance_uuid
"instance_uuid": instance_uuid,
"unix_socket_path": unix_sock
}

# Setup Logging
Expand Down

0 comments on commit 1fadae8

Please sign in to comment.