[Daemon] Improve logging when another process is using listen port
This commit is contained in:
parent
b2db96e4df
commit
b32c5d8247
|
@ -11,7 +11,9 @@ from __future__ import print_function, unicode_literals
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from logging import FileHandler, getLogger
|
from logging import DEBUG, FileHandler, getLogger
|
||||||
|
|
||||||
|
from twisted.internet.error import CannotListenError
|
||||||
|
|
||||||
from deluge.common import run_profiled
|
from deluge.common import run_profiled
|
||||||
from deluge.configmanager import get_config_dir
|
from deluge.configmanager import get_config_dir
|
||||||
|
@ -55,8 +57,8 @@ def start_daemon(skip_start=False):
|
||||||
from deluge.core.daemon import is_daemon_running
|
from deluge.core.daemon import is_daemon_running
|
||||||
pid_file = get_config_dir('deluged.pid')
|
pid_file = get_config_dir('deluged.pid')
|
||||||
if is_daemon_running(pid_file):
|
if is_daemon_running(pid_file):
|
||||||
print('Cannot run multiple daemons using the same config directory.\n'
|
print('Cannot run multiple daemons with same config directory.\n'
|
||||||
'If you believe this is an error, you can force a start by deleting: %s' % pid_file)
|
'If you believe this is an error, force starting by deleting: %s' % pid_file)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
log = getLogger(__name__)
|
log = getLogger(__name__)
|
||||||
|
@ -78,11 +80,18 @@ def start_daemon(skip_start=False):
|
||||||
return daemon
|
return daemon
|
||||||
else:
|
else:
|
||||||
daemon.start()
|
daemon.start()
|
||||||
|
except CannotListenError as ex:
|
||||||
|
log.error('Cannot start deluged, listen port in use.\n'
|
||||||
|
' Check for other running daemons or services using this port: %s:%s',
|
||||||
|
ex.interface, ex.port)
|
||||||
|
sys.exit(1)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
log.exception(ex)
|
log.error('Unable to start deluged: %s', ex)
|
||||||
|
if log.isEnabledFor(DEBUG):
|
||||||
|
log.exception(ex)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
finally:
|
finally:
|
||||||
|
log.info('Exiting...')
|
||||||
if options.pidfile:
|
if options.pidfile:
|
||||||
os.remove(options.pidfile)
|
os.remove(options.pidfile)
|
||||||
|
|
||||||
|
|
|
@ -374,8 +374,7 @@ class RPCServer(component.Component):
|
||||||
try:
|
try:
|
||||||
reactor.listenSSL(port, self.factory, ServerContextFactory(), interface=hostname)
|
reactor.listenSSL(port, self.factory, ServerContextFactory(), interface=hostname)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
log.info('Daemon already running or port not available.')
|
log.debug('Daemon already running or port not available.: %s', ex)
|
||||||
log.error(ex)
|
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def register_object(self, obj, name=None):
|
def register_object(self, obj, name=None):
|
||||||
|
|
Loading…
Reference in New Issue