bridge (pb): Remove existing socket if any:
If the backend was not closed properly, the former socket may still be present. This was preventing the backend to start again, while now the old socket is removed in this case.
This commit is contained in:
parent
04d53ebe10
commit
243aab9cec
2 changed files with 34 additions and 6 deletions
|
|
@ -19,10 +19,12 @@
|
||||||
|
|
||||||
|
|
||||||
import dataclasses
|
import dataclasses
|
||||||
from functools import partial
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from twisted.spread import jelly, pb
|
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
|
from twisted.spread import jelly, pb
|
||||||
|
|
||||||
|
from libervia.backend.core import exceptions
|
||||||
from libervia.backend.core.log import getLogger
|
from libervia.backend.core.log import getLogger
|
||||||
from libervia.backend.tools import config
|
from libervia.backend.tools import config
|
||||||
|
|
||||||
|
|
@ -103,7 +105,7 @@ class PBRoot(pb.Root):
|
||||||
##METHODS_PART##
|
##METHODS_PART##
|
||||||
|
|
||||||
|
|
||||||
class bridge(object):
|
class bridge:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
log.info("Init Perspective Broker...")
|
log.info("Init Perspective Broker...")
|
||||||
self.root = PBRoot()
|
self.root = PBRoot()
|
||||||
|
|
@ -113,6 +115,18 @@ class bridge(object):
|
||||||
if conn_type == "unix_socket":
|
if conn_type == "unix_socket":
|
||||||
socket_path = bridge_conf.socket_dir / "bridge_pb"
|
socket_path = bridge_conf.socket_dir / "bridge_pb"
|
||||||
log.info(f"using UNIX Socket at {socket_path}")
|
log.info(f"using UNIX Socket at {socket_path}")
|
||||||
|
if socket_path.exists():
|
||||||
|
if socket_path.is_socket():
|
||||||
|
log.warning(
|
||||||
|
"There is already a socket at this path, probably due to a bad "
|
||||||
|
"closing of the backend; we remove it."
|
||||||
|
)
|
||||||
|
socket_path.unlink()
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise exceptions.BridgeInitError(
|
||||||
|
f"Unexpected file at socket path: {socket_path}"
|
||||||
|
)
|
||||||
reactor.listenUNIX(
|
reactor.listenUNIX(
|
||||||
str(socket_path), pb.PBServerFactory(self.root), mode=0o600
|
str(socket_path), pb.PBServerFactory(self.root), mode=0o600
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,12 @@
|
||||||
|
|
||||||
|
|
||||||
import dataclasses
|
import dataclasses
|
||||||
from functools import partial
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from twisted.spread import jelly, pb
|
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
|
from twisted.spread import jelly, pb
|
||||||
|
|
||||||
|
from libervia.backend.core import exceptions
|
||||||
from libervia.backend.core.log import getLogger
|
from libervia.backend.core.log import getLogger
|
||||||
from libervia.backend.tools import config
|
from libervia.backend.tools import config
|
||||||
|
|
||||||
|
|
@ -103,7 +105,7 @@ class PBRoot(pb.Root):
|
||||||
##METHODS_PART##
|
##METHODS_PART##
|
||||||
|
|
||||||
|
|
||||||
class bridge(object):
|
class bridge:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
log.info("Init Perspective Broker...")
|
log.info("Init Perspective Broker...")
|
||||||
self.root = PBRoot()
|
self.root = PBRoot()
|
||||||
|
|
@ -113,6 +115,18 @@ class bridge(object):
|
||||||
if conn_type == "unix_socket":
|
if conn_type == "unix_socket":
|
||||||
socket_path = bridge_conf.socket_dir / "bridge_pb"
|
socket_path = bridge_conf.socket_dir / "bridge_pb"
|
||||||
log.info(f"using UNIX Socket at {socket_path}")
|
log.info(f"using UNIX Socket at {socket_path}")
|
||||||
|
if socket_path.exists():
|
||||||
|
if socket_path.is_socket():
|
||||||
|
log.warning(
|
||||||
|
"There is already a socket at this path, probably due to a bad "
|
||||||
|
"closing of the backend; we remove it."
|
||||||
|
)
|
||||||
|
socket_path.unlink()
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise exceptions.BridgeInitError(
|
||||||
|
f"Unexpected file at socket path: {socket_path}"
|
||||||
|
)
|
||||||
reactor.listenUNIX(
|
reactor.listenUNIX(
|
||||||
str(socket_path), pb.PBServerFactory(self.root), mode=0o600
|
str(socket_path), pb.PBServerFactory(self.root), mode=0o600
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue