Skip to content

Commit e4a3153

Browse files
phlogistonjohnmergify[bot]
authored andcommitted
satellite: remove socket file on startup
There's an annoying behavior in the python varlink lib. It's described in the comment. Work around it by proactively removing the socket file before the server starts. Signed-off-by: John Mulligan <[email protected]>
1 parent 9facbe3 commit e4a3153

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

sambacc/commands/satellite/keybridge.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import argparse
2020
import logging
21+
import pathlib
2122
import signal
2223
import sys
2324
import typing
@@ -181,10 +182,22 @@ def _serve(ctx: Context) -> None:
181182
opts = sambacc.varlink.server.VarlinkServerOptions(ctx.cli.address)
182183
srv = sambacc.varlink.server.VarlinkServer(opts)
183184
srv.add_endpoint(sambacc.varlink.keybridge.endpoint(scopes))
185+
_clean_socket_file(ctx.cli.address)
184186
with srv.serve():
185187
signal.pause()
186188

187189

190+
def _clean_socket_file(address: str) -> None:
191+
"""Remove the old socket file. I think the lib has fixed this in
192+
as-yet-unreleased code, but right now every time you start the server when
193+
the file exists it fails (but then removes the socket) and so without this
194+
cleanup it always needs to be started twice.
195+
"""
196+
assert address.startswith("unix:")
197+
path = pathlib.Path(address.split(":", 1)[-1])
198+
path.unlink(missing_ok=True)
199+
200+
188201
def _new_scope(
189202
ctx: Context, scope_cfg: sambacc.config.KeyBridgeScopeConfig
190203
) -> Scope:

0 commit comments

Comments
 (0)