Fix issue where the gtkui sometimes won't start if there is a stale lock file or socket in the ipc/
directory.
This commit is contained in:
parent
ae426eb0cd
commit
450d526eca
|
@ -58,9 +58,23 @@ class IPCProtocolClient(Protocol):
|
||||||
def connectionMade(self):
|
def connectionMade(self):
|
||||||
self.transport.write(deluge.rencode.dumps(self.factory.args))
|
self.transport.write(deluge.rencode.dumps(self.factory.args))
|
||||||
self.transport.loseConnection()
|
self.transport.loseConnection()
|
||||||
|
|
||||||
def connectionLost(self, reason):
|
def connectionLost(self, reason):
|
||||||
reactor.stop()
|
reactor.stop()
|
||||||
|
self.factory.stop = True
|
||||||
|
|
||||||
|
class IPCClientFactory(ClientFactory):
|
||||||
|
protocol = IPCProtocolClient
|
||||||
|
|
||||||
|
def __init__(self, args, connect_failed):
|
||||||
|
self.stop = False
|
||||||
|
self.args = args
|
||||||
|
self.connect_failed = connect_failed
|
||||||
|
|
||||||
|
def clientConnectionFailed(self, connector, reason):
|
||||||
|
log.info("Connection to running instance failed. Starting new one..")
|
||||||
|
reactor.stop()
|
||||||
|
|
||||||
class IPCInterface(component.Component):
|
class IPCInterface(component.Component):
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
component.Component.__init__(self, "IPCInterface")
|
component.Component.__init__(self, "IPCInterface")
|
||||||
|
@ -125,17 +139,44 @@ class IPCInterface(component.Component):
|
||||||
reactor.listenUNIX(socket, self.factory, wantPID=True)
|
reactor.listenUNIX(socket, self.factory, wantPID=True)
|
||||||
except twisted.internet.error.CannotListenError, e:
|
except twisted.internet.error.CannotListenError, e:
|
||||||
log.info("Deluge is already running! Sending arguments to running instance..")
|
log.info("Deluge is already running! Sending arguments to running instance..")
|
||||||
self.factory = ClientFactory()
|
self.factory = IPCClientFactory(args, self.connect_failed)
|
||||||
self.factory.args = args
|
|
||||||
self.factory.protocol = IPCProtocolClient
|
|
||||||
reactor.connectUNIX(socket, self.factory, checkPID=True)
|
reactor.connectUNIX(socket, self.factory, checkPID=True)
|
||||||
reactor.run()
|
reactor.run()
|
||||||
import gtk
|
if self.factory.stop:
|
||||||
gtk.gdk.notify_startup_complete()
|
import gtk
|
||||||
sys.exit(0)
|
gtk.gdk.notify_startup_complete()
|
||||||
|
sys.exit(0)
|
||||||
|
else:
|
||||||
|
self.connect_failed(args)
|
||||||
else:
|
else:
|
||||||
process_args(args)
|
process_args(args)
|
||||||
|
|
||||||
|
def connect_failed(self, args):
|
||||||
|
# This gets called when we're unable to do a connectUNIX to the ipc
|
||||||
|
# socket. We'll delete the lock and socket files and start up Deluge.
|
||||||
|
#reactor.stop()
|
||||||
|
socket = os.path.join(deluge.configmanager.get_config_dir("ipc"), "deluge-gtk")
|
||||||
|
if os.path.exists(socket):
|
||||||
|
try:
|
||||||
|
os.remove(socket)
|
||||||
|
except Exception, e:
|
||||||
|
log.error("Unable to remove socket file: %s", e)
|
||||||
|
|
||||||
|
lock = socket + ".lock"
|
||||||
|
if os.path.lexists(lock):
|
||||||
|
try:
|
||||||
|
os.remove(lock)
|
||||||
|
except Exception, e:
|
||||||
|
log.error("Unable to remove lock file: %s", e)
|
||||||
|
try:
|
||||||
|
self.factory = Factory()
|
||||||
|
self.factory.protocol = IPCProtocolServer
|
||||||
|
reactor.listenUNIX(socket, self.factory, wantPID=True)
|
||||||
|
except Exception, e:
|
||||||
|
log.error("Unable to start IPC listening socket: %s", e)
|
||||||
|
finally:
|
||||||
|
process_args(args)
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
if deluge.common.windows_check():
|
if deluge.common.windows_check():
|
||||||
import win32api
|
import win32api
|
||||||
|
|
Loading…
Reference in New Issue